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) AsyncCall(serviceMethod string, arg interface{}, result interface{}, ...) tp.CallCmd
- func (c *Client) Call(serviceMethod string, arg interface{}, result interface{}, ...) tp.CallCmd
- func (c *Client) Close()
- func (c *Client) Peer() tp.Peer
- func (c *Client) PluginContainer() *tp.PluginContainer
- func (c *Client) Push(serviceMethod string, arg interface{}, setting ...tp.MessageSetting) *tp.Status
- 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 tp.ProtoFunc)
- func (c *Client) SubRoute(pathPrefix string, plugin ...tp.Plugin) *tp.SubRouter
- func (c *Client) UseCallHeartbeat()
- 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 ...tp.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) RouteCall(ctrlStruct interface{}, plugin ...tp.Plugin) []string
- func (s *Server) RouteCallFunc(callHandleFunc 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 ...tp.ProtoFunc) (tp.Session, *tp.Status)
- func (s *Server) SetBindErrorFunc(fn binder.ErrorFunc)
- func (s *Server) SetUnknownCall(fn func(tp.UnknownCallCtx) (interface{}, *tp.Status), plugin ...tp.Plugin)
- func (s *Server) SetUnknownPush(fn func(tp.UnknownPushCtx) *tp.Status, plugin ...tp.Plugin)
- func (s *Server) SubRoute(pathPrefix string, plugin ...tp.Plugin) *tp.SubRouter
- type SrvConfig
Constants ¶
This section is empty.
Variables ¶
var ( // RerrClientClosed: client is closed. RerrClientClosed = tp.NewStatus(100, "client is closed", "") // RerrInvalidParameter: Invalid Parameter RerrInvalidParameter = tp.NewStatus(tp.CodeBadMessage, "Invalid Parameter", "") // RerrInternalServerError: System is busy, please try again later RerrInternalServerError = tp.NewStatus(tp.CodeInternalServerError, "System is busy, please try again later", "") // RerrNotFound: Not Found RerrNotFound = tp.NewStatus(tp.CodeNotFound, "Not Found", "") // RerrNotOnline: User is not online RerrNotOnline = tp.NewStatus(tp.CodeNotFound, "Not Found", "User is not online") // RerrRenderFailed: Template Rendering Failed RerrRenderFailed = tp.NewStatus(tp.CodeInternalServerError, "Template Rendering Failed", "") )
NOTE: error code range [-1,999]
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 { 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 */ 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 */ 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) AsyncCall ¶
func (c *Client) AsyncCall( serviceMethod string, arg interface{}, result interface{}, callCmdChan chan<- tp.CallCmd, setting ...tp.MessageSetting, ) tp.CallCmd
AsyncCall 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) Call ¶
func (c *Client) Call(serviceMethod string, arg interface{}, result interface{}, setting ...tp.MessageSetting) tp.CallCmd
Call 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) PluginContainer ¶
func (c *Client) PluginContainer() *tp.PluginContainer
PluginContainer returns the global plugin container.
func (*Client) Push ¶
func (c *Client) Push(serviceMethod string, arg interface{}, setting ...tp.MessageSetting) *tp.Status
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) RoutePushFunc ¶
RoutePushFunc registers PUSH handler, and returns the path.
func (*Client) SetProtoFunc ¶
SetProtoFunc sets tp.ProtoFunc.
func (*Client) UseCallHeartbeat ¶
func (c *Client) UseCallHeartbeat()
UseCallHeartbeat uses CALL method to ping.
func (*Client) UsePushHeartbeat ¶
func (c *Client) UsePushHeartbeat()
UsePushHeartbeat uses PUSH method to ping.
type Linker ¶
type Linker interface { // Select selects a service address by URI path. Select(uriPath string, exclude map[string]struct{}) (addr string, stat *tp.Status) // 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) 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) RouteCallFunc ¶
RouteCallFunc registers CALL handler, and returns the path.
func (*Server) RoutePushFunc ¶
RoutePushFunc registers PUSH handler, and returns the path.
func (*Server) SetBindErrorFunc ¶
SetBindErrorFunc sets the binding or balidating error function. Note: If fn=nil, set as default.
func (*Server) SetUnknownCall ¶
func (s *Server) SetUnknownCall(fn func(tp.UnknownCallCtx) (interface{}, *tp.Status), plugin ...tp.Plugin)
SetUnknownCall sets the default handler, which is called when no handler for CALL 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'.
func (*SrvConfig) PeerConfig ¶
func (s *SrvConfig) PeerConfig() tp.PeerConfig
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. |
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/proto
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. |
micro
|
|
run/fsnotify
Package fsnotify implements file system notification.
|
Package fsnotify implements file system notification. |
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. |