api/routes.go
2023-11-24 11:41:57 +08:00

66 lines
1.7 KiB
Go

package api
import (
"fmt"
"strings"
"github.com/gin-gonic/gin"
)
// ///////////////////////////////////////////////////////////////////
// IRouter & IRoutes in gin, we redefine it simple
// ///////////////////////////////////////////////////////////////////
//
// // IRouter defines all router handle interface
// // includes single and group router.
// type IRouter interface {
// IRoutes
// Group(string, ...HandlerFunc) *RouterGroup
// }
//
// // IRoutes defines all router handle interface.
// type IRoutes interface {
// Use(...HandlerFunc) IRoutes
//
// Handle(string, string, ...HandlerFunc) IRoutes
// Any(string, ...HandlerFunc) IRoutes
// GET(string, ...HandlerFunc) IRoutes
// POST(string, ...HandlerFunc) IRoutes
// DELETE(string, ...HandlerFunc) IRoutes
// PATCH(string, ...HandlerFunc) IRoutes
// PUT(string, ...HandlerFunc) IRoutes
// OPTIONS(string, ...HandlerFunc) IRoutes
// HEAD(string, ...HandlerFunc) IRoutes
//
// StaticFile(string, string) IRoutes
// StaticFileFS(string, string, http.FileSystem) IRoutes
// Static(string, string) IRoutes
// StaticFS(string, http.FileSystem) IRoutes
// }
//
// ///////////////////////////////////////////////////////////////////
type Handler interface {
ApiName() string
HandlerFunc() HandlerFunc
}
type HandlerFunc func(*Context) error
type IRoutes interface {
GET(uri string, handler Handler)
POST(uri string, handler Handler)
}
type unimplementHandler struct {
c *gin.Context
}
func (u unimplementHandler) ApiName() string {
req := u.c.Request
return strings.ToLower(fmt.Sprintf("[%s]%s", req.Method, req.RequestURI))
}
func (u unimplementHandler) HandlerFunc() HandlerFunc {
return DumpHandlerFunc
}