Documentation ¶
Overview ¶
Package tp-micro is a simple, powerful micro service framework based on Teleport.
Copyright 2018 HenryLee and xiaoenai. 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 ¶
- 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, arg interface{}, result interface{}, pullCmdChan chan<- tp.PullCmd, ...) tp.PullCmd
- func (c *Client) Close()
- func (c *Client) Peer() tp.Peer
- func (c *Client) PluginContainer() *tp.PluginContainer
- func (c *Client) Pull(uri string, arg interface{}, result interface{}, ...) tp.PullCmd
- func (c *Client) Push(uri string, arg 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
- func (c *Client) UsePullHeartbeat()
- func (c *Client) UsePushHeartbeat()
- 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) ListenAndServe(protoFunc ...socket.ProtoFunc) error
- func (s *Server) Peer() tp.Peer
- func (s *Server) PluginContainer() *tp.PluginContainer
- 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) SetBindErrorFunc(fn binder.ErrorFunc)
- 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 ¶
This section is empty.
Variables ¶
var NotFoundService = tp.NewRerror(tp.CodeNotFound, "Not Found Service", "not found service")
NotFoundService error: not found service in linker.
Functions ¶
func InnerIpPort ¶
InnerIpPort returns the service's intranet address, such as '192.168.1.120: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 { Network string `yaml:"network" ini:"network" comment:"Network; tcp, tcp4, tcp6, unix or unixpacket"` LocalIP string `yaml:"local_ip" ini:"local_ip" comment:"Local IP"` 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"` PrintDetail bool `yaml:"print_detail" ini:"print_detail" comment:"Is print body and metadata or not"` CountTime bool `yaml:"count_time" ini:"count_time" comment:"Is count cost time or not"` 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 NewClient ¶
NewClient creates a client peer.
func (*Client) AsyncPull ¶
func (c *Client) AsyncPull( uri string, arg interface{}, result interface{}, pullCmdChan chan<- tp.PullCmd, setting ...socket.PacketSetting, ) tp.PullCmd
AsyncPull sends a packet and receives reply asynchronously. Note:
If the arg 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) PluginContainer ¶
func (c *Client) PluginContainer() *tp.PluginContainer
PluginContainer returns the global plugin container.
func (*Client) Pull ¶
func (c *Client) Pull(uri string, arg interface{}, result interface{}, setting ...socket.PacketSetting) tp.PullCmd
Pull sends a packet and receives reply. Note:
If the arg 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 arg 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) RoutePush ¶
RoutePush registers PUSH handlers, and returns the paths.
func (*Client) RoutePushFunc ¶
RoutePushFunc registers PUSH handler, and returns the path.
func (*Client) SetProtoFunc ¶
SetProtoFunc sets socket.ProtoFunc.
func (*Client) SubRoute ¶
SubRoute adds handler group.
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.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server server peer
func NewServer ¶
NewServer creates a server peer.
func (*Server) CountSession ¶
CountSession returns the number of sessions.
func (*Server) GetSession ¶
GetSession gets the session by id.
func (*Server) ListenAndServe ¶
ListenAndServe turns on the listening service.
func (*Server) PluginContainer ¶
func (s *Server) PluginContainer() *tp.PluginContainer
PluginContainer returns the global plugin container.
func (*Server) RangeSession ¶
RangeSession ranges all sessions. If fn returns false, stop traversing.
func (*Server) RoutePull ¶
RoutePull registers PULL handlers, and returns the paths.
func (*Server) RoutePullFunc ¶
RoutePullFunc registers PULL handler, and returns the path.
func (*Server) RoutePush ¶
RoutePush registers PUSH handlers, and returns the paths.
func (*Server) RoutePushFunc ¶
RoutePushFunc registers PUSH handler, and returns the path.
func (*Server) Router ¶
Router returns the root router of pull or push handlers.
func (*Server) ServeConn ¶
ServeConn serves the connection and returns a session.
func (*Server) SetBindErrorFunc ¶
SetBindErrorFunc sets the binding or balidating error function. Note: If fn=nil, set as default.
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 { 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"` 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"` PrintDetail bool `yaml:"print_detail" ini:"print_detail" comment:"Is print body and metadata or not"` CountTime bool `yaml:"count_time" ini:"count_time" comment:"Is count cost time or not"` 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 '9090'.
func (*SrvConfig) OuterIpPort ¶
OuterIpPort returns the service's extranet address, such as '113.116.141.121:8080'.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
micro
Command micro is a deployment tools of tp-micro frameware.
|
Command micro is a deployment tools of tp-micro frameware. |
micro/run/fsnotify
Package fsnotify implements file system notification.
|
Package fsnotify implements file system notification. |
Package discovery is the service discovery module implemented by ETCD.
|
Package discovery is the service discovery module implemented by ETCD. |
examples
|
|
Package gateway is the main program for TCP and HTTP services.
|
Package gateway is the main program for TCP and HTTP services. |
helper/agent
Package agent is a generated protocol buffer package.
|
Package agent is a generated protocol buffer package. |
helper/gray/logic/model
Package model is a generated protocol buffer package.
|
Package model is a generated protocol buffer package. |
helper/gray/types
Package types is a generated protocol buffer package.
|
Package types is a generated protocol buffer package. |
types
Package types is a generated protocol buffer package.
|
Package types is a generated protocol buffer package. |
mod-html
Package html is HTML render for http client.
|
Package html is HTML render for http client. |
model
|
|
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. |
redis
redis (cluster) client package.
|
redis (cluster) client package. |
sqlx
Package sqlx provides general purpose extensions to database/sql.
|
Package sqlx provides general purpose extensions to database/sql. |
sqlx/reflectx
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages.
|
Package reflectx implements extensions to the standard reflect lib suitable for implementing marshalling and unmarshalling packages. |