Import path:
gitlab.soludian.com/soludian/fountain/libs/fnet/ftcp
ftcp
import "gitlab.soludian.com/soludian/fountain/libs/fnet/ftcp"Index
- Constants
- Variables
- func Accept(listener net.Listener) (net.Conn, error)
- func RegisterServiceHandler(x proto.Message, handler Handle)
- func RegisterType(x proto.Message, name string)
- func WithAddr(addr string) lib_3rd.Option[config]
- func WithConfig(conf *config) lib_3rd.Option[config]
- func WithConnectionMaxIdleTime(duration time.Duration) lib_3rd.Option[config]
- func WithDisableHeartbeat(disable ...bool) lib_3rd.Option[config]
- func WithDisableTraceMiddleware(disable ...bool) lib_3rd.Option[config]
- func WithHeartbeatInterval(interval time.Duration) lib_3rd.Option[config]
- func WithMaxConcurrentConnection(maxConcurrentConnection int) lib_3rd.Option[config]
- func WithName(name string) lib_3rd.Option[config]
- func WithProtoName(protoName string) lib_3rd.Option[config]
- func WithSendChanSize(sendChanSize int) lib_3rd.Option[config]
- func WithServerCallbackInstance(instance ServerCallback) lib_3rd.Option[config]
- func WithVacuumInterval(interval time.Duration) lib_3rd.Option[config]
- type Handle
- type Server
- func (s *Server) Destroy() error
- func (s *Server) GetConnection(connID uint64) *connect.Connection
- func (s *Server) GracefulStop(ctx context.Context) error
- func (s *Server) IsRunning() bool
- func (s *Server) OnTCPConnectionClosed(conn *connect.Connection)
- func (s *Server) PackageName() string
- func (s *Server) Pause()
- func (s *Server) SendBroadcastMessage(msg any) error
- func (s *Server) SendMessageByConn(conn *connect.Connection, msg any) error
- func (s *Server) SendMessageByConnID(connID uint64, msg any) error
- func (s *Server) SendMessageProtoByConn(conn *connect.Connection, cntl *codec.MessageController, msg proto.Message) error
- func (s *Server) Serving()
- func (s *Server) Serving2()
- type ServerCallback
Constants
const KMaxConcurrentConnection = 10000000const KPackageName = "ftcp_server"Variables
var GetFountainInstance = Lib.GetFountainInstancevar GetFountainManager = Lib.GetFountainManagerSử dụng khi config instance ở dạng key:value; Nếu config instance ở dạng key:array thì sử dụng hàm InstallFountainInstances Nếu config ở dạng key:array thì sẽ chỉ install config phần tử đầu tiên mà thôi
Install with config format <key>:<value>; eg: ftcp:<value>
Usage:
config.yaml:
ftcp:
name: default_name
...
code.go
ftcp.InstallFountainInstance()
ftcp.WithConfigKey("ftcp").InstallFountainInstance()var InstallFountainInstance = Lib.InstallFountainInstanceSử dụng khi config instance ở dạng key:array<value>; Sẽ luôn cố gắng khởi tạo kể cả khi config ở dạng key:value
Install with config format <key>:array<value>; eg: ftcp:array<value>
Usage:
config.yaml:
ftcp:
- name: default_name
...
code.go
ftcp.InstallFountainInstances()
ftcp.WithConfigKey("ftcp").InstallFountainInstances()var InstallFountainInstances = Lib.InstallFountainInstancesvar KDefaultServerName = env.GetFullAppService(KPackageName)Truy cập thẳng tới bộ quản lý thư viện
var Lib = lib_3rd.NewLib(newServer, lib_3rd.WithDefaultConfigFunc[config, Server](DefaultConfig))var WithConfigKey = Lib.WithConfigKeyfunc Accept
func Accept(listener net.Listener) (net.Conn, error)Accept func. Server accept a connection.
func RegisterServiceHandler
func RegisterServiceHandler(x proto.Message, handler Handle)RegisterServiceHandler func;
func RegisterType
func RegisterType(x proto.Message, name string)RegisterType func; Register a type of object that can send or receive over ftcp;
func WithAddr
func WithAddr(addr string) lib_3rd.Option[config]func WithConfig
func WithConfig(conf *config) lib_3rd.Option[config]WithConfig
func WithConnectionMaxIdleTime
func WithConnectionMaxIdleTime(duration time.Duration) lib_3rd.Option[config]func WithDisableHeartbeat
func WithDisableHeartbeat(disable ...bool) lib_3rd.Option[config]func WithDisableTraceMiddleware
func WithDisableTraceMiddleware(disable ...bool) lib_3rd.Option[config]func WithHeartbeatInterval
func WithHeartbeatInterval(interval time.Duration) lib_3rd.Option[config]func WithMaxConcurrentConnection
func WithMaxConcurrentConnection(maxConcurrentConnection int) lib_3rd.Option[config]func WithName
func WithName(name string) lib_3rd.Option[config]func WithProtoName
func WithProtoName(protoName string) lib_3rd.Option[config]func WithSendChanSize
func WithSendChanSize(sendChanSize int) lib_3rd.Option[config]func WithServerCallbackInstance
func WithServerCallbackInstance(instance ServerCallback) lib_3rd.Option[config]func WithVacuumInterval
func WithVacuumInterval(interval time.Duration) lib_3rd.Option[config]type Handle
type Handle func(*connect.Connection, *codec.MessageController, proto.Message) errorfunc FindHandler
func FindHandler(msg proto.Message) HandleFindHandler func;
type Server
type Server struct {
*runnable.ServerInstance
// contains filtered or unexported fields
}func (*Server) Destroy
func (s *Server) Destroy() errorDestroy func
func (*Server) GetConnection
func (s *Server) GetConnection(connID uint64) *connect.ConnectionGetConnection func
func (*Server) GracefulStop
func (s *Server) GracefulStop(ctx context.Context) errorGracefulStop implements Runnable interface it will stop echo server gracefully
func (*Server) IsRunning
func (s *Server) IsRunning() boolIsRunning func
func (*Server) OnTCPConnectionClosed
func (s *Server) OnTCPConnectionClosed(conn *connect.Connection)OnTCPConnectionClosed func to implement connect.ConnectionClosedCallback interface
func (*Server) PackageName
func (s *Server) PackageName() stringPackageName package name
func (*Server) Pause
func (s *Server) Pause()Pause func
func (*Server) SendBroadcastMessage
func (s *Server) SendBroadcastMessage(msg any) errorSendBroadcastMessage func; Send msg to all connection that was connected msg can be either *codec.Message or proto.Message or []byte
func (*Server) SendMessageByConn
func (s *Server) SendMessageByConn(conn *connect.Connection, msg any) errorfunc (*Server) SendMessageByConnID
func (s *Server) SendMessageByConnID(connID uint64, msg any) errorSendMessageByConnID func; Send data according to ConnID
func (*Server) SendMessageProtoByConn
func (s *Server) SendMessageProtoByConn(conn *connect.Connection, cntl *codec.MessageController, msg proto.Message) errorSendMessageProtoByConn func; Find client by addr and send msg to all connection that was connected
func (*Server) Serving
func (s *Server) Serving()Serve func need run in a goroutine
func (*Server) Serving2
func (s *Server) Serving2()Serve2 func; Using connect.NewBufferedConn, not comparable with codec interface TODO(@Kim Ericko): A tricky way
type ServerCallback
type ServerCallback interface {
OnNewTCPClient(conn *connect.Connection)
OnTCPClientDataArrived(conn *connect.Connection, msg any) error
OnTCPClientClosed(conn *connect.Connection)
}Generated by gomarkdoc