micro.go 933 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package micro
  2. import (
  3. "context"
  4. "git.nspix.com/golang/micro/gateway"
  5. )
  6. type (
  7. HandleOptions struct {
  8. HttpMethod string
  9. }
  10. HandleOption func(o *HandleOptions)
  11. HandleFunc func(ctx gateway.Context) (err error)
  12. Application interface {
  13. RegisterHandle(method string, cb HandleFunc) (err error) //注册一个处理器
  14. NewRequest(service, method string, payload interface{}) (err error) //创建一个rpc请求
  15. }
  16. Server interface {
  17. Start(ctx context.Context) (err error)
  18. Stop() (err error)
  19. }
  20. Request struct {
  21. ServiceName string
  22. Method string
  23. Body interface{}
  24. client *Client
  25. }
  26. Response interface {
  27. StatusCode() int
  28. Error() error
  29. Decode(i interface{}) error
  30. }
  31. )
  32. func (r *Request) Do(ctx context.Context) (Response, error) {
  33. return r.client.Do(ctx, r)
  34. }
  35. func WithHttpMethod(method string) HandleOption {
  36. return func(o *HandleOptions) {
  37. o.HttpMethod = method
  38. }
  39. }