server: work in progress: routing config
This commit is contained in:
parent
e2afdeb61a
commit
ca08bbb9c7
3 changed files with 35 additions and 21 deletions
32
server/config.go
Normal file
32
server/config.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
lib "git.sr.ht/~cco/go-scopes"
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
*config.BaseCfg
|
||||
Port string
|
||||
Addr string
|
||||
routes []routeCfg
|
||||
}
|
||||
|
||||
type routeCfg struct {
|
||||
methods []string
|
||||
path string
|
||||
spec routeSpec
|
||||
}
|
||||
|
||||
type routeSpec interface{}
|
||||
|
||||
type fsSpec struct {
|
||||
docRoot string
|
||||
}
|
||||
|
||||
type rcellSpec struct {
|
||||
lib.Config
|
||||
}
|
||||
|
||||
type Handler func(lib.Context, *gin.Context)
|
|
@ -4,30 +4,10 @@ import (
|
|||
"net/http"
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
type Cfg struct {
|
||||
*config.BaseCfg
|
||||
Port string
|
||||
Routes []RouteCfg
|
||||
}
|
||||
|
||||
type RouteCfg struct {
|
||||
Method string
|
||||
Path string
|
||||
Handler Handler
|
||||
}
|
||||
|
||||
type FSCfg struct {
|
||||
RouteCfg
|
||||
DocRoot string
|
||||
}
|
||||
|
||||
type Handler func(lib.Context, *gin.Context)
|
||||
|
||||
type ServerState struct {
|
||||
server *http.Server
|
||||
}
|
||||
|
@ -45,7 +25,6 @@ func HandleDone(ctx lib.Context) bool {
|
|||
}
|
||||
|
||||
func Serve(ctx lib.Context) {
|
||||
//r := gin.Default()
|
||||
r := gin.New()
|
||||
r.Use(gin.Recovery())
|
||||
r.Use(Logger(ctx))
|
||||
|
|
|
@ -31,6 +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"))
|
||||
|
||||
test_client := &client.Cfg{
|
||||
BaseCfg: b("test-client", core.Start),
|
||||
|
|
Loading…
Add table
Reference in a new issue