Documentation
¶
Index ¶
- Constants
- func CorsAllowAll(allowedOrigins []string) *cors.Cors
- type Codec
- type Config
- type Package
- type Resolver
- type Router
- type Server
- func (s *Server) Close()
- func (s *Server) FindResolver(r *http.Request) (*Resolver, error)
- func (s *Server) HTTPError(resolver *Resolver, metric *middleware.Metrics, w http.ResponseWriter, ...)
- func (s *Server) HTTPSuccess(resolver *Resolver, metric *middleware.Metrics, ...)
- func (s *Server) Private(method, path string, handlerFn http.HandlerFunc, packageName string) (*Solver, error)
- func (s *Server) Public(method, path string, handlerFn http.HandlerFunc, packageName string) (*Solver, error)
- func (s *Server) RemoveRouterById(id string, save bool) error
- func (s *Server) Reset()
- func (s *Server) Save() error
- func (s *Server) SetRouter(method, path, resolve string, typeHeader int, header et.Json, ...) (*Solver, error)
- func (s *Server) Start()
- func (s *Server) ToJson() et.Json
- func (s *Server) ToString() string
- func (s *Server) Use(middlewares ...func(http.Handler) http.Handler)
- func (s *Server) UseAuthentication(middleware func(http.Handler) http.Handler) *Server
- type Solver
- type Status
- type Storage
- type TpHeader
- type TransportConfig
- type TypeRouter
Constants ¶
const ( MSG_ROUTE_NOT_FOUND = "Route not found" MSG_ROUTE_DELETE = "Route deleted" MSG_RESET_ROUTES = "Reset server routes" MSG_PACKAGE_DELETE = "Package deleted" MSG_ROUTER_NOT_FOUND = "router not found" MSG_ERROR_CALLING_SERVICE = "error calling the service: %v" )
const ( GET = "GET" POST = "POST" PUT = "PUT" PATCH = "PATCH" DELETE = "DELETE" HEAD = "HEAD" OPTIONS = "OPTIONS" RPC = "RPC" )
const (
EVENT_RESOLVER_STATUS = "event:resolver:status"
)
const (
ResoluteKey request.ContextKey = "resolute"
)
const (
Version = "v0.0.2"
)
Variables ¶
This section is empty.
Functions ¶
func CorsAllowAll ¶
* * CorsAllowAll: CORS handler that accepts the given origins (any when empty) and every header; * credentials only with an explicit allowlist. * @param allowedOrigins []string * @return *cors.Cors *
Types ¶
type Codec ¶ added in v1.0.22
type Codec struct {
// contains filtered or unexported fields
}
* * Codec: gob rpc.ServerCodec of the pipe: one request per connection, answered by jrpc.Call. *
func (*Codec) ReadRequestBody ¶ added in v1.0.22
* * ReadRequestBody * @param body interface{} * @return error *
func (*Codec) ReadRequestHeader ¶ added in v1.0.22
* * ReadRequestHeader * @param r *rpc.Request * @return error *
type Config ¶
type Config struct {
Port int `json:"port"` // HTTP port
RpcPort int `json:"rpc_port"` // RPC (pipe) port; 0 = assigned by the OS
Parent string `json:"parent"` // path prefix of the handlers registered with Public/Private
ReadTimeout time.Duration `json:"read_timeout"` // http.Server.ReadTimeout
WriteTimeout time.Duration `json:"write_timeout"`
IdleTimeout time.Duration `json:"idle_timeout"` // http.Server.IdleTimeout; + 300 ms = life of a Resolver in Requests
Timeout time.Duration `json:"timeout"` // timeout of the proxy http.Client
AllowOrigin []string `json:"allow_origin"` // CORS allowlist; empty = any origin, without credentials
IsTLS bool `json:"is_tls"` // serve HTTPS with CertFile and KeyFile
CertFile string `json:"cert_file"`
KeyFile string `json:"key_file"`
Transport *TransportConfig `json:"transport"` // nil = built-in transport (100 conns, 90 s idle, HTTP/2)
Debug bool `json:"debug"` // log the route table and the server state
}
* * Config: Settings of New. *
type Package ¶
type Package struct {
Name string `json:"name"`
Routes et.Json `json:"routes"`
// contains filtered or unexported fields
}
* * Package: Routes registered by one service, by solver id. *
type Resolver ¶
type Resolver struct {
*http.Request
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Status Status `json:"status"`
ID string `json:"id"`
URL string `json:"url"`
Path string `json:"path"`
Kind TypeRouter `json:"kind"`
// contains filtered or unexported fields
}
* * Resolver: A request matched to a Solver: the target URL with the path params applied, the headers * already merged and its status, published on EVENT_RESOLVER_STATUS at each change. *
type Router ¶
type Router struct {
Tag string `json:"tag"`
Param string `json:"param"`
Solver *Solver `json:"solver"`
Router map[string]*Router `json:"router"`
// contains filtered or unexported fields
}
* * Router: Node of the route tree of one method: one segment per level (Param when it is {name}), * with the Solver at the leaf. *
type Server ¶
type Server struct {
CreatedAt time.Time `json:"created_at"`
Name string `json:"name"`
Host string `json:"host"`
Port int `json:"port"`
RpcPort int `json:"rpc_port"`
Addr string `json:"addr"`
Parent string `json:"parent"`
Version string `json:"version"`
Solvers map[string]*Solver `json:"solvers"`
Packages map[string]*Package `json:"packages"`
Requests map[string]*Resolver `json:"requests"`
// contains filtered or unexported fields
}
* * Server: API gateway: routes (Solvers, by METHOD:path) grouped in Packages, resolved per request * into Requests, served over HTTP and over a gob RPC pipe; routes persist through Save/load. *
func New ¶
* * New: Builds the server, its proxy client and opens the RPC listener; Start serves it. * @param name string, cnf *Config * @return (*Server, error) *
func (*Server) FindResolver ¶
* * FindResolver * @param r *http.Request * @return *Request, error *
func (*Server) HTTPError ¶
func (s *Server) HTTPError(resolver *Resolver, metric *middleware.Metrics, w http.ResponseWriter, r *http.Request, status int, message string)
* * HTTPError: Marks the resolver as failed, drops it from Requests and writes the error through the metric. * @param resolver *Resolver, metric *middleware.Metrics, w http.ResponseWriter, r *http.Request, status int, message string *
func (*Server) HTTPSuccess ¶
func (s *Server) HTTPSuccess(resolver *Resolver, metric *middleware.Metrics, rw *middleware.ResponseWriterWrapper)
* * HTTPSuccess * @param resolver *Resolver, metric *middleware.Metrics, rw *middleware.ResponseWriterWrapper *
func (*Server) Private ¶
func (s *Server) Private(method, path string, handlerFn http.HandlerFunc, packageName string) (*Solver, error)
* * Private * @param method, path string, handlerFn http.HandlerFunc, packageName string *
func (*Server) Public ¶
func (s *Server) Public(method, path string, handlerFn http.HandlerFunc, packageName string) (*Solver, error)
* * Public * @param method, path string, handlerFn http.HandlerFunc, packageName string *
func (*Server) RemoveRouterById ¶
* * RemoveRouterById * @param id string * @return error *
func (*Server) SetRouter ¶
func (s *Server) SetRouter(method, path, resolve string, typeHeader int, header et.Json, excludeHeader []string, version int, packageName string, saved bool) (*Solver, error)
* * SetRouter * @param method, path, resolve string, header et.Json, excludeHeader []string, version int, packageName string, saved bool * @return *Solver, error *
type Solver ¶
type Solver struct {
ID string `json:"id"`
Kind TypeRouter `json:"kind"`
Method string `json:"method"`
Path string `json:"path"`
Solver string `json:"solver"`
TypeHeader TpHeader `json:"type_header"`
Header map[string]string `json:"header"`
ExcludeHeader []string `json:"exclude_header"`
Version int `json:"version"`
PackageName string `json:"package_name"`
// contains filtered or unexported fields
}
* * Solver: One route of the gateway (ID = METHOD:path): a local handler (TpHandler) or * a proxied URL (TpApiRest) with its header policy, version and package. *
type Storage ¶
* * Storage: What Save persists (in the cache under <name>:<version>, or in apigateway.json). *
type TransportConfig ¶ added in v1.0.22
type TransportConfig struct {
InsecureSkipVerify bool `json:"insecure_skip_verify"`
MaxIdleConns int `json:"max_idle_conns"`
MaxIdleConnsPerHost int `json:"max_idle_conns_per_host"`
MaxConnsPerHost int `json:"max_conns_per_host"`
IdleConnTimeout int `json:"idle_conn_timeout"`
TLSHandshakeTimeout int `json:"tls_handshake_timeout"`
ForceAttemptHTTP2 bool `json:"force_attempt_http2"`
}
* * TransportConfig: Settings of the proxy's http.Transport; the timeouts are in seconds and * zero values keep the net/http defaults. *
type TypeRouter ¶
type TypeRouter int
const ( TpHandler TypeRouter = iota + 1 TpApiRest )
func StringToTypeRouter ¶
func StringToTypeRouter(s string) TypeRouter
func (TypeRouter) String ¶
func (t TypeRouter) String() string
* * String: Name of the route kind ("handler" or "app"). * @return string *