123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package micro
- import (
- "context"
- )
- type (
- Context interface {
- Bind(i interface{}) (err error)
- Error(code int, msg string) (err error)
- Success(i interface{}) (err error)
- }
- HandleOptions struct {
- HttpMethod string
- DisableRpc bool
- DisableHttp bool
- }
- HandleOption func(o *HandleOptions)
- HandleFunc func(ctx Context) (err error)
- Application interface {
- Handle(method string, cb HandleFunc) (err error) //注册一个处理器
- NewRequest(service, method string, payload interface{}) (err error) //创建一个rpc请求
- }
- Server interface {
- Start(ctx context.Context) (err error)
- Stop() (err error)
- }
- Request struct {
- ServiceName string
- Method string
- Body interface{}
- client *Client
- }
- Response interface {
- StatusCode() int
- Error() error
- Decode(i interface{}) error
- }
- )
- func (r *Request) Do(ctx context.Context) (Response, error) {
- return r.client.Do(ctx, r)
- }
- func WithHttpMethod(method string) HandleOption {
- return func(o *HandleOptions) {
- o.HttpMethod = method
- }
- }
|