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]) Exists(key string) bool
- func (c *BaseCtx[S, A]) Get(key string) any
- func (c *BaseCtx[S, A]) GetInHdr(key string) string
- func (c *BaseCtx[S, A]) GetInputHeader(key string) string
- func (c *BaseCtx[S, A]) KitCtx() *kit.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]) Set(key string, value any)
- func (c *BaseCtx[S, A]) SetUserContext(userCtx context.Context)
- func (c *BaseCtx[S, A]) State() S
- func (c *BaseCtx[S, A]) StopExecution()
- func (c *BaseCtx[S, A]) Walk(f func(key string, val any) bool)
- func (c *BaseCtx[S, A]) WalkInHdr(f func(key string, val string) bool)
- func (c *BaseCtx[S, A]) WalkInputHeader(f func(key string, val string) bool)
- type CORSConfig
- type CompressionLevel
- type DecoderFunc
- type EMPTY
- type Error
- type InitState
- type Message
- type Middleware
- type NOP
- type NodeSelectorFunc
- 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 WithDisableHeaderNamesNormalizing() ServerOption
- func WithGlobalHandlers(handlers ...kit.HandlerFunc) ServerOption
- func WithLogger(logger kit.Logger) ServerOption
- func WithPredicateKey(key string) ServerOption
- func WithPrefork() ServerOption
- func WithServerName(name string) ServerOption
- func WithShutdownTimeout(timeout time.Duration) ServerOption
- func WithTracer(tracer kit.Tracer) ServerOption
- func WithWebsocketEndpoint(endpoint string) ServerOption
- type SetupContext
- type SetupOption
- func WithContract[S State[A], A Action](contract *desc.Contract) SetupOption[S, A]
- func WithCoordinator[S State[A], A Action](sel NodeSelectorFunc) SetupOption[S, A]
- func WithMiddleware[S State[A], A Action, M Middleware[S, A]](m ...M) 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 StatefulMiddleware
- type StatelessMiddleware
- type StreamCtx
- type StreamHandler
- type StreamOption
- type StreamSelectorOption
- type UnaryCtx
- type UnaryHandler
- type UnaryOption
- func ALL(path string, opt ...UnarySelectorOption) 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]) GetInputHeader ¶ added in v0.11.23
func (*BaseCtx[S, A]) KitCtx ¶ added in v0.11.22
KitCtx returns the underlying kit.Context. This is useful when we need to pass the context into inner layers of our application when we need to have access to more generic functionalities.
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 EMPTY ¶ added in v0.11.19
type EMPTY struct{}
EMPTY is a special State that does nothing. This is a utility object when we don't to have a shared state in our service.
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 Middleware[S State[A], A Action] interface { StatefulMiddleware[S, A] | StatelessMiddleware }
type NOP ¶ added in v0.11.19
type NOP struct{}
NOP is a special Action that does nothing. This is a utility object when we use EMPTY state.
type PushOpt ¶
func WithHdrMap ¶
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
func (*Server) ExportDesc ¶ added in v0.11.23
func (s *Server) ExportDesc() []desc.ServiceDesc
ExportDesc returns all services descriptions.
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 WithDisableHeaderNamesNormalizing ¶ added in v0.11.31
func WithDisableHeaderNamesNormalizing() ServerOption
func WithGlobalHandlers ¶ added in v0.11.21
func WithGlobalHandlers(handlers ...kit.HandlerFunc) ServerOption
func WithLogger ¶ added in v0.11.21
func WithLogger(logger kit.Logger) ServerOption
func WithPredicateKey ¶
func WithPredicateKey(key string) ServerOption
func WithPrefork ¶ added in v0.11.21
func WithPrefork() ServerOption
func WithServerName ¶
func WithServerName(name string) ServerOption
func WithShutdownTimeout ¶ added in v0.11.21
func WithShutdownTimeout(timeout time.Duration) ServerOption
func WithTracer ¶ added in v0.11.21
func WithTracer(tracer kit.Tracer) 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 WithContract ¶ added in v0.11.22
func WithContract[S State[A], A Action]( contract *desc.Contract, ) SetupOption[S, A]
WithContract is a SetupOption to set up a legacy desc.Contract directly. This method is useful when you are migrating your old code to rony.
func WithCoordinator ¶ added in v0.11.24
func WithCoordinator[S State[A], A Action](sel NodeSelectorFunc) SetupOption[S, A]
func WithMiddleware ¶ added in v0.11.19
func WithMiddleware[S State[A], A Action, M Middleware[S, A]]( m ...M, ) 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 StatefulMiddleware ¶ added in v0.11.21
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 UnaryCtx ¶
func (*UnaryCtx[S, A]) RESTConn ¶
RESTConn returns the underlying RESTConn if the connection is RESTConn.
func (*UnaryCtx[S, A]) SetOutHdrMap ¶ added in v0.11.23
SetOutHdrMap is shorthand for SetOutputHeaderMap
func (*UnaryCtx[S, A]) SetOutputHeader ¶ added in v0.11.23
SetOutputHeader sets the output header
func (*UnaryCtx[S, A]) SetOutputHeaderMap ¶ added in v0.11.23
SetOutputHeaderMap sets the output header map
type UnaryHandler ¶
type UnaryOption ¶
Exposing internal types
func ALL ¶ added in v0.11.30
func ALL(path string, opt ...UnarySelectorOption) UnaryOption
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