Skip to content

Commit 94370ab

Browse files
authored
feat(zipper): router can be customized in NewZipper() (#667)
1 parent 92788ae commit 94370ab

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

cli/serve.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/spf13/cobra"
2424
"github.com/yomorun/yomo"
25+
"github.com/yomorun/yomo/core/router"
2526
pkgconfig "github.com/yomorun/yomo/pkg/config"
2627
"github.com/yomorun/yomo/pkg/log"
2728
"github.com/yomorun/yomo/pkg/trace"
@@ -62,7 +63,7 @@ var serveCmd = &cobra.Command{
6263
}
6364
}
6465

65-
zipper, err := yomo.NewZipper(conf.Name, conf.Downstreams, options...)
66+
zipper, err := yomo.NewZipper(conf.Name, router.Default(), conf.Downstreams, options...)
6667
if err != nil {
6768
log.FailureStatusEvent(os.Stdout, err.Error())
6869
return

zipper.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func RunZipper(ctx context.Context, configPath string) error {
4343
}
4444
}
4545

46-
zipper, err := NewZipper(conf.Name, conf.Downstreams, options...)
46+
zipper, err := NewZipper(conf.Name, router.Default(), conf.Downstreams, options...)
4747
if err != nil {
4848
return err
4949
}
@@ -53,7 +53,7 @@ func RunZipper(ctx context.Context, configPath string) error {
5353
}
5454

5555
// NewZipper returns a zipper.
56-
func NewZipper(name string, meshConfig map[string]config.Downstream, options ...ZipperOption) (Zipper, error) {
56+
func NewZipper(name string, router router.Router, meshConfig map[string]config.Downstream, options ...ZipperOption) (Zipper, error) {
5757
opts := &zipperOptions{}
5858

5959
for _, o := range options {
@@ -84,7 +84,7 @@ func NewZipper(name string, meshConfig map[string]config.Downstream, options ...
8484
server.AddDownstreamServer(downstream)
8585
}
8686

87-
server.ConfigRouter(router.Default())
87+
server.ConfigRouter(router)
8888

8989
// watch signal.
9090
go waitSignalForShutdownServer(server)

zipper_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import (
66

77
"github.com/stretchr/testify/assert"
88
"github.com/yomorun/yomo/core"
9+
"github.com/yomorun/yomo/core/router"
910
"github.com/yomorun/yomo/core/ylog"
1011
)
1112

1213
func TestZipperRun(t *testing.T) {
1314
zipper, err := NewZipper(
1415
"zipper",
16+
router.Default(),
1517
nil,
1618
// WithAuth("token", "<CREDENTIAL>"),
1719
WithUpstreamOption(core.ClientOption(WithCredential("token:<CREDENTIAL>"))),

0 commit comments

Comments
 (0)