Documentation ¶
Index ¶
- func Setup[S State[A], A Action](srv *Server, name string, initState InitState[S, A], opt ...SetupOption[S, A])
- type Action
- type BaseCtx
- func (c *BaseCtx[S, A]) Conn() kit.Conn
- func (c *BaseCtx[S, A]) Context() context.Context
- func (c *BaseCtx[S, A]) Next()
- func (c *BaseCtx[S, A]) ReduceState(action A, fn func(s S, err error) error) (err error)
- func (c *BaseCtx[S, A]) Route() string
- func (c *BaseCtx[S, A]) SetUserContext(userCtx context.Context)
- func (c *BaseCtx[S, A]) State() S
- func (c *BaseCtx[S, A]) StopExecution()
- type CORSConfig
- type CompressionLevel
- type DecoderFunc
- type EMPTY
- type Error
- type InitState
- type Message
- type Middleware
- type NOP
- type PushOpt
- type RESTParam
- type RESTParams
- type Selector
- type Server
- type ServerOption
- func Listen(addr string) ServerOption
- func WithCORS(cors CORSConfig) ServerOption
- func WithCompression(lvl CompressionLevel) ServerOption
- func WithCustomRPC(in kit.IncomingRPCFactory, out kit.OutgoingRPCFactory) ServerOption
- func WithPredicateKey(key string) ServerOption
- func WithServerName(name string) ServerOption
- func WithWebsocketEndpoint(endpoint string) ServerOption
- type SetupContext
- type SetupOption
- func WithMiddleware[S State[A], A Action](h ...StatelessMiddleware) SetupOption[S, A]
- func WithStream[S State[A], A Action, IN, OUT Message](h StreamHandler[S, A, IN, OUT], opt ...StreamOption) SetupOption[S, A]
- func WithUnary[S State[A], A Action, IN, OUT Message](h UnaryHandler[S, A, IN, OUT], opt ...UnaryOption) SetupOption[S, A]
- type State
- type StatelessMiddleware
- type StreamCtx
- type StreamHandler
- type StreamOption
- type StreamSelectorOption
- type UnaryCtx
- type UnaryHandler
- type UnaryOption
- func DELETE(path string, opt ...UnarySelectorOption) UnaryOption
- func GET(path string, opt ...UnarySelectorOption) UnaryOption
- func HEAD(path string, opt ...UnarySelectorOption) UnaryOption
- func OPTIONS(path string, opt ...UnarySelectorOption) UnaryOption
- func PATCH(path string, opt ...UnarySelectorOption) UnaryOption
- func POST(path string, opt ...UnarySelectorOption) UnaryOption
- func PUT(path string, opt ...UnarySelectorOption) UnaryOption
- func REST(method, path string, opt ...UnarySelectorOption) UnaryOption
- type UnarySelectorOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Setup ¶
func Setup[S State[A], A Action]( srv *Server, name string, initState InitState[S, A], opt ...SetupOption[S, A], )
Setup is a helper function to set up server and services. S **MUST** implement State[A] and also **MUST** be a pointer to a struct, otherwise this function panics Possible options are: - WithState: to set up state - WithUnary: to set up unary handler - WithStream: to set up stream handler
Types ¶
type BaseCtx ¶ added in v0.11.19
BaseCtx is a base context object used by UnaryCtx and StreamCtx to provide common functionality.
func (*BaseCtx[S, A]) ReduceState ¶ added in v0.11.19
ReduceState is a helper function to reduce state and call fn if it's not nil. If you need to reduce the state in an atomic fashion, then you should pass a function fn which is guaranteed to be called in a locked state. Although, it only works if S implements sync.Locker interface.
func (*BaseCtx[S, A]) SetUserContext ¶ added in v0.11.19
func (*BaseCtx[S, A]) StopExecution ¶ added in v0.11.19
func (c *BaseCtx[S, A]) StopExecution()
StopExecution stops the execution so the next middleware/handler won't be called.
type CORSConfig ¶
type CORSConfig = fasthttp.CORSConfig
type CompressionLevel ¶
type CompressionLevel = fasthttp.CompressionLevel
const ( CompressionLevelDisabled CompressionLevel = -1 CompressionLevelDefault CompressionLevel = 0 CompressionLevelBestSpeed CompressionLevel = 1 CompressionLevelBestCompression CompressionLevel = 2 )
Represents compression level that will be used in the middleware
type DecoderFunc ¶
type DecoderFunc func(bag RESTParams, data []byte) (kit.Message, error)
type InitState ¶
func EmptyState ¶ added in v0.11.19
func EmptyState() InitState[EMPTY, NOP]
EmptyState is a helper function to create an empty state. This is a noop state that does nothing; whenever you don't need a state, you can use this function to create one.
func ToInitiateState ¶
type Middleware ¶ added in v0.11.19
type PushOpt ¶
func WithHdrMap ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
func (*Server) PostmanCollection ¶
func (*Server) SwaggerAPI ¶
type ServerOption ¶
type ServerOption func(cfg *serverConfig)
func Listen ¶
func Listen(addr string) ServerOption
func WithCORS ¶
func WithCORS(cors CORSConfig) ServerOption
func WithCompression ¶
func WithCompression(lvl CompressionLevel) ServerOption
func WithCustomRPC ¶
func WithCustomRPC(in kit.IncomingRPCFactory, out kit.OutgoingRPCFactory) ServerOption
func WithPredicateKey ¶
func WithPredicateKey(key string) ServerOption
func WithServerName ¶
func WithServerName(name string) ServerOption
func WithWebsocketEndpoint ¶
func WithWebsocketEndpoint(endpoint string) ServerOption
type SetupContext ¶
SetupContext is a context object holds data until the Server starts. It is used internally to hold state and server configuration.
type SetupOption ¶ added in v0.11.19
type SetupOption[S State[A], A Action] func(ctx *SetupContext[S, A])
func WithMiddleware ¶ added in v0.11.19
func WithMiddleware[S State[A], A Action]( h ...StatelessMiddleware, ) SetupOption[S, A]
func WithStream ¶ added in v0.11.19
func WithStream[S State[A], A Action, IN, OUT Message]( h StreamHandler[S, A, IN, OUT], opt ...StreamOption, ) SetupOption[S, A]
WithStream is a SetupOption to set up stream handler. Possible options are: - RPC: to set up RPC handler
func WithUnary ¶ added in v0.11.19
func WithUnary[S State[A], A Action, IN, OUT Message]( h UnaryHandler[S, A, IN, OUT], opt ...UnaryOption, ) SetupOption[S, A]
WithUnary is a SetupOption to set up unary handler. Possible options are: - REST: to set up REST handler - GET: to set up GET handler - POST: to set up POST handler - PUT: to set up PUT handler - DELETE: to set up DELETE handler - PATCH: to set up PATCH handler - HEAD: to set up HEAD handler - OPTIONS: to set up OPTIONS handler
type StatelessMiddleware ¶ added in v0.11.19
type StatelessMiddleware = kit.HandlerFunc
type StreamHandler ¶
type StreamOption ¶
Exposing internal types
func RPC ¶
func RPC(predicate string, opt ...StreamSelectorOption) StreamOption
RPC is a StreamOption to set up RPC handler. Possible options are: - StreamDecoder: to set up a custom decoder
type StreamSelectorOption ¶
type StreamSelectorOption = stream.SelectorOption
Exposing internal types
func StreamDecoder ¶
func StreamDecoder(decoder DecoderFunc) StreamSelectorOption
type UnaryHandler ¶
type UnaryOption ¶
Exposing internal types
func DELETE ¶
func DELETE(path string, opt ...UnarySelectorOption) UnaryOption
func GET ¶
func GET(path string, opt ...UnarySelectorOption) UnaryOption
func HEAD ¶
func HEAD(path string, opt ...UnarySelectorOption) UnaryOption
func OPTIONS ¶
func OPTIONS(path string, opt ...UnarySelectorOption) UnaryOption
func PATCH ¶
func PATCH(path string, opt ...UnarySelectorOption) UnaryOption
func POST ¶
func POST(path string, opt ...UnarySelectorOption) UnaryOption
func PUT ¶
func PUT(path string, opt ...UnarySelectorOption) UnaryOption
func REST ¶
func REST(method, path string, opt ...UnarySelectorOption) UnaryOption
type UnarySelectorOption ¶
type UnarySelectorOption = unary.SelectorOption
Exposing internal types
func UnaryDecoder ¶
func UnaryDecoder(decoder DecoderFunc) UnarySelectorOption
func UnaryName ¶
func UnaryName(name string) UnarySelectorOption