server: first basic route config
This commit is contained in:
parent
ca08bbb9c7
commit
10908bbd61
2 changed files with 26 additions and 4 deletions
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
lib "git.sr.ht/~cco/go-scopes"
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
"git.sr.ht/~cco/go-scopes/core"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
@ -13,6 +14,19 @@ type Cfg struct {
|
|||
routes []routeCfg
|
||||
}
|
||||
|
||||
func (c *Cfg) AddRoute(path string, spec routeSpec, methods ...string) routeSpec {
|
||||
rcfg := routeCfg{
|
||||
methods: methods,
|
||||
path: path,
|
||||
spec: spec,
|
||||
}
|
||||
if methods == nil {
|
||||
rcfg.methods = []string{"GET"}
|
||||
}
|
||||
c.routes = append(c.routes, rcfg)
|
||||
return spec
|
||||
}
|
||||
|
||||
type routeCfg struct {
|
||||
methods []string
|
||||
path string
|
||||
|
@ -25,8 +39,16 @@ type fsSpec struct {
|
|||
docRoot string
|
||||
}
|
||||
|
||||
type rcellSpec struct {
|
||||
func FileServer(docRoot string) routeSpec {
|
||||
return &fsSpec{docRoot}
|
||||
}
|
||||
|
||||
type RCellSpec struct {
|
||||
lib.Config
|
||||
}
|
||||
|
||||
func RCellHandler() routeSpec {
|
||||
return &RCellSpec{config.Base("", core.Start)}
|
||||
}
|
||||
|
||||
type Handler func(lib.Context, *gin.Context)
|
||||
|
|
|
@ -31,9 +31,9 @@ func Config() lib.Config {
|
|||
BaseCfg: b("server", server.Start),
|
||||
Port: ovr("8123", SERVER_PORT),
|
||||
}
|
||||
// server_c.AddRoute("/docs", FileServer("html"))
|
||||
// server_rc := server_c.AddRoute("/api", RCellHandler())
|
||||
// server_rc.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
||||
server_c.AddRoute("/docs", server.FileServer("html"))
|
||||
server_rc := server_c.AddRoute("/api", server.RCellHandler()).(*server.RCellSpec)
|
||||
server_rc.AddAction("demo", action.Base(action.Forward, "test-receiver"))
|
||||
|
||||
test_client := &client.Cfg{
|
||||
BaseCfg: b("test-client", core.Start),
|
||||
|
|
Loading…
Add table
Reference in a new issue