2023-04-23 17:57:36 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"embed"
|
|
|
|
"flag"
|
2023-08-25 09:53:45 +08:00
|
|
|
"git.nspix.com/golang/kos/entry/http"
|
|
|
|
httpkg "net/http"
|
2023-06-11 11:19:01 +08:00
|
|
|
|
2023-04-23 17:57:36 +08:00
|
|
|
"git.nspix.com/golang/kos"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed web
|
|
|
|
var webDir embed.FS
|
|
|
|
|
|
|
|
type subServer struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *subServer) Start(ctx context.Context) (err error) {
|
2023-08-25 09:53:45 +08:00
|
|
|
kos.Http().Root("/web", httpkg.FS(webDir))
|
|
|
|
kos.Http().Handle(httpkg.MethodGet, "/hello", func(ctx *http.Context) (err error) {
|
|
|
|
return ctx.Success("Hello World")
|
|
|
|
})
|
2023-04-23 17:57:36 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *subServer) Stop() (err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
|
|
|
svr := kos.Init(
|
|
|
|
kos.WithName("git.nspix.com/golang/test", "0.0.1"),
|
|
|
|
kos.WithServer(&subServer{}),
|
2023-05-31 11:14:15 +08:00
|
|
|
kos.WithDirectHttp(),
|
2023-04-23 17:57:36 +08:00
|
|
|
)
|
|
|
|
svr.Run()
|
|
|
|
}
|