36 lines
569 B
Go
36 lines
569 B
Go
|
|
package route
|
||
|
|
|
||
|
|
import (
|
||
|
|
"Crimson-Gatekeeper/internal/query"
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
type Controller interface {
|
||
|
|
register(gin *gin.Engine)
|
||
|
|
}
|
||
|
|
|
||
|
|
func RegCtrl(cs []Controller) {
|
||
|
|
route := gin.Default()
|
||
|
|
for _, ctrl := range cs {
|
||
|
|
ctrl.register(route)
|
||
|
|
}
|
||
|
|
http.Handle("/", route)
|
||
|
|
}
|
||
|
|
|
||
|
|
type TestBoot struct {
|
||
|
|
c *query.Query
|
||
|
|
}
|
||
|
|
|
||
|
|
func (t *TestBoot) Run() error {
|
||
|
|
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
w.Write([]byte("hello world!"))
|
||
|
|
})
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewTestBoot(q *query.Query) *TestBoot {
|
||
|
|
return &TestBoot{q}
|
||
|
|
}
|