tk103331 opened a new issue, #2863:
URL: https://github.com/apache/incubator-devlake/issues/2863

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/incubator-devlake/issues?q=is%3Aissue) and 
found no similar feature requirement.
   
   
   ### Description
   
   I found that the plugin's ApiResources registration has a declaration about 
connections.
   ```
   func (plugin Github) ApiResources() 
map[string]map[string]core.ApiResourceHandler {
        return map[string]map[string]core.ApiResourceHandler{
                "test": {
                        "POST": api.TestConnection,
                },
                "connections": {
                        "POST": api.PostConnections,
                        "GET":  api.ListConnections,
                },
                "connections/:connectionId": {
                        "GET":    api.GetConnection,
                        "PATCH":  api.PatchConnection,
                        "DELETE": api.DeleteConnection,
                },
        }
   }
   ```
   
   Is it possible to abstract as a golang interface? like this:
   ```
   type PluginConnectionHandler interface {
        TestConnection(input *ApiResourceInput) (*ApiResourceOutput, error)
        PostConnections(input *ApiResourceInput) (*ApiResourceOutput, error)
        PatchConnection(input *ApiResourceInput) (*ApiResourceOutput, error)
        DeleteConnection(input *ApiResourceInput) (*ApiResourceOutput, error)
        ListConnections(input *ApiResourceInput) (*ApiResourceOutput, error)
        GetConnection(input *ApiResourceInput) (*ApiResourceOutput, error)
   }
   ```
   
   The benefits of doing this are:
   
   - The backend can determine whether all methods are implemented by checking 
whether the interface is implemented.
   - Plugin authors only need to implement the interface and do not need to 
care about the details of API requests (such as request paths and request 
methods).
   - The front end can use the same API interface.
   
   ### Use case
   
   _No response_
   
   ### Related issues
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to