1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package application_test
- import (
- "context"
- "strings"
- "testing"
- "time"
- "git.ali33.ru/fcg-xvii/rest"
- "git.ali33.ru/fcg-xvii/rest/application"
- )
- type Hello struct {
- Name string `rest:"required"`
- }
- func (s *Hello) Validate(req rest.IRequestIn) rest.IRequestOut {
- if s.Name = strings.TrimSpace(s.Name); len(s.Name) == 0 {
- return req.OutError(rest.ErrorFiled("name", "expected not empty string"))
- }
- return nil
- }
- func (s *Hello) Execute(req rest.IRequestIn) rest.IRequestOut {
- response := HelloResponse{
- Message: "Hello, " + s.Name,
- }
- return rest.OutFileds(req, &response, nil)
- }
- type HelloResponse struct {
- Message string `rest:"default"`
- }
- ////////////////////////////
- var (
- commands = map[string]func() rest.IExecuter{
- "/api/hello": func() rest.IExecuter { return &Hello{} },
- }
- )
- func Command(cName string) (rest.IExecuter, bool) {
- if command, check := commands[cName]; check {
- return command(), true
- }
- return nil, false
- }
- func TestApp(t *testing.T) {
- 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,
- }
- app := application.New(conf, nil, context.Background())
- t.Log(app)
- <-time.After(time.Hour)
- }
|