xshare

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

View Source
const (
	//ServicesMetadataVersion      = "ver"
	ServicesMetadataAverage = "Average"

	ServicesMetadataRpcServerId      = "_rpc_srv_id"   //服务器编号
	ServicesMetadataRpcServerAddress = "_rpc_srv_addr" //rpc服务器ID,selector 中固定转发地址

)
View Source
const (
	SelectorTypeLocal     = "local"     //本地程序内访问
	SelectorTypeProcess   = "process"   //进程内访问
	SelectorTypeDiscovery = "discovery" //服务发现
)
View Source
const (
	ServicesServerIdAll = "-"
)

Variables

View Source
var Options = &Rpcx{
	Timeout: 2,
	Network: "tcp",
	Address: ":8100",
}

Options Etcd Redis 二选一

View Source
var Service = map[string]string{}

Functions

func Address

func Address() *utils.Address

func AddressFormat

func AddressFormat(address string) string

func AddressPrefix

func AddressPrefix() string

func Discovery

func Discovery() (client.ServiceDiscovery, error)

func Equal

func Equal(src, tar any) bool

func EqualSliceString

func EqualSliceString(v1, v2 []string) bool

EqualSliceString 包含相同的字符串(可以顺序不同)

func LocalIpv4

func LocalIpv4() (ip string, err error)

func Register

func Register(urlRpcxAddr *utils.Address) (*redis.RedisRegisterPlugin, error)

func Timeout

func Timeout() time.Duration

func TypeOf

func TypeOf(src any) reflect.Type

Types

type Context

type Context struct {
	Binder binder.Interface
	// contains filtered or unexported fields
}

func NewContext

func NewContext(ctx ctx, b binder.Interface) *Context

func (*Context) Bind

func (this *Context) Bind(i interface{}) error

func (*Context) Bytes

func (this *Context) Bytes() []byte

func (*Context) Error

func (this *Context) Error(err any) *values.Message

func (*Context) Errorf

func (this *Context) Errorf(code int, format any, args ...interface{}) *values.Message

func (*Context) Get

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

func (*Context) GetInt

func (this *Context) GetInt(key string) (val int)

func (*Context) GetInt32

func (this *Context) GetInt32(key string) (val int32)

func (*Context) GetInt64

func (this *Context) GetInt64(key string) (val int64)

func (*Context) GetMetadata

func (this *Context) GetMetadata(key string) (val string)

GetMetadata GET REQ Metadata

func (*Context) GetString

func (this *Context) GetString(key string) (val string)

func (*Context) GetValue

func (this *Context) GetValue(key any) any

func (*Context) Metadata

func (this *Context) Metadata() map[string]string

func (*Context) Reader

func (this *Context) Reader() io.Reader

Reader 返回一个io.Reader来读取包体

func (*Context) ServiceMethod

func (this *Context) ServiceMethod() string

func (*Context) ServicePath

func (this *Context) ServicePath() string

func (*Context) SetMetadata

func (this *Context) SetMetadata(key, val string)

SetMetadata SET RES Metadata

func (*Context) SetValue

func (this *Context) SetValue(key, val any)

func (*Context) Write

func (this *Context) Write(data []byte) error

type Handler

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

func (*Handler) Caller

func (this *Handler) Caller(node *registry.Node, c *Context) (reply interface{}, err error)

func (*Handler) Filter

func (this *Handler) Filter(node *registry.Node) bool

func (*Handler) Marshal

func (this *Handler) Marshal(c *Context, reply interface{}) (data []byte, err error)

func (*Handler) Metadata

func (this *Handler) Metadata() string

func (*Handler) Use

func (this *Handler) Use(src interface{})

type HandlerCaller

type HandlerCaller func(node *registry.Node, c *Context) (interface{}, error)

type HandlerFilter

type HandlerFilter func(node *registry.Node) bool

type HandlerMetadata

type HandlerMetadata func() string

type HandlerSerialize

type HandlerSerialize func(c *Context, reply interface{}) ([]byte, error)

type Metadata

type Metadata map[string]string

func NewMetadata

func NewMetadata(args ...string) Metadata

NewMetadata 创建新Metadata,参数k1,v1,k2,v2...

func (Metadata) Json

func (this Metadata) Json() map[string]string

func (Metadata) SetAddress

func (this Metadata) SetAddress(v string)

func (Metadata) SetContentType

func (this Metadata) SetContentType(v string)

func (Metadata) SetServerId

func (this Metadata) SetServerId(v int32)

type Rpcx

type Rpcx struct {
	Redis    string //服务发现
	Timeout  int32
	Network  string
	Address  string //仅仅启动服务器时需要
	BasePath string
}

type Selector

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

func NewSelector

func NewSelector(servicePath string) *Selector

func (*Selector) Select

func (this *Selector) Select(ctx context.Context, servicePath, serviceMethod string, args interface{}) string

Select 默认按负载

func (*Selector) UpdateServer

func (this *Selector) UpdateServer(servers map[string]string)

Jump to

Keyboard shortcuts

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