From e1606273ddc2d48b54944756d070dd7fc9ca6e20 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 4 Apr 2020 10:05:27 +0200 Subject: [PATCH] remove useless func type --- dynamic/handler.go | 12 ++++++------ dynamic/types.go | 5 +---- handler.go | 2 +- server.go | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/dynamic/handler.go b/dynamic/handler.go index 54bded1..29b654a 100644 --- a/dynamic/handler.go +++ b/dynamic/handler.go @@ -8,16 +8,16 @@ import ( "git.xdrm.io/go/aicra/internal/config" ) -// Build a handler from a service configuration and a HandlerFn +// Build a handler from a service configuration and a dynamic function // -// a HandlerFn must have as a signature : `func(api.Request, inputStruct) (outputStruct, api.Error)` +// @fn must have as a signature : `func(inputStruct) (*outputStruct, api.Error)` // - `inputStruct` is a struct{} containing a field for each service input (with valid reflect.Type) // - `outputStruct` is a struct{} containing a field for each service output (with valid reflect.Type) // // Special cases: -// - it there is no input, `inputStruct` can be omitted -// - it there is no output, `outputStruct` can be omitted -func Build(fn HandlerFn, service config.Service) (*Handler, error) { +// - it there is no input, `inputStruct` must be omitted +// - it there is no output, `outputStruct` must be omitted +func Build(fn interface{}, service config.Service) (*Handler, error) { h := &Handler{ spec: makeSpec(service), fn: fn, @@ -39,7 +39,7 @@ func Build(fn HandlerFn, service config.Service) (*Handler, error) { return h, nil } -// Handle binds input @data into HandleFn and returns map output +// Handle binds input @data into the dynamic function and returns map output func (h *Handler) Handle(data map[string]interface{}) (map[string]interface{}, api.Error) { fnv := reflect.ValueOf(h.fn) diff --git a/dynamic/types.go b/dynamic/types.go index a180e63..041ddb9 100644 --- a/dynamic/types.go +++ b/dynamic/types.go @@ -2,13 +2,10 @@ package dynamic import "reflect" -// HandlerFn defines a dynamic handler function -type HandlerFn interface{} - // Handler represents a dynamic api handler type Handler struct { spec spec - fn HandlerFn + fn interface{} } type spec struct { diff --git a/handler.go b/handler.go index 8af4f34..16af6ca 100644 --- a/handler.go +++ b/handler.go @@ -16,7 +16,7 @@ type handler struct { // createHandler builds a handler from its http method and path // also it checks whether the function signature is valid -func createHandler(method, path string, service config.Service, fn dynamic.HandlerFn) (*handler, error) { +func createHandler(method, path string, service config.Service, fn interface{}) (*handler, error) { method = strings.ToUpper(method) dynHandler, err := dynamic.Build(fn, service) diff --git a/server.go b/server.go index 54e53b4..7bfa323 100644 --- a/server.go +++ b/server.go @@ -6,7 +6,6 @@ import ( "os" "git.xdrm.io/go/aicra/datatype" - "git.xdrm.io/go/aicra/dynamic" "git.xdrm.io/go/aicra/internal/config" ) @@ -47,7 +46,7 @@ func New(configPath string, dtypes ...datatype.T) (*Server, error) { } // Handle sets a new handler for an HTTP method to a path -func (s *Server) Handle(method, path string, fn dynamic.HandlerFn) error { +func (s *Server) Handle(method, path string, fn interface{}) error { // find associated service var found *config.Service = nil for _, service := range s.config.Services {