ettp

package
v1.0.52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
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"
)
View Source
const (
	GET     = "GET"
	POST    = "POST"
	PUT     = "PUT"
	PATCH   = "PATCH"
	DELETE  = "DELETE"
	HEAD    = "HEAD"
	OPTIONS = "OPTIONS"
	RPC     = "RPC"
)
View Source
const (
	EVENT_RESOLVER_STATUS = "event:resolver:status"
)
View Source
const (
	ResoluteKey request.ContextKey = "resolute"
)
View Source
const (
	Version = "v0.0.2"
)

Variables

This section is empty.

Functions

func CorsAllowAll

func CorsAllowAll(allowedOrigins []string) *cors.Cors

* * 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

func (s *Codec) ReadRequestBody(body interface{}) error

* * ReadRequestBody * @param body interface{} * @return error *

func (*Codec) ReadRequestHeader added in v1.0.22

func (s *Codec) ReadRequestHeader(r *rpc.Request) error

* * ReadRequestHeader * @param r *rpc.Request * @return error *

func (*Codec) WriteResponse added in v1.0.22

func (s *Codec) WriteResponse(r *rpc.Response, body interface{}) error

* * WriteResponse * @param r *rpc.Response, body interface{} * @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. *

func (*Package) ToJson

func (s *Package) ToJson() (et.Json, error)

* * ToJson * @return (et.Json, error) *

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. *

func (*Resolver) ToJson

func (r *Resolver) ToJson() et.Json

* * ToJson * @return et.Json *

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. *

func (*Router) ToJson

func (s *Router) ToJson() et.Json

* * ToJson * @return et.Json *

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

func New(name string, cnf *Config) (*Server, error)

* * 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) Close

func (s *Server) Close()

* * Close * @return error *

func (*Server) FindResolver

func (s *Server) FindResolver(r *http.Request) (*Resolver, error)

* * 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

func (s *Server) RemoveRouterById(id string, save bool) error

* * RemoveRouterById * @param id string * @return error *

func (*Server) Reset

func (s *Server) Reset()

* * Reset * @return error *

func (*Server) Save

func (s *Server) Save() error

* * Save * @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 *

func (*Server) Start

func (s *Server) Start()

* * Start * @return error *

func (*Server) ToJson

func (s *Server) ToJson() et.Json

* * ToJson * @return et.Json *

func (*Server) ToString added in v1.0.26

func (s *Server) ToString() string

* * ToString * @return string *

func (*Server) Use

func (s *Server) Use(middlewares ...func(http.Handler) http.Handler)

* * Use * @param middlewares ...func(http.Handler) http.Handler *

func (*Server) UseAuthentication added in v1.0.44

func (s *Server) UseAuthentication(middleware func(http.Handler) http.Handler) *Server

* * UseAuthentication * @param middleware func(http.HandlerFunc) http.HandlerFunc * @return *Server *

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. *

func (*Solver) ToJson

func (s *Solver) ToJson() et.Json

* * ToJson * @return et.Json *

type Status

type Status int
const (
	TpStatusPending Status = iota
	TpStatusFailed
	TpStatusSuccess
)

func (Status) String

func (s Status) String() string

* * String: Name of the resolver status ("pending", "failed", "success"). * @return string *

type Storage

type Storage struct {
	Solvers map[string]*Solver
	Version string
	Key     string
}

* * Storage: What Save persists (in the cache under <name>:<version>, or in apigateway.json). *

type TpHeader

type TpHeader int
const (
	TpKeepHeader TpHeader = iota
	TpJoinHeader
	TpReplaceHeader
)

func (TpHeader) String

func (t TpHeader) String() string

* * String * @return string *

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 *

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址