mirror of
https://github.com/eolinker/apinto
synced 2025-12-24 13:28:15 +08:00
router 驱动
This commit is contained in:
@@ -3,6 +3,7 @@ package service_http
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/eolinker/goku-eosc/router/checker"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -118,11 +119,15 @@ func (s *serviceWorker) ProxyAddr() string {
|
||||
}
|
||||
|
||||
//Handle 将服务发送到负载
|
||||
func (s *serviceWorker) Handle(w http.ResponseWriter, r *http.Request, router service.IRouterRule) error {
|
||||
func (s *serviceWorker) Handle(w http.ResponseWriter, r *http.Request, router service.IRouterEndpoint) error {
|
||||
// 构造context
|
||||
ctx := http_context.NewContext(r, w)
|
||||
// 设置目标URL
|
||||
ctx.ProxyRequest.SetTargetURL(recombinePath(r.URL.Path, router.Location(), s.rewriteURL))
|
||||
location,has:=router.Location()
|
||||
if has && location.CheckType()== checker.CheckTypePrefix{
|
||||
ctx.ProxyRequest.SetTargetURL(recombinePath(r.URL.Path,location.Value() , s.rewriteURL))
|
||||
}
|
||||
|
||||
response, err := s.upstream.Send(ctx, s)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"github.com/eolinker/goku-eosc/router/checker"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
@@ -12,12 +13,16 @@ func CheckSkill(skill string) bool {
|
||||
|
||||
//IService github.com/eolinker/goku-eosc/service.service.IService
|
||||
type IService interface {
|
||||
Handle(w http.ResponseWriter, r *http.Request, router IRouterRule) error
|
||||
Handle(w http.ResponseWriter, r *http.Request, router IRouterEndpoint) error
|
||||
}
|
||||
|
||||
//IRouterRule 实现了返回路由规则信息方法的接口,如返回location、Host、Header、Query
|
||||
type IRouterRule interface {
|
||||
Location() string
|
||||
//IRouterEndpoint 实现了返回路由规则信息方法的接口,如返回location、Host、Header、Query
|
||||
type IRouterEndpoint interface {
|
||||
Location()( checker.Checker,bool)
|
||||
Header(name string)( checker.Checker,bool)
|
||||
Query(name string)(checker.Checker,bool)
|
||||
Headers()[]string
|
||||
Queries()[]string
|
||||
}
|
||||
|
||||
//IServiceDetail 实现了返回服务信息方法的接口,如返回服务名,服务描述,重试次数间等..
|
||||
|
||||
Reference in New Issue
Block a user