You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
router/route.go

61 lines
855 B
Go

2 years ago
package router
import "net/http"
type Route struct {
// isGlobal=True == no prefix route
IsGlobal bool
Method string
Path string
Endpoint interface{}
Params []string
}
type Option func(*Route)
2 years ago
func NewRoute(endpoint interface{}, opts ...Option) Route {
2 years ago
route := Route{
IsGlobal: false,
Method: http.MethodGet,
Path: "/",
Endpoint: endpoint,
Params: []string{},
}
for _, o := range opts {
o(&route)
}
return route
}
func IsGlobal(n bool) Option {
2 years ago
return func(o *Route) {
o.IsGlobal = n
}
}
func Method(n string) Option {
2 years ago
return func(o *Route) {
o.Method = n
}
}
func Path(n string) Option {
2 years ago
return func(o *Route) {
o.Path = n
}
}
func Endpoint(n interface{}) Option {
2 years ago
return func(o *Route) {
o.Endpoint = n
}
}
func Params(n ...string) Option {
2 years ago
return func(o *Route) {
o.Params = n
}
}