12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package micro
- import (
- "context"
- )
- type (
- applicationKey struct {
- }
- HandleOptions struct {
- DisableRpc bool //禁用RPC功能
- DisableHttp bool //禁用HTTP功能
- HttpPath string //重定向HTTP路由
- HttpMethod string //HTTP路径
- }
- HandleOption func(o *HandleOptions)
- HandleFunc func(ctx Context) (err error)
- Application interface {
- Handle(method string, cb HandleFunc, opts ...HandleOption) //注册一个处理器
- CreateRequest(name, method string, body interface{}) (req *Request, err error) //创建一个rpc请求
- }
- Server interface {
- Start(ctx context.Context) (err error)
- Stop() (err error)
- }
- )
- var (
- contextKey = applicationKey{}
- )
- func FromContext(ctx context.Context) Application {
- if v := ctx.Value(contextKey); v != nil {
- return v.(Application)
- }
- return nil
- }
- func WithContext(ctx context.Context, app Application) context.Context {
- return context.WithValue(ctx, contextKey, app)
- }
|