-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
See if we can use more info from Go's type system #12
Comments
Thoughts @Teamwork/gophers ? |
Problem with that is somehow we also need to add the Doing your change would work, but then we would need to wrap that method in the router mapping to just return the error. Or maybe something like this (but it seems to complicate the code for the sake of the documentation):
|
Changing to a custom |
See my answer there @abiosoft |
Yeah, that is my concern as well. OTOH, it does make writing documentation easier, so I don't know. There are good points to be made for both approaches I think; although I'm kind of leaning towards keeping it as-is, simple because that's the least effort (I'm lazy 😄). |
Also, there are some projects where we want to return a specific error message with |
fwiw this is the pattern I use in my hobby projects: type doSomethingArgs struct {
// some properties
}
type doSomethingResponse struct {
// some properties
}
var doSomething = &endpoint.Endpoint{
Method: "POST",
Path: "/api/v1/centralAccount/doSomething",
RequiresSession: false,
GetArgsStruct: func() interface{} { return &doSomethingArgs{}},
ExampleResponseStructure: &doSomethingResponse{}
CtxHandler: func(ctx echo.Context, a interface{}) interface{} {
args := a.(*doSomethingArgs)
// Some business logic, to build up a *doSomethingResponse value
// any errors are paniced immediately and the server will
// recover from them and return the associated http status code
// and message from the error
return doSomethingResponse{}
},
} this and other [
{
"method": "GET",
"path": "/api/v1/centralAccount/getRegions",
"requiresSession": false,
"exampleResponseStructure": [
"use",
"usw",
"eu"
]
},
{
"method": "POST",
"path": "/api/v1/centralAccount/register",
"requiresSession": false,
"argsLocation": "Body",
"argsStructure": {
"name": "",
"email": "",
"pwd": "",
"region": "",
"language": "",
"displayName": null,
"theme": 0
}
},
{
"method": "POST",
"path": "/api/v1/centralAccount/resendActivationEmail",
"requiresSession": false,
"argsLocation": "Body",
"argsStructure": {
"email": ""
}
},
] |
Right now there is quite a lot of duplication in the Kommentaar comment blocks:
Pretty much every element except the description is duplicated from somewhere:
var args ...
c.JSON
callguru whicherrs
)The upshot of getting this from the type system is that it avoids duplication and typos, and that all the standard Go tooling will work (e.g. renames). I've had a number of typos on e.g. the path name and such.
The downside is that it's more complex to implement in Kommentaar, and that it will be much stronger tied to the way we structure our handlers. Right now, there is almost no relation between the code in the handler and the documentation. This is not accidental: one of the big problems with the previous go-swagger approach in Desk was that we needed to refactor code in a way that no one liked to make it work.
I don't know if there is a better way to do this. Perhaps the current approach is the best possible/least worst one; but on the other hand, I think that if eliminating at least the duplicate
Request body:
orResponse 200:
would be a good win.For example, if we could restructure things to be like:
Then that might be nice? Question is, is it worth is, and will it work with echo?
The text was updated successfully, but these errors were encountered: