rpc

package
v0.0.0-...-c9b56a8 Latest Latest
Warning

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

Go to latest
Published: May 9, 2021 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyDefined = errors.New("AlreadyDefined")
View Source
var ErrEndpointNotFound = errors.New("EndpointNotFound")
View Source
var ErrNotExported = errors.New("NotExported")

Functions

func ReqIDFromRequest

func ReqIDFromRequest(r *http.Request) uuid.UUID

Types

type Context

type Context struct {
	ID       string
	Endpoint string
	Request  *http.Request
	Writer   http.ResponseWriter
}

type Empty

type Empty struct {
}

type ResBody

type ResBody struct {
	ID    string
	Ok    bool
	Error json.RawMessage
	Data  json.RawMessage
}

func NewDataResBody

func NewDataResBody(v interface{}) (body *ResBody, err error)

func NewErrorResBody

func NewErrorResBody(err error) *ResBody

func (*ResBody) WriteResponse

func (rb *ResBody) WriteResponse(code int, w http.ResponseWriter)

type ServiceRegistry

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

ServiceRegistry 服务注册表:对内提供服务注册机制,对外提供 HTTP 接口调用。

调用点 ( Endpoint ):接口的名字,格式如下:"<mod>/<service>.<method>",如 `auth/UserService.Login`。 其中, <mod> 为模块名称,约定名称与 '/pkg/<mod>' 保持一直,如 `auth`。 <service> 为服务名称,通常命名为 `XXXXService` ,如 `UserService`。 <method> 为方法名称,如 `Login`

func NewServiceRegistry

func NewServiceRegistry(prefix string) *ServiceRegistry

func (*ServiceRegistry) RegisterService

func (rg *ServiceRegistry) RegisterService(modName string, ser interface{}) error

RegisterService 注册服务

modName 模块名称

service 服务实例

func (*ServiceRegistry) ServeHTTP

func (rg *ServiceRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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