Documentation
¶
Index ¶
- Constants
- Variables
- func AttachToCmdrCommand(tcp cmdr.OptCmd, opts ...CmdrOpt)
- func DefaultCommandAction(cmd *cmdr.Command, args []string, prefixPrefix string, opts ...Opt) (err error)
- func New(config *base.Config, opts ...Opt) (serve ServeFunc, obj *Obj, tlsEnabled bool, err error)
- func Shutdown(serverObj *Obj)
- type CmdrOpt
- func WithCmdrCommandAction(action CommandAction) CmdrOpt
- func WithCmdrLogger(logger log.Logger) CmdrOpt
- func WithCmdrNil() CmdrOpt
- func WithCmdrPort(port int) CmdrOpt
- func WithCmdrPrefixPrefix(prefixPrefix string) CmdrOpt
- func WithCmdrServerOptions(opts ...Opt) CmdrOpt
- func WithCmdrServerProtocolInterceptor(fn protocol.Interceptor) CmdrOpt
- func WithCmdrUDPMode(mode bool) CmdrOpt
- type CommandAction
- type Connection
- type NewConnectionFunc
- type Obj
- func (s *Obj) BaseUri() string
- func (s *Obj) Close()
- func (s *Obj) Config() *base.Config
- func (s *Obj) ListenTo(listener net.Listener)
- func (s *Obj) ProtocolInterceptor() protocol.Interceptor
- func (s *Obj) RequestShutdown()
- func (s *Obj) Serve(baseCtx context.Context) (err error)
- func (s *Obj) SetLogger(l log.Logger)
- func (s *Obj) SetNewConnectionFunc(fn NewConnectionFunc)
- func (s *Obj) SetProtocolInterceptor(pi protocol.Interceptor)
- func (s *Obj) WithLogger(logger log.Logger) *Obj
- func (s *Obj) WithProtocolInterceptor(pi protocol.Interceptor) *Obj
- type Opt
- func WithServerLogger(logger log.Logger) Opt
- func WithServerNetworkType(typeOfNetwork string) Opt
- func WithServerNewConnectionFunc(fn NewConnectionFunc) Opt
- func WithServerPrefixInConfigFile(prefix string) Opt
- func WithServerProtocolInterceptor(fn protocol.Interceptor) Opt
- func WithServerUDPMode(mode bool) Opt
- type ServeFunc
Constants ¶
const CTX_CONN_KEY = "conn"
const CTX_SERVER_OBJECT_KEY = "server-object"
const (
DefaultPort = 8883
)
Variables ¶
var ErrServerClosed = errors.New("server closed")
Functions ¶
func AttachToCmdrCommand ¶ added in v0.3.0
func DefaultCommandAction ¶ added in v0.2.5
Types ¶
type CmdrOpt ¶
type CmdrOpt func(*builder)
func WithCmdrCommandAction ¶
func WithCmdrCommandAction(action CommandAction) CmdrOpt
WithCmdrCommandAction allows a custom CommandAction of yours. The default is DefaultCommandAction, it's enough in most cases. But, if you want, write yours.
func WithCmdrLogger ¶
func WithCmdrNil ¶
func WithCmdrNil() CmdrOpt
func WithCmdrPort ¶
func WithCmdrPrefixPrefix ¶
WithCmdrPrefixPrefix setup a prefix of prefix of tls configs and server/client tcp/udp configs.
For the `prefixPrefix` = "some-here", the section in yaml config file looks like:
```yaml app:
some-here: server: addr: # host[:port] # The default ports for the whole socket-lib. ports: default: 1883 tls: 8883 websocket: 443 #sn: 1884 # mqttsn udp mode tls: enabled: true client-auth: false cacert: root.pem cert: cert.pem key: cert.key locations: - ./ci/certs - $CFG_DIR/certs cl ient: # To run the client with an interactive mode, set interactive to true. The default is always false. # interactive: true addr: # host[:port] # The default ports for the whole socket-lib. ports: default: 1883 tls: 8883 websocket: 443 #sn: 1884 # mqttsn udp mode tls: enabled: true cacert: root.pem server-cert: cert.pem client-auth: false cert: client.pem key: client.key locations: - ./ci/certs - $CFG_DIR/certs
```
func WithCmdrServerOptions ¶
func WithCmdrServerProtocolInterceptor ¶
func WithCmdrServerProtocolInterceptor(fn protocol.Interceptor) CmdrOpt
func WithCmdrUDPMode ¶
type CommandAction ¶
type Connection ¶
type NewConnectionFunc ¶
type Obj ¶
type Obj struct { ReadTimeout time.Duration WriteTimeout time.Duration log.Logger // contains filtered or unexported fields }
func (*Obj) ProtocolInterceptor ¶
func (s *Obj) ProtocolInterceptor() protocol.Interceptor
func (*Obj) RequestShutdown ¶
func (s *Obj) RequestShutdown()
func (*Obj) SetNewConnectionFunc ¶
func (s *Obj) SetNewConnectionFunc(fn NewConnectionFunc)
func (*Obj) SetProtocolInterceptor ¶
func (s *Obj) SetProtocolInterceptor(pi protocol.Interceptor)
func (*Obj) WithProtocolInterceptor ¶
func (s *Obj) WithProtocolInterceptor(pi protocol.Interceptor) *Obj
type Opt ¶
type Opt func(so *Obj)
func WithServerLogger ¶
func WithServerNetworkType ¶
WithServerNetworkType setups the network type of the listener.
The network must be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".
For TCP networks, if the host in the address parameter is empty or a literal unspecified IP address, Listen listens on all available unicast and anycast IP addresses of the local system. To only use IPv4, use network "tcp4". The address can use a host name, but this is not recommended, because it will create a listener for at most one of the host's IP addresses. If the port in the address parameter is empty or "0", as in "127.0.0.1:" or "[::1]:0", a port number is automatically chosen. The Addr method of Listener can be used to discover the chosen port.
func WithServerNewConnectionFunc ¶
func WithServerNewConnectionFunc(fn NewConnectionFunc) Opt
func WithServerProtocolInterceptor ¶
func WithServerProtocolInterceptor(fn protocol.Interceptor) Opt