Skip to content

Commit

Permalink
remove option
Browse files Browse the repository at this point in the history
  • Loading branch information
vlorc committed Jun 22, 2018
1 parent 739a730 commit ec9c739
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 177 deletions.
3 changes: 2 additions & 1 deletion examples/gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"errors"
"flag"
"github.com/hprose/hprose-golang/rpc"
"github.com/vlorc/hprose-gateway-core/option"
"github.com/vlorc/hprose-gateway-core/source"
_ "github.com/vlorc/hprose-gateway-plugins/session"
_ "github.com/vlorc/hprose-gateway-protocol/forward"
_ "github.com/vlorc/hprose-gateway-protocol/hprose"
_ "github.com/vlorc/hprose-gateway-protocol/restful"
"github.com/vlorc/hprose-gateway/gateway"
"github.com/vlorc/hprose-gateway/named"
"github.com/vlorc/hprose-gateway/option"

"net/http"
)

Expand Down
2 changes: 1 addition & 1 deletion examples/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"flag"
"github.com/hprose/hprose-golang/rpc"
"github.com/vlorc/hprose-gateway-core/etcd"
"github.com/vlorc/hprose-gateway-core/types"
"github.com/vlorc/hprose-gateway-types"
"log"
"net"
)
Expand Down
16 changes: 10 additions & 6 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@ package gateway
import (
"github.com/hprose/hprose-golang/rpc"
"github.com/vlorc/hprose-gateway-core/invoker"
"github.com/vlorc/hprose-gateway/option"
"github.com/vlorc/hprose-gateway-core/option"
"reflect"
"sort"
)

type HproseGateway struct {
opt *option.GatewayOption
}

func NewGateway(o ...func(*option.GatewayOption)) *HproseGateway {
opt := &option.GatewayOption{}
opt := option.NewDefault()
opt.Plugins = invoker.NewInvoker(NewInvoker(opt))
for _, v := range o {
v(opt)
}
go opt.Resolver.Watch("*", opt.Water)
opt = option.NewOptionWith(opt, o...)
sort.Sort(opt.Plugins)
go opt.Resolver.Watch(opt.Prefix, opt.Water)
return NewGatewayWith(opt)
}

func NewGatewayWith(opt *option.GatewayOption) *HproseGateway {
return &HproseGateway{opt: opt}
}

Expand Down
20 changes: 12 additions & 8 deletions gateway/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package gateway

import (
"context"
"github.com/vlorc/hprose-gateway-core/types"
"github.com/vlorc/hprose-gateway/option"
"github.com/vlorc/hprose-gateway-core/option"
"github.com/vlorc/hprose-gateway-types"
"go.uber.org/zap"
"reflect"
)
Expand All @@ -14,20 +14,24 @@ func NewInvoker(opt *option.GatewayOption) types.Plugin {
return (*Invoker)(opt)
}

func (g *Invoker) Close() error {
func (i *Invoker) Level() int {
return 0
}

func (i *Invoker) Close() error {
return nil
}

func (g *Invoker) Name() string {
func (i *Invoker) Name() string {
return "Invoker"
}

func (g *Invoker) Handler(_ types.InvokeHandler, ctx context.Context, method string, args []reflect.Value) ([]reflect.Value, error) {
func (i *Invoker) Handler(_ types.InvokeHandler, ctx context.Context, method string, args []reflect.Value) ([]reflect.Value, error) {
app_id, _ := ctx.Value("appid").(string)
client_id := g.Router.Resolver(method, app_id).Next(g.Context, method, args)
result, err := g.Manager.Resolver(client_id).Endpoint().Invoke(g.Context, method, args)
client_id := i.Router.Resolver(method, app_id).Next(i.Context, method, args)
result, err := i.Manager.Resolver(client_id).Endpoint().Invoke(i.Context, method, args)

g.Log().Debug("Proxy",
i.Log().Debug("Proxy",
zap.String("path", method),
zap.String("app_id", app_id),
zap.String("client_id", client_id),
Expand Down
2 changes: 1 addition & 1 deletion gateway/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package gateway
import (
"bytes"
"fmt"
"github.com/vlorc/hprose-gateway-core/types"
"github.com/vlorc/hprose-gateway-types"
"io"
"reflect"
"strconv"
Expand Down
2 changes: 1 addition & 1 deletion named/mode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package named

import (
"github.com/vlorc/hprose-gateway-core/types"
"github.com/vlorc/hprose-gateway-types"
"strings"
)

Expand Down
159 changes: 0 additions & 159 deletions option/option.go

This file was deleted.

0 comments on commit ec9c739

Please sign in to comment.