framework

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2019 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Copyright 2009 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	// Defaults used by HandleHTTP
	DefaultRPCPath   = "/_goRPC_"
	DefaultDebugPath = "/debug/rpc"
)
View Source
const (
	DefaultHostURL = "gotree:3000"
)
View Source
const (
	StatusUnprocessableEntity = 422
)

Variables

View Source
var App appInter
View Source
var DefaultServer = NewServer()

DefaultServer is the default instance of *Server.

View Source
var ErrConnect = errors.New("dial is fail")
View Source
var ErrNetwork = errors.New("connection is shut down")
View Source
var ErrShutdown = errors.New("connection is shut down")
View Source
var Unexpected = errors.New("unexpected EOF")

Functions

func AppDaemon

func AppDaemon()

func AppRestart

func AppRestart(name, addr string, port int)

func AppStop

func AppStop(name, addr string, port int)

func ConvertAssign

func ConvertAssign(dest, src interface{}) error

func CurrentTimeNum

func CurrentTimeNum() int

func Exit

func Exit(errorMsg ...interface{})

func ExpandValueEnv

func ExpandValueEnv(value string) (realValue string)

func FieldEmpty

func FieldEmpty(v reflect.Value) error

func FileExists

func FileExists(path string) bool

FileExists

func GetSysClock

func GetSysClock() int64

GetSysClock

func LoadConfig

func LoadConfig(project string) (e error)

func Log

func Log() *log

func ParseBool

func ParseBool(val interface{}) (value bool, err error)

func ParseStruct

func ParseStruct(t reflect.Type, v reflect.Value, def string, sn string) (sInds []reflect.Value, eTyps []reflect.Type, defs []string, structName []string)

func Register

func Register(rcvr interface{}) error

Register publishes the receiver's methods in the DefaultServer.

func RegisterBreaker

func RegisterBreaker(cmd breakerCmd, rangeSec int, timeoutRatio float32, resumeSec int)

RegisterBreaker 注册熔断

func RegisterConf

func RegisterConf(name string, adapter Config)

func RegisterName

func RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func RunDay

func RunDay(hour, minute int, child func(), name string)

func RunDefaultTimer

func RunDefaultTimer(tick int64, child func())

func RunTickStopTimer

func RunTickStopTimer(tick int64, child TickStopRun)

func ServeCodec

func ServeCodec(codec ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

func ServeRequest

func ServeRequest(codec ServerCodec) error

ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.

func Testing

func Testing() bool

func UnRegister

func UnRegister(name string)

Types

type CallBreak

type CallBreak struct {
	ComEntity
}

func (*CallBreak) Breaking

func (this *CallBreak) Breaking(cmd _cmdInrer) bool

func (*CallBreak) Call

func (this *CallBreak) Call(cmd _cmdInrer, timeout bool)

func (*CallBreak) Gotree

func (this *CallBreak) Gotree() *CallBreak

func (*CallBreak) RunTick

func (this *CallBreak) RunTick()

func (*CallBreak) StopTick

func (this *CallBreak) StopTick()

type CallClient

type CallClient struct {
	ComEntity
	// contains filtered or unexported fields
}

func (*CallClient) Close

func (this *CallClient) Close()

func (*CallClient) Do

func (this *CallClient) Do(inArg interface{}, reply interface{}) (err error)

func (*CallClient) Gotree

func (this *CallClient) Gotree(concurrency int, timeout int) *CallClient

并发数量 和rpc失败重试次数

func (*CallClient) Start

func (this *CallClient) Start()

type CallCmd

type CallCmd struct {
	GotreeBase
	Gseq string `opt:"null"`
	Head string `opt:"null"`
}

func (*CallCmd) Gotree

func (this *CallCmd) Gotree(child interface{}) *CallCmd

func (*CallCmd) Header

func (this *CallCmd) Header(k string) string

func (*CallCmd) RemoteAddr

func (this *CallCmd) RemoteAddr(naddr interface{}) (string, error)

client调用RemoteAddr 传入NodeMaster, 获取远程地址

func (*CallCmd) ServiceMethod

func (this *CallCmd) ServiceMethod() string

func (*CallCmd) SetHeader

func (this *CallCmd) SetHeader(k string, v string)

func (*CallCmd) SetHttpHeader

func (this *CallCmd) SetHttpHeader(head http.Header)

type CallController

type CallController struct {
	GotreeBase
	// contains filtered or unexported fields
}

func (*CallController) CallInvoke_

func (this *CallController) CallInvoke_(conn net.Conn, gs *GotreeService)

func (*CallController) CallName_

func (this *CallController) CallName_() string

用于rpcserver 注册,不可重写

func (*CallController) FUCK_YOU_

func (this *CallController) FUCK_YOU_(cmd int, result *int) error

func (*CallController) Gotree

func (this *CallController) Gotree(child interface{}) *CallController

Gotree 构造

func (*CallController) OnCreate

func (this *CallController) OnCreate(method string, argv interface{})

func (*CallController) OnDestory

func (this *CallController) OnDestory(method string, reply interface{}, e error)

func (*CallController) RemoteAddr

func (this *CallController) RemoteAddr() string

type CallQps

type CallQps struct {
	ComEntity
	// contains filtered or unexported fields
}

func (*CallQps) ComQpsBeginTime

func (this *CallQps) ComQpsBeginTime(args ...interface{})

func (*CallQps) Gotree

func (this *CallQps) Gotree() *CallQps

func (*CallQps) Qps

func (this *CallQps) Qps(serviceMethod string, ms int64)

type CallRoute

type CallRoute struct {
	ComEntity
	// contains filtered or unexported fields
}

func (*CallRoute) GetAddrList

func (this *CallRoute) GetAddrList(SerName string) *panels

func (*CallRoute) Gotree

func (this *CallRoute) Gotree() *CallRoute

func (*CallRoute) LocalAddCom

func (this *CallRoute) LocalAddCom(name, ip, port string, id int)

type CmdHeader

type CmdHeader struct {
}

func (*CmdHeader) Get

func (this *CmdHeader) Get(src, key string) string

func (*CmdHeader) Set

func (this *CmdHeader) Set(src, key, val string) string

type ComEntity

type ComEntity struct {
	GotreeBase
	// contains filtered or unexported fields
}

func (*ComEntity) AddComObject

func (this *ComEntity) AddComObject(obj interface{})

AddComObject

func (*ComEntity) GetComObject

func (this *ComEntity) GetComObject(obj interface{}) error

GetComObject

func (*ComEntity) Gotree

func (this *ComEntity) Gotree(child interface{}) *ComEntity

func (*ComEntity) UpdateComObject

func (this *ComEntity) UpdateComObject(component *ComObject)

UpdateComObject

type ComLocator

type ComLocator struct {
	ComEntity
	// contains filtered or unexported fields
}

func (*ComLocator) Add

func (this *ComLocator) Add(obj interface{})

func (*ComLocator) Broadcast

func (this *ComLocator) Broadcast(fun string, arg interface{}) error

func (*ComLocator) Exist

func (this *ComLocator) Exist(com interface{}) bool

func (*ComLocator) Fetch

func (this *ComLocator) Fetch(obj interface{}) error

func (*ComLocator) Get

func (this *ComLocator) Get(name string) interface{}

func (*ComLocator) Gotree

func (this *ComLocator) Gotree() *ComLocator

func (*ComLocator) Remove

func (this *ComLocator) Remove(obj interface{})

type ComNode

type ComNode interface {
	RandomAddr() string                       //随机地址
	BalanceAddr() string                      //负载均衡地址
	HostHashRpcAddr(value interface{}) string //热一致性哈希地址
	HashRpcAddr(value interface{}) string     //一致性哈希地址
	SlaveAddr() string                        //返回随机从节点  主节点:节点id=1,当只有主节点返回主节点
	MasterAddr() string                       //返回主节点
	AllCom() (list []*Panel)                  //获取全部节点,自定义分发
}

type ComObject

type ComObject struct {
	// contains filtered or unexported fields
}

func (*ComObject) Add

func (this *ComObject) Add(obj interface{})

func (*ComObject) Broadcast

func (this *ComObject) Broadcast(method string, arg interface{})

func (*ComObject) Get

func (this *ComObject) Get(obj interface{}) error

func (*ComObject) Gotree

func (this *ComObject) Gotree() *ComObject

func (*ComObject) Remove

func (this *ComObject) Remove(obj interface{})

type ComPanel

type ComPanel struct {
	Name  string
	Port  string
	ID    int
	Extra []interface{} `opt:"null"`
}

type ConHash

type ConHash struct {
	// contains filtered or unexported fields
}

func (*ConHash) Add

func (this *ConHash) Add(addr interface{})

func (*ConHash) Check

func (this *ConHash) Check(addr interface{}) bool

CheckAddr检查该物理地址是否存在

func (*ConHash) ConHash

func (this *ConHash) ConHash() *ConHash

func (*ConHash) Remove

func (this *ConHash) Remove(addr interface{})

func (*ConHash) Search

func (this *ConHash) Search(value uint32) interface{}

Search查找节点位置

type Config

type Config interface {
	Parse(key string) (Configer, error)
}

type Configer

type Configer interface {
	DefaultString(key string, defaultVal string) string
	DefaultInt(key string, defaultVal int) int
	DefaultInt64(key string, defaultVal int64) int64
	DefaultBool(key string, defaultVal bool) bool
	DefaultFloat(key string, defaultVal float64) float64
	GetSection(section string) (map[string]string, error)
	String(key string) string
}

func GetConfig

func GetConfig() Configer

func NewConfig

func NewConfig(adapterName, filename string) (Configer, error)

type Func

type Func func() interface{}

Func

func (Func) Value

func (f Func) Value() interface{}

type GotreeBase

type GotreeBase struct {
	// contains filtered or unexported fields
}

func (*GotreeBase) AddChild

func (this *GotreeBase) AddChild(parnet interface{}, child ...interface{})

func (*GotreeBase) AddEvent

func (this *GotreeBase) AddEvent(event string, handle handlerFunc)

func (*GotreeBase) Event

func (this *GotreeBase) Event(event string, args ...interface{})

func (*GotreeBase) GetChild

func (this *GotreeBase) GetChild(parnet interface{}) (child interface{}, err error)

func (*GotreeBase) Gotree

func (this *GotreeBase) Gotree(child interface{}) *GotreeBase

func (*GotreeBase) RemoveEvent

func (this *GotreeBase) RemoveEvent(event string)

func (*GotreeBase) TopChild

func (this *GotreeBase) TopChild() (result interface{})

type GotreeMap

type GotreeMap struct {
	// contains filtered or unexported fields
}

func (*GotreeMap) AllKey

func (this *GotreeMap) AllKey() []interface{}

func (*GotreeMap) DelAll

func (this *GotreeMap) DelAll()

func (*GotreeMap) Exist

func (this *GotreeMap) Exist(key interface{}) bool

func (*GotreeMap) Get

func (this *GotreeMap) Get(key interface{}, value interface{}) error

func (*GotreeMap) Gotree

func (this *GotreeMap) Gotree(openLock ...bool) *GotreeMap

func (*GotreeMap) Interface

func (this *GotreeMap) Interface(key interface{}) interface{}

func (*GotreeMap) Remove

func (this *GotreeMap) Remove(key interface{})

func (*GotreeMap) Set

func (this *GotreeMap) Set(key interface{}, value interface{})

func (*GotreeMap) SetOrStore

func (this *GotreeMap) SetOrStore(key interface{}, value interface{}) (v interface{}, set bool)

type GotreeService

type GotreeService struct {
	GotreeBase
	// contains filtered or unexported fields
}

func (*GotreeService) Actions

func (this *GotreeService) Actions() []string

Actions

func (*GotreeService) Calls

func (this *GotreeService) Calls() int

func (*GotreeService) CancelController

func (this *GotreeService) CancelController(name string)

CancelController

func (*GotreeService) Close

func (this *GotreeService) Close()

func (*GotreeService) Gotree

func (this *GotreeService) Gotree() *GotreeService

func (*GotreeService) Hook

func (this *GotreeService) Hook(key string, value interface{})

func (*GotreeService) RegController

func (this *GotreeService) RegController(controller interface{})

RegController

func (*GotreeService) Run

func (this *GotreeService) Run(addr string)

func (*GotreeService) Runtime

func (this *GotreeService) Runtime() RuntimeStack

type Hash

type Hash struct {
	// contains filtered or unexported fields
}

func (*Hash) Gotree

func (this *Hash) Gotree(mod uint32) *Hash

func (*Hash) HashNodeSum

func (this *Hash) HashNodeSum(v interface{}, modarg ...int) int

type HealthClient

type HealthClient struct {
	ComEntity

	AppRemote []*struct {
		Addr      string
		Port      int
		StartPort int
	}

	StartTime    string
	LastInfoTime int64
	// contains filtered or unexported fields
}

func (*HealthClient) AddAppRemote

func (this *HealthClient) AddAppRemote(ip string, port int)

func (*HealthClient) AddDaoByNode

func (this *HealthClient) AddDaoByNode(name string, id int, args ...interface{})

func (*HealthClient) AddRemoteAddr

func (this *HealthClient) AddRemoteAddr(RemoteAddr string)

AddRemoteSerAddr 加入远程地址

func (*HealthClient) Close

func (this *HealthClient) Close()

func (*HealthClient) Gotree

func (this *HealthClient) Gotree() *HealthClient

func (*HealthClient) Start

func (this *HealthClient) Start()

type HealthController

type HealthController struct {
	CallController
}

func (*HealthController) AppInfo

func (this *HealthController) AppInfo(arg interface{}, ret *string) error

func (*HealthController) ComQps

func (this *HealthController) ComQps(arg interface{}, ret *string) error

ComQps

func (*HealthController) ComQpsBeginTime

func (this *HealthController) ComQpsBeginTime(arg interface{}, ret *string) error

ComQpsBeginTime

func (*HealthController) ComStatus

func (this *HealthController) ComStatus(arg interface{}, ret *string) error

func (*HealthController) DaoInfo

func (this *HealthController) DaoInfo(arg interface{}, ret *string) error

func (*HealthController) DaoServerStatus

func (this *HealthController) DaoServerStatus(arg interface{}, ret *string) error

func (*HealthController) Gotree

func (this *HealthController) Gotree() *HealthController

func (*HealthController) HandShake

func (this *HealthController) HandShake(coms struct {
	ComList []ComPanel
}, ret *int) error

func (*HealthController) Ping

func (this *HealthController) Ping(arg interface{}, ret *int) error

api 服务器发来的握手

func (*HealthController) ProcessId

func (this *HealthController) ProcessId(arg interface{}, ret *int) error

ProcessId 获取进程id

type IniConfig

type IniConfig struct {
}

func (*IniConfig) Parse

func (ini *IniConfig) Parse(name string) (Configer, error)

type IniConfigContainer

type IniConfigContainer struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*IniConfigContainer) Bool

func (c *IniConfigContainer) Bool(key string) (bool, error)

func (*IniConfigContainer) DefaultBool

func (c *IniConfigContainer) DefaultBool(key string, defaultval bool) bool

func (*IniConfigContainer) DefaultFloat

func (c *IniConfigContainer) DefaultFloat(key string, defaultval float64) float64

func (*IniConfigContainer) DefaultInt

func (c *IniConfigContainer) DefaultInt(key string, defaultval int) int

func (*IniConfigContainer) DefaultInt64

func (c *IniConfigContainer) DefaultInt64(key string, defaultval int64) int64

func (*IniConfigContainer) DefaultString

func (c *IniConfigContainer) DefaultString(key string, defaultval string) string

func (*IniConfigContainer) Float

func (c *IniConfigContainer) Float(key string) (float64, error)

func (*IniConfigContainer) GetSection

func (c *IniConfigContainer) GetSection(section string) (map[string]string, error)

func (*IniConfigContainer) Int

func (c *IniConfigContainer) Int(key string) (int, error)

func (*IniConfigContainer) Int64

func (c *IniConfigContainer) Int64(key string) (int64, error)

func (*IniConfigContainer) String

func (c *IniConfigContainer) String(key string) string

type KeyValue

type KeyValue struct {
	Key   string
	Value insideVar
}

KeyValue

type Limiting

type Limiting struct {
	// contains filtered or unexported fields
}

func (*Limiting) Go

func (this *Limiting) Go(fun func() error) (e error)

func (*Limiting) Gotree

func (this *Limiting) Gotree(count int) *Limiting

type NetConn

type NetConn struct {
	GotreeBase

	UserAgent string
	// contains filtered or unexported fields
}

func (*NetConn) Close

func (this *NetConn) Close(pool string) (string, bool)

func (*NetConn) Do

func (this *NetConn) Do(req *http.Request, v interface{}) (r *http.Response, err error)

func (*NetConn) Gotree

func (this *NetConn) Gotree(host ...string) *NetConn

func (*NetConn) Host

func (this *NetConn) Host() string

func (*NetConn) NewRequest

func (this *NetConn) NewRequest(method, path string, body interface{}) (*http.Request, error)

type ObServer

type ObServer struct {
	// contains filtered or unexported fields
}

func (*ObServer) AddEvent

func (this *ObServer) AddEvent(o interface{}, handle handlerFunc)

func (*ObServer) Event

func (this *ObServer) Event(args ...interface{})

func (*ObServer) Gotree

func (this *ObServer) Gotree() *ObServer

func (*ObServer) RemoveEvent

func (this *ObServer) RemoveEvent(o interface{})

func (*ObServer) SubscribeLen

func (this *ObServer) SubscribeLen() int

type PB

type PB struct {
	// contains filtered or unexported fields
}

A PB

func (*PB) Next

func (this *PB) Next() bool

Next 下一个迭代

type Panel

type Panel struct {
	Extra []interface{}
	// contains filtered or unexported fields
}

func (*Panel) RpcAddr

func (this *Panel) RpcAddr() string

RpcAddr 节点地址

type Request

type Request struct {
	ServiceMethod string // format: "Service.Method"
	Seq           uint64 // sequence number chosen by client
	// contains filtered or unexported fields
}

Request is a header written before every RPC call. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

type Response

type Response struct {
	ServiceMethod string // echoes that of the Request
	Seq           uint64 // echoes that of the request
	Error         string // error, if any.
	// contains filtered or unexported fields
}

Response is a header written before every RPC return. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.

type RunStack

type RunStack struct {
	// contains filtered or unexported fields
}

RunStack

func (*RunStack) Calls

func (this *RunStack) Calls() (result int)

func (*RunStack) Del

func (this *RunStack) Del(key string)

func (*RunStack) Eval

func (this *RunStack) Eval(key string, value interface{}) error

func (*RunStack) Get

func (this *RunStack) Get(key string) interface{}

func (*RunStack) Gotree

func (this *RunStack) Gotree() *RunStack

func (*RunStack) Remove

func (this *RunStack) Remove()

func (*RunStack) Set

func (this *RunStack) Set(key string, value interface{})

type RuntimeStack

type RuntimeStack interface {
	Set(string, interface{})
	Get(string) interface{}
	Remove()
	Calls() int
	Eval(string, interface{}) error
	// contains filtered or unexported methods
}

type Scanner

type Scanner interface {
	Scan(src interface{}) error
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents an RPC Server.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

func (*Server) Close

func (server *Server) Close()

func (*Server) Register

func (server *Server) Register(rcvr interface{}) error

Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:

  • exported method of exported type
  • two arguments, both of exported type
  • the second argument is a pointer
  • one return value, of type error

It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.

func (*Server) RegisterGotreeService

func (server *Server) RegisterGotreeService(gs *GotreeService)

func (*Server) RegisterName

func (server *Server) RegisterName(name string, rcvr interface{}) error

RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.

func (*Server) ServeCodec

func (server *Server) ServeCodec(codec ServerCodec)

ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.

func (*Server) ServeRequest

func (server *Server) ServeRequest(codec ServerCodec) error

ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.

func (*Server) ServiceNameList

func (server *Server) ServiceNameList() []string

func (*Server) UnRegister

func (server *Server) UnRegister(name string)

type ServerCodec

type ServerCodec interface {
	ReadRequestHeader(*Request) error
	ReadRequestBody(interface{}) error
	// WriteResponse must be safe for concurrent use by multiple goroutines.
	WriteResponse(*Response, interface{}) error
	ConnInterface() net.Conn
	Close() error
}

A ServerCodec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadRequestHeader and ReadRequestBody in pairs to read requests from the connection, and it calls WriteResponse to write a response back. The server calls Close when finished with the connection. ReadRequestBody may be called with a nil argument to force the body of the request to be read and discarded.

func NewServerCodec

func NewServerCodec(conn net.Conn) ServerCodec

type SleepObject

type SleepObject struct {
	// contains filtered or unexported fields
}

func (*SleepObject) Gotree

func (this *SleepObject) Gotree() *SleepObject

func (*SleepObject) Reset

func (this *SleepObject) Reset()

func (*SleepObject) Sleep

func (this *SleepObject) Sleep() int64

type StopTick

type StopTick interface {
	Stop()
}

func RunTick

func RunTick(tick int64, child func(), name string, delay int) StopTick

type TickStopRun

type TickStopRun func(stop *bool)

type Trace

type Trace struct {
	ComEntity

	Key   string
	Value string
	Error error
	Buf   []byte
	// contains filtered or unexported fields
}

func (*Trace) BoolValue

func (this *Trace) BoolValue() (bool, error)

BoolValue

func (*Trace) Caller

func (this *Trace) Caller(depth int) string

func (*Trace) CharIn

func (this *Trace) CharIn(b byte, s string) int

func (*Trace) Gotree

func (this *Trace) Gotree() *Trace

func (*Trace) HasKey

func (this *Trace) HasKey() bool

HasKey

func (*Trace) HasValue

func (this *Trace) HasValue() bool

HasValue

func (*Trace) IntValue

func (this *Trace) IntValue() (int, error)

IntValue

func (*Trace) NewRetryListener

func (this *Trace) NewRetryListener(l net.Listener, minSleepMs, maxSleepMs int) net.Listener

func (*Trace) NoKey

func (this *Trace) NoKey() bool

func (*Trace) NoValue

func (this *Trace) NoValue() bool

NoValue

func (*Trace) Parse

func (this *Trace) Parse(str, sep string) *Trace

func (*Trace) ParseTraceWith

func (this *Trace) ParseTraceWith(str, sep string, sepIndexFn func(string, string) int) *Trace

ParseTraceWith

func (*Trace) ReadInput

func (this *Trace) ReadInput(prompt, def string) string

func (*Trace) RetryListen

func (this *Trace) RetryListen(netname, addr string, minSleepMs, maxSleepMs int) (net.Listener, error)

func (*Trace) Rparse

func (this *Trace) Rparse(str, sep string) *Trace

Rparse

func (*Trace) SortedNumberIn

func (this *Trace) SortedNumberIn(n int, nums ...int)

func (*Trace) String

func (this *Trace) String() string

String

func (*Trace) Trim

func (this *Trace) Trim() *Trace

func (*Trace) ValueOrKey

func (this *Trace) ValueOrKey() string

ValueOrKey

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL