Documentation ¶
Overview ¶
Package httpgateway provides an http-rpc handler which provides the entire http request over rpc
Package httpgateway 网关配置
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultRoute = func(app module.App, r *http.Request) (*Service, error) { if r.URL.Path == "" { return nil, errors.New("path is nil") } handers := strings.Split(r.URL.Path, "/") if len(handers) < 2 { return nil, errors.New("path is not /[server]/path") } server := handers[1] if server == "" { return nil, errors.New("server is nil") } session, err := app.GetRouteServer(server, selector.WithStrategy(func(services []*registry.Service) selector.Next { var nodes []*registry.Node for _, service := range services { for _, node := range service.Nodes { nodes = append(nodes, node) } } var mtx sync.Mutex return func() (*registry.Node, error) { mtx.Lock() defer mtx.Unlock() if len(nodes) == 0 { return nil, fmt.Errorf("no node") } index := rand.Intn(int(len(nodes))) return nodes[index], nil } }), ) if err != nil { return nil, errors.New(err.Error()) } return &Service{SrvSession: session, Hander: r.URL.Path}, err }
DefaultRoute 默认路由规则
Functions ¶
Types ¶
type APIHandler ¶ added in v1.3.6
APIHandler 网关handler
func (*APIHandler) ServeHTTP ¶ added in v1.3.6
func (a *APIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
API handler is the default handler which takes api.Request and returns api.Response
type Service ¶
type Service struct { // hander Hander string // node SrvSession module.ServerSession }
Service represents an API service
Click to show internal directories.
Click to hide internal directories.