-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: ToTu-Dev <[email protected]>
- Loading branch information
1 parent
a63caae
commit f0e55c2
Showing
9 changed files
with
149 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package group | ||
|
||
import "github.com/gominima/minima" | ||
|
||
func RouteGroup() *minima.Group { | ||
grp := minima.NewGroup("/v1") | ||
grp.Get("/auth", func(res *minima.Response, req *minima.Request) { | ||
res.Send("auth") | ||
}) | ||
return grp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
_examples/rtr/auth/test2.go → _examples/rtr/test_routes/test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package auth | ||
package test | ||
import "github.com/gominima/minima" | ||
|
||
func SimpleTests() minima.Handler { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package minima | ||
|
||
/** | ||
* @info The minima group structure | ||
* @property {[]cacheroute} [route] The array of cached routes | ||
* @property {[string} [prefix] The group prefix | ||
*/ | ||
type Group struct { | ||
route []*cacheRoute | ||
prefix string | ||
} | ||
|
||
/** | ||
* @info Creates a new minima group | ||
* @return {Group} | ||
*/ | ||
func NewGroup(prefix string) *Group { | ||
return &Group{ | ||
route: make([]*cacheRoute, 0), | ||
prefix: prefix, | ||
} | ||
} | ||
|
||
func (g *Group) register(method string, path string, handler Handler) { | ||
g.route = append(g.route, &cacheRoute{ | ||
method: method, | ||
path: g.prefix + path, | ||
handler: handler, | ||
}) | ||
} | ||
|
||
/** | ||
* @info Adds route with Get method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Router} | ||
*/ | ||
func (g *Group) Get(path string, handler Handler) *Group { | ||
g.register("GET", path, handler) | ||
return g | ||
} | ||
|
||
/** | ||
* @info Adds route with Post method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Group} | ||
*/ | ||
func (g *Group) Post(path string, handler Handler) *Group { | ||
g.register("POST", path, handler) | ||
return g | ||
} | ||
|
||
/** | ||
* @info Adds route with Put method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Group} | ||
*/ | ||
func (g *Group) Put(path string, handler Handler) *Group { | ||
g.register("PUT", path, handler) | ||
return g | ||
} | ||
|
||
/** | ||
* @info Adds route with Patch method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Group} | ||
*/ | ||
func (g *Group) Patch(path string, handler Handler) { | ||
g.register("PATCH", path, handler) | ||
} | ||
|
||
/** | ||
* @info Adds route with Options method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Group} | ||
*/ | ||
func (g *Group) Options(path string, handler Handler) *Group { | ||
g.register("OPTIONS", path, handler) | ||
return g | ||
} | ||
|
||
/** | ||
* @info Adds route with Head method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Group} | ||
*/ | ||
func (g *Group) Head(path string, handler Handler) *Group { | ||
g.register("HEAD", path, handler) | ||
return g | ||
} | ||
|
||
/** | ||
* @info Adds route with Delete method | ||
* @param {string} [path] The route path | ||
* @param {...Handler} [handler] The handler for the given route | ||
* @returns {*Group} | ||
*/ | ||
func (g *Group) Delete(path string, handler Handler) *Group { | ||
g.register("DELETE", path, handler) | ||
return g | ||
} | ||
|
||
/** | ||
* @info Returns all routes for the group | ||
* @return {[]cachRoute} | ||
*/ | ||
func (g *Group) GetGroupRoutes() []*cacheRoute { | ||
return g.route | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.