github.com/pavlo67/common@v0.5.3/common/server_http/operator.go (about) 1 package server_http 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/pavlo67/common/common/auth" 8 9 "github.com/pavlo67/common/common/joiner" 10 ) 11 12 const OnRequestMiddlewareInterfaceKey joiner.InterfaceKey = "server_http_on_request_middleware" 13 const InterfaceKey joiner.InterfaceKey = "server_http" 14 15 type PathParams map[string]string 16 17 type OnRequestMiddleware interface { 18 Identity(r *http.Request) (*auth.Identity, error) 19 } 20 21 type StaticPath struct { 22 LocalPath string 23 MIMEType *string 24 } 25 26 type WorkerHTTP func(Operator, *http.Request, PathParams, *auth.Identity) (Response, error) 27 28 type Operator interface { 29 HandleMiddleware(onRequest OnRequestMiddleware) error 30 HandleEndpoint(key EndpointKey, serverPath string, endpoint Endpoint) error 31 HandleFiles(key EndpointKey, serverPath string, staticPath StaticPath) error 32 33 Start() error 34 Addr() (port int, https bool) 35 Shutdown(ctx context.Context) error 36 }