-
Notifications
You must be signed in to change notification settings - Fork 277
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
add resource for routes #210
base: master
Are you sure you want to change the base?
Conversation
"Index": routeMethod{Name: "Index", HttpMethod: http.MethodGet}, | ||
"Create": routeMethod{Name: "Create", HttpMethod: http.MethodPost}, | ||
"Show": routeMethod{Name: "Show", HttpMethod: http.MethodGet, Param: param}, | ||
"Update": routeMethod{Name: "Update", HttpMethod: http.MethodPut, Param: param}, | ||
"Delete": routeMethod{Name: "Delete", HttpMethod: http.MethodDelete, Param: param}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I'd go with having enum-style indexes, rather than strings, to avoid possibility of having a typo:
const (
MethodIndex = iota
MethodCreate
MethodShow
MethodUpdate
MethodDelete
)
But I agree your way the code looks more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition, just a small concern regarding query param handling.
param := stringy.New(name).KebabCase().ToLower() | ||
paramSingular := pluralize.NewClient().Singular(param) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you did this magic on routeMethod.Param
. I guess you probably were thinking about the safety and bad names specified by users? I would remove this and keep this up to the users to think about what is allowed and what is not in the query string.
Also, this adds two unnecessary dependencies on 3rd-party packages:
"github.com/gertd/go-pluralize"
"github.com/gobeam/stringy"
Examples
Create handlers
Initialize resource routes
Run