|
@@ -8,8 +8,15 @@ import (
|
|
|
|
|
|
"git.ali33.ru/fcg-xvii/rest"
|
|
"git.ali33.ru/fcg-xvii/rest"
|
|
"git.ali33.ru/fcg-xvii/rest/application"
|
|
"git.ali33.ru/fcg-xvii/rest/application"
|
|
|
|
+ "git.ali33.ru/fcg-xvii/rest/commands"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+func init() {
|
|
|
|
+ commands.Register("hello", func() rest.IExecuter {
|
|
|
|
+ return &Hello{}
|
|
|
|
+ })
|
|
|
|
+}
|
|
|
|
+
|
|
type Hello struct {
|
|
type Hello struct {
|
|
Name string `rest:"required"`
|
|
Name string `rest:"required"`
|
|
}
|
|
}
|
|
@@ -35,13 +42,13 @@ type HelloResponse struct {
|
|
////////////////////////////
|
|
////////////////////////////
|
|
|
|
|
|
var (
|
|
var (
|
|
- commands = map[string]func() rest.IExecuter{
|
|
|
|
|
|
+ commandsList = map[string]func() rest.IExecuter{
|
|
"/api/hello": func() rest.IExecuter { return &Hello{} },
|
|
"/api/hello": func() rest.IExecuter { return &Hello{} },
|
|
}
|
|
}
|
|
)
|
|
)
|
|
|
|
|
|
func Command(cName string) (rest.IExecuter, bool) {
|
|
func Command(cName string) (rest.IExecuter, bool) {
|
|
- if command, check := commands[cName]; check {
|
|
|
|
|
|
+ if command, check := commandsList[cName]; check {
|
|
return command(), true
|
|
return command(), true
|
|
}
|
|
}
|
|
return nil, false
|
|
return nil, false
|
|
@@ -49,14 +56,11 @@ func Command(cName string) (rest.IExecuter, bool) {
|
|
|
|
|
|
func TestApp(t *testing.T) {
|
|
func TestApp(t *testing.T) {
|
|
conf := &application.AppConfig{
|
|
conf := &application.AppConfig{
|
|
- Addr: "192.168.100.3:5000",
|
|
|
|
- Http: true,
|
|
|
|
- Websocket: false,
|
|
|
|
- Secret: []byte("secret"),
|
|
|
|
- HttpPrefix: "/api/",
|
|
|
|
- WebsocketPrefix: "/ws/",
|
|
|
|
- HTTPHeaders: application.HTTPHeadersCrossOrigin(),
|
|
|
|
- Commands: Command,
|
|
|
|
|
|
+ Addr: "192.168.100.3:5000",
|
|
|
|
+ Http: true,
|
|
|
|
+ Websocket: false,
|
|
|
|
+ Secret: []byte("secret"),
|
|
|
|
+ HttpPrefix: "/api/",
|
|
}
|
|
}
|
|
|
|
|
|
app := application.New(conf, nil, context.Background())
|
|
app := application.New(conf, nil, context.Background())
|