Skip to content

Commit

Permalink
Merge pull request #80 from printfcoder/master
Browse files Browse the repository at this point in the history
fix some bugs
  • Loading branch information
printfcoder authored Jan 27, 2021
2 parents 741a637 + 7a719c4 commit da96552
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
17 changes: 17 additions & 0 deletions service/stack/stack_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ func (s *stackService) initComponents() error {
s.opts.SelectorOptions = append(s.opts.SelectorOptions, sel.Registry(s.opts.Registry))
s.opts.BrokerOptions = append(s.opts.BrokerOptions, br.Registry(s.opts.Registry))

// set wrappers
for _, wrapper := range s.opts.HandlerWrapper {
s.opts.ServerOptions = append(s.opts.ServerOptions, ser.WrapHandler(wrapper))
}
for _, wrapper := range s.opts.CallWrapper {
s.opts.ClientOptions = append(s.opts.ClientOptions, cl.WrapCall(wrapper))
}
for _, wrapper := range s.opts.ClientWrapper {
s.opts.ClientOptions = append(s.opts.ClientOptions, cl.Wrap(wrapper))
}
for _, wrapper := range s.opts.SubscriberWrapper {
s.opts.ServerOptions = append(s.opts.ServerOptions, ser.WrapSubscriber(wrapper))
}

if err := s.opts.Auth.Init(s.opts.AuthOptions...); err != nil {
return fmt.Errorf("Error configuring auth: %v ", err)
}
Expand Down Expand Up @@ -171,6 +185,9 @@ func (s *stackService) initComponents() error {
// wrap client to inject From-Service header on any calls
// todo wrap not here
s.opts.Client = wrapper.FromService(s.Name(), s.opts.Client)
for i := len(s.opts.ClientWrapper); i > 0; i-- {
s.opts.Client = s.opts.ClientWrapper[i-1](s.opts.Client)
}
if err := s.opts.Client.Init(s.opts.ClientOptions...); err != nil {
return fmt.Errorf("Error configuring client: %v ", err)
}
Expand Down
2 changes: 2 additions & 0 deletions service/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/stack-labs/stack-rpc/service"
"github.com/stack-labs/stack-rpc/util/log"
)

func NewOptions(opts ...service.Option) []service.Option {
Expand Down Expand Up @@ -41,6 +42,7 @@ func setHandle(sOpts *service.Options) error {
if sOpts.Context.Value(handlerFuncsKey{}) != nil {
if handlers, ok := sOpts.Context.Value(handlerFuncsKey{}).([]HandlerFunc); ok {
for _, handler := range handlers {
log.Debugf("handler url, root: [%s], route: [%s]", rootPath, handler.Route)
muxTmp.HandleFunc(path.Join(rootPath, handler.Route), handler.Func)
}
}
Expand Down
8 changes: 4 additions & 4 deletions util/stackctl/new/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ func run(ctx *cli.Context) {
{"main.go", tmpl.MainFNC},
{"generate.go", tmpl.GenerateFile},
{"plugin.go", tmpl.Plugin},
{"stack_config.yml", tmpl.StackConfig},
{"stack.yml", tmpl.StackConfig},
{"handler/" + alias + ".go", tmpl.HandlerFNC},
{"subscriber/" + alias + ".go", tmpl.SubscriberFNC},
{"proto/" + alias + "/" + alias + ".proto", tmpl.ProtoFNC},
Expand Down Expand Up @@ -278,7 +278,7 @@ func run(ctx *cli.Context) {
{"main.go", tmpl.MainSRV},
{"generate.go", tmpl.GenerateFile},
{"plugin.go", tmpl.Plugin},
{"stack_config.yml", tmpl.StackConfig},
{"stack.yml", tmpl.StackConfig},
{"handler/" + alias + ".go", tmpl.HandlerSRV},
{"subscriber/" + alias + ".go", tmpl.SubscriberSRV},
{"proto/" + alias + "/" + alias + ".proto", tmpl.ProtoSRV},
Expand Down Expand Up @@ -315,7 +315,7 @@ func run(ctx *cli.Context) {
{"main.go", tmpl.MainAPI},
{"generate.go", tmpl.GenerateFile},
{"plugin.go", tmpl.Plugin},
{"stack_config.yml", tmpl.StackConfig},
{"stack.yml", tmpl.StackConfig},
{"client/" + alias + ".go", tmpl.WrapperAPI},
{"handler/" + alias + ".go", tmpl.HandlerAPI},
{"proto/" + alias + "/" + alias + ".proto", tmpl.ProtoAPI},
Expand Down Expand Up @@ -355,7 +355,7 @@ func run(ctx *cli.Context) {
Files: []file{
{"main.go", tmpl.MainWEB},
{"plugin.go", tmpl.Plugin},
{"stack_config.yml", tmpl.StackConfig},
{"stack.yml", tmpl.StackConfig},
{"handler/handler.go", tmpl.HandlerWEB},
{"html/index.html", tmpl.HTMLWEB},
{"Dockerfile", tmpl.DockerWEB},
Expand Down

0 comments on commit da96552

Please sign in to comment.