make ToHTTPServer() check for missing handlers
- check for missing handlers in ToHTTPServer() - rename HTTP() to ToHTTPServer() - remove logs
This commit is contained in:
parent
a15a5c1f7a
commit
2ee48560b6
31
server.go
31
server.go
|
@ -1,8 +1,8 @@
|
||||||
package aicra
|
package aicra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.xdrm.io/go/aicra/api"
|
"git.xdrm.io/go/aicra/api"
|
||||||
|
@ -42,12 +42,6 @@ func New(configPath string, dtypes ...datatype.T) (*Server, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. log configuration services
|
|
||||||
log.Printf("🔧 Reading configuration '%s'\n", configPath)
|
|
||||||
for _, service := range i.config.Services {
|
|
||||||
log.Printf(" ->\t%s\t'%s'\n", service.Method, service.Pattern)
|
|
||||||
}
|
|
||||||
|
|
||||||
return i, nil
|
return i, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,15 +57,24 @@ func (s *Server) Handle(handler *api.Handler) {
|
||||||
s.handlers = append(s.handlers, handler)
|
s.handlers = append(s.handlers, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTP converts the server to a http server
|
// ToHTTPServer converts the server to a http server
|
||||||
func (s Server) HTTP() httpServer {
|
func (s Server) ToHTTPServer() (*httpServer, error) {
|
||||||
|
|
||||||
// 1. log available handlers
|
// check if handlers are missing
|
||||||
log.Printf("🔗 Mapping handlers\n")
|
for _, service := range s.config.Services {
|
||||||
for i := 0; i < len(s.handlers); i++ {
|
found := false
|
||||||
log.Printf(" ->\t%s\t'%s'\n", s.handlers[i].GetMethod(), s.handlers[i].GetPath())
|
for _, handler := range s.handlers {
|
||||||
|
if handler.GetPath() == service.Pattern {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
return nil, fmt.Errorf("missing handler for %s '%s'", service.Method, service.Pattern)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. cast to http server
|
// 2. cast to http server
|
||||||
return httpServer(s)
|
httpServer := httpServer(s)
|
||||||
|
return &httpServer, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue