core

package
Version: v1.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCheckFirst = errors.New("need login/register first")
)
View Source
var (
	ErrPeerNotFound = errors.New("core: peer not found")
)
View Source
var ReqCheck = &RequestCheck{}

Functions

func InitRequestCheck

func InitRequestCheck(loginCnf *config.MethodPathConfig, whiteList []*config.MethodPathConfig)

Types

type Dispatcher

type Dispatcher interface {
	Dispatch(sess Session, req Request)
}

type Hub

type Hub interface {
	Start() error
	Stop() error
	Subscribe(ssid string, sub Subscriber) (*Subscription, error)
	UnSubscribe(subscription *Subscription)
	Publish(kv *KV)
}

type HubDispatcher

type HubDispatcher interface {
	Hub
	Dispatcher
}

type KV

type KV struct {
	Key []byte
	Val []byte
}

type LocalPeer

type LocalPeer interface {
	Name() string
	SetRouter(Router)
	Notify(PeerRouter, ...MethodPath)
	Request(PeerRouter, proto.Message) (proto.Message, error)
}

type MethodPath

type MethodPath interface {
	String() string
}

func NewMethodPath

func NewMethodPath(version, resource, action string) MethodPath

type PeerRouter

type PeerRouter interface {
	PeerName() string
	SetPeerName(name string)
	AppName() string
	Equals(pr PeerRouter) bool
	String() string
}

func NewPeerRouter

func NewPeerRouter(peerName, appName string) PeerRouter

type PeerRouters

type PeerRouters []PeerRouter

func (*PeerRouters) Append

func (s *PeerRouters) Append(pr PeerRouter)

func (PeerRouters) FindOne

func (s PeerRouters) FindOne(peerName string) (PeerRouter, error)

func (PeerRouters) Len

func (s PeerRouters) Len() int

func (PeerRouters) Less

func (s PeerRouters) Less(i, j int) bool

func (*PeerRouters) RemoveByPeer

func (s *PeerRouters) RemoveByPeer(peerName string)

func (*PeerRouters) RemoveByPeerRouter

func (s *PeerRouters) RemoveByPeerRouter(pr PeerRouter)

func (*PeerRouters) Sort

func (s *PeerRouters) Sort()

func (PeerRouters) Swap

func (s PeerRouters) Swap(i, j int)

type Request

type Request []byte

func Marshal

func Marshal(model proto.Message) (req Request, err error)

func (Request) Unmarshal

func (req Request) Unmarshal(model proto.Message) error

type RequestCheck

type RequestCheck struct {
	LoginMP   MethodPath
	WhiteList []MethodPath
	// contains filtered or unexported fields
}

账户体系,不用接口,这里用接口会带来很多对象开销

func (*RequestCheck) CheckFirst

func (rc *RequestCheck) CheckFirst(mp MethodPath) error

func (*RequestCheck) CheckLogin

func (rc *RequestCheck) CheckLogin(mp MethodPath) bool

func (*RequestCheck) NeedCheck

func (rc *RequestCheck) NeedCheck() bool

type Router

type Router interface {
	//获取路由分流指向
	RouteIn(mp MethodPath, id string, request proto.Message) (response proto.Message, err error)
	//根据peerRouter将request定向到指定Grpc服务并返回结果
	RouteOut(pr PeerRouter, request proto.Message) (response proto.Message, err error)
	//注册单个
	//appName 资源服务名称
	//peer 节点名称(空字符串为本地)
	//address  资源服务连接地址(ps:www.example.com:8080)
	Register(mps []MethodPath, pr PeerRouter, address string) error
	//注销app下所有
	UnRegisterApp(pr PeerRouter)
	//注销peer下所有
	UnRegisterPeer(peerName string)
}

type Session

type Session interface {
	io.WriteCloser
	GetID() string
	GetUserId() string
	Send(message proto.Message) error
	LoggedIn() bool
	SetUserId(userId string)
}

type Subscriber

type Subscriber = Session

type Subscription

type Subscription struct {
	Ssid string
	Sub  Subscriber
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL