|
@@ -7,6 +7,7 @@ import (
|
|
"git.nspix.com/golang/kos/entry/cli"
|
|
"git.nspix.com/golang/kos/entry/cli"
|
|
"git.nspix.com/golang/kos/entry/http"
|
|
"git.nspix.com/golang/kos/entry/http"
|
|
httpkg "net/http"
|
|
httpkg "net/http"
|
|
|
|
+ "time"
|
|
|
|
|
|
"git.nspix.com/golang/kos"
|
|
"git.nspix.com/golang/kos"
|
|
)
|
|
)
|
|
@@ -28,18 +29,28 @@ func (s *subServer) Start(ctx context.Context) (err error) {
|
|
kos.Http().Handle(httpkg.MethodGet, "/hello", func(ctx *http.Context) (err error) {
|
|
kos.Http().Handle(httpkg.MethodGet, "/hello", func(ctx *http.Context) (err error) {
|
|
return ctx.Success("Hello World")
|
|
return ctx.Success("Hello World")
|
|
})
|
|
})
|
|
|
|
+
|
|
kos.Command().Handle("/test", "test command", func(ctx *cli.Context) (err error) {
|
|
kos.Command().Handle("/test", "test command", func(ctx *cli.Context) (err error) {
|
|
return ctx.Success([][]string{
|
|
return ctx.Success([][]string{
|
|
[]string{"NAME", "AGE"},
|
|
[]string{"NAME", "AGE"},
|
|
[]string{"SSS", "aaa"},
|
|
[]string{"SSS", "aaa"},
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
+
|
|
kos.Command().Handle("/users", "test command", func(ctx *cli.Context) (err error) {
|
|
kos.Command().Handle("/users", "test command", func(ctx *cli.Context) (err error) {
|
|
return ctx.Success([]*users{
|
|
return ctx.Success([]*users{
|
|
{Name: "Zhan", Age: 10, Tags: []string{"a", "b"}},
|
|
{Name: "Zhan", Age: 10, Tags: []string{"a", "b"}},
|
|
{Name: "Lisi", Age: 15, Tags: []string{"c", "d"}},
|
|
{Name: "Lisi", Age: 15, Tags: []string{"c", "d"}},
|
|
})
|
|
})
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ kos.Command().Handle("/ctx", "context test", func(ctx *cli.Context) (err error) {
|
|
|
|
+ select {
|
|
|
|
+ case <-ctx.Context().Done():
|
|
|
|
+ case <-time.After(time.Second * 2):
|
|
|
|
+ }
|
|
|
|
+ return ctx.Success("OK")
|
|
|
|
+ })
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|