Documentation ¶
Overview ¶
Package tp-micro is a simple, powerful micro service framework based on Teleport.
Copyright 2018 HenryLee. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- func InnerIpPort(port string) (string, error)
- func OuterIpPort(port string) (string, error)
- type CircuitBreakerConfig
- type CliConfig
- type Client
- func (c *Client) AsyncPull(uri string, args interface{}, reply interface{}, pullCmdChan chan<- tp.PullCmd, ...) tp.PullCmd
- func (c *Client) Close()
- func (c *Client) Peer() tp.Peer
- func (c *Client) Pull(uri string, args interface{}, reply interface{}, ...) tp.PullCmd
- func (c *Client) Push(uri string, args interface{}, setting ...socket.PacketSetting) *tp.Rerror
- func (c *Client) RoutePush(ctrlStruct interface{}, plugin ...tp.Plugin) []string
- func (c *Client) RoutePushFunc(pushHandleFunc interface{}, plugin ...tp.Plugin) string
- func (c *Client) SetProtoFunc(protoFunc socket.ProtoFunc)
- func (c *Client) SubRoute(pathPrefix string, plugin ...tp.Plugin) *tp.SubRouter
- type Linker
- type Server
- func (s *Server) Close() error
- func (s *Server) CountSession() int
- func (s *Server) GetSession(sessionId string) (tp.Session, bool)
- func (s *Server) Listen(protoFunc ...socket.ProtoFunc) error
- func (s *Server) Peer() tp.Peer
- func (s *Server) RangeSession(fn func(sess tp.Session) bool)
- func (s *Server) RoutePull(ctrlStruct interface{}, plugin ...tp.Plugin) []string
- func (s *Server) RoutePullFunc(pullHandleFunc interface{}, plugin ...tp.Plugin) string
- func (s *Server) RoutePush(ctrlStruct interface{}, plugin ...tp.Plugin) []string
- func (s *Server) RoutePushFunc(pushHandleFunc interface{}, plugin ...tp.Plugin) string
- func (s *Server) Router() *tp.Router
- func (s *Server) ServeConn(conn net.Conn, protoFunc ...socket.ProtoFunc) (tp.Session, error)
- func (s *Server) SetUnknownPull(fn func(tp.UnknownPullCtx) (interface{}, *tp.Rerror), plugin ...tp.Plugin)
- func (s *Server) SetUnknownPush(fn func(tp.UnknownPushCtx) *tp.Rerror, plugin ...tp.Plugin)
- func (s *Server) SubRoute(pathPrefix string, plugin ...tp.Plugin) *tp.SubRouter
- type SrvConfig
Constants ¶
const ( RerrCodeClientClosed int32 = 10000 RerrCodeBind int32 = 10001 )
error codes
Variables ¶
var NotFoundService = tp.NewRerror(tp.CodeDialFailed, "Dial Failed", "not found service")
NotFoundService error: not found service in linker.
var ( // RerrClosed reply error: client is closed RerrClosed = tp.NewRerror(RerrCodeClientClosed, "client is closed", "") )
Functions ¶
func InnerIpPort ¶
InnerIpPort returns the service's intranet address, such as '192.168.1.120:8080'.
func OuterIpPort ¶
OuterIpPort returns the service's extranet address, such as '113.116.141.121:8080'.
Types ¶
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct { Enable bool `yaml:"enable" ini:"enable" comment:"Whether to use circuit breaker"` ErrorPercentage int `` /* 151-byte string literal not displayed */ BreakDuration time.Duration `yaml:"break_duration" ini:"break_duration" comment:"The period of one-cycle break in milliseconds; must ≥ 1ms"` }
CircuitBreakerConfig circuit breaker config
type CliConfig ¶
type CliConfig struct { TlsCertFile string `yaml:"tls_cert_file" ini:"tls_cert_file" comment:"TLS certificate file path"` TlsKeyFile string `yaml:"tls_key_file" ini:"tls_key_file" comment:"TLS key file path"` DefaultSessionAge time.Duration `` /* 152-byte string literal not displayed */ DefaultContextAge time.Duration `` /* 165-byte string literal not displayed */ DefaultDialTimeout time.Duration `` /* 139-byte string literal not displayed */ RedialTimes int `` /* 176-byte string literal not displayed */ Failover int `yaml:"failover" ini:"failover" comment:"The maximum times of failover"` SlowCometDuration time.Duration `yaml:"slow_comet_duration" ini:"slow_comet_duration" comment:"Slow operation alarm threshold; ns,µs,ms,s ..."` DefaultBodyCodec string `yaml:"default_body_codec" ini:"default_body_codec" comment:"Default body codec type id"` PrintBody bool `yaml:"print_body" ini:"print_body" comment:"Is print body or not"` CountTime bool `yaml:"count_time" ini:"count_time" comment:"Is count cost time or not"` Network string `yaml:"network" ini:"network" comment:"Network; tcp, tcp4, tcp6, unix or unixpacket"` HeartbeatSecond int `` /* 189-byte string literal not displayed */ SessMaxQuota int `yaml:"sess_max_quota" ini:"sess_max_quota" comment:"The maximum number of sessions in the connection pool"` SessMaxIdleDuration time.Duration `` /* 153-byte string literal not displayed */ CircuitBreaker CircuitBreakerConfig `yaml:"circuit_breaker" ini:"circuit_breaker" comment:"Circuit breaker config"` }
CliConfig client config Note:
yaml tag is used for github.com/henrylee2cn/cfgo ini tag is used for github.com/henrylee2cn/ini
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client client peer
func (*Client) AsyncPull ¶
func (c *Client) AsyncPull( uri string, args interface{}, reply interface{}, pullCmdChan chan<- tp.PullCmd, setting ...socket.PacketSetting, ) tp.PullCmd
AsyncPull sends a packet and receives reply asynchronously. Note:
If the args is []byte or *[]byte type, it can automatically fill in the body codec name. If the session is a client role and PeerConfig.RedialTimes>0, it is automatically re-called once after a failure. Do not support failover to try again
func (*Client) Pull ¶
func (c *Client) Pull(uri string, args interface{}, reply interface{}, setting ...socket.PacketSetting) tp.PullCmd
Pull sends a packet and receives reply. Note:
If the args is []byte or *[]byte type, it can automatically fill in the body codec name; If the session is a client role and PeerConfig.RedialTimes>0, it is automatically re-called once after a failure.
func (*Client) Push ¶
Push sends a packet, but do not receives reply. Note:
If the args is []byte or *[]byte type, it can automatically fill in the body codec name; If the session is a client role and PeerConfig.RedialTimes>0, it is automatically re-called once after a failure.
func (*Client) RoutePushFunc ¶
RoutePushFunc registers PUSH handler, and returns the path.
func (*Client) SetProtoFunc ¶
SetProtoFunc sets socket.ProtoFunc.
type Linker ¶
type Linker interface { // Select selects a service address by URI path. Select(uriPath string, exclude map[string]struct{}) (addr string, rerr *tp.Rerror) // Len returns the number of nodes corresponding to the URI. Len(uriPath string) int // WatchOffline pushs service node offline notification. WatchOffline() <-chan string // Close closes the linker. Close() }
Linker linker for client.
func NewStaticLinker ¶
NewStaticLinker creates a static linker.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server server peer
func (*Server) CountSession ¶
CountSession returns the number of sessions.
func (*Server) GetSession ¶
GetSession gets the session by id.
func (*Server) RangeSession ¶
RangeSession ranges all sessions. If fn returns false, stop traversing.
func (*Server) RoutePullFunc ¶
RoutePullFunc registers PULL handler, and returns the path.
func (*Server) RoutePushFunc ¶
RoutePushFunc registers PUSH handler, and returns the path.
func (*Server) SetUnknownPull ¶
func (s *Server) SetUnknownPull(fn func(tp.UnknownPullCtx) (interface{}, *tp.Rerror), plugin ...tp.Plugin)
SetUnknownPull sets the default handler, which is called when no handler for PULL is found.
func (*Server) SetUnknownPush ¶
SetUnknownPush sets the default handler, which is called when no handler for PUSH is found.
type SrvConfig ¶
type SrvConfig struct { TlsCertFile string `yaml:"tls_cert_file" ini:"tls_cert_file" comment:"TLS certificate file path"` TlsKeyFile string `yaml:"tls_key_file" ini:"tls_key_file" comment:"TLS key file path"` DefaultSessionAge time.Duration `` /* 148-byte string literal not displayed */ DefaultContextAge time.Duration `` /* 161-byte string literal not displayed */ SlowCometDuration time.Duration `yaml:"slow_comet_duration" ini:"slow_comet_duration" comment:"Slow operation alarm threshold; ns,µs,ms,s ..."` DefaultBodyCodec string `yaml:"default_body_codec" ini:"default_body_codec" comment:"Default body codec type id"` PrintBody bool `yaml:"print_body" ini:"print_body" comment:"Is print body or not"` CountTime bool `yaml:"count_time" ini:"count_time" comment:"Is count cost time or not"` Network string `yaml:"network" ini:"network" comment:"Network; tcp, tcp4, tcp6, unix or unixpacket"` ListenAddress string `yaml:"listen_address" ini:"listen_address" comment:"Listen address; for server role"` EnableHeartbeat bool `yaml:"enable_heartbeat" ini:"enable_heartbeat" comment:"enable heartbeat"` }
SrvConfig server config Note:
yaml tag is used for github.com/henrylee2cn/cfgo ini tag is used for github.com/henrylee2cn/ini
func (*SrvConfig) InnerIpPort ¶
InnerIpPort returns the service's intranet address, such as '192.168.1.120:8080'.
func (*SrvConfig) ListenPort ¶
ListenPort returns the listened port, such as '8080'.
func (*SrvConfig) OuterIpPort ¶
OuterIpPort returns the service's extranet address, such as '113.116.141.121:8080'.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package discovery is the service discovery module implemented by ETCD.
|
Package discovery is the service discovery module implemented by ETCD. |
etcd
etcd package is the [ETCD](https://github.com/coreos/etcd) client v3 mirror.
|
etcd package is the [ETCD](https://github.com/coreos/etcd) client v3 mirror. |
examples
|
|