Skip to content

Commit

Permalink
Merge pull request #11 from hb-chen/master
Browse files Browse the repository at this point in the history
rename gateway
  • Loading branch information
hb-chen authored Dec 12, 2020
2 parents ec02069 + e66c160 commit 1290d98
Show file tree
Hide file tree
Showing 37 changed files with 214 additions and 229 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
- [etcd](./registry/etcd) ETCD配置中心
- [zookeeper](./registry/zookeeper) Zookeeper配置中心
- Service
- [gateway](./service/gateway) 网关
- [stackway](service/stackway) 网关
8 changes: 0 additions & 8 deletions service/gateway/Dockerfile

This file was deleted.

19 changes: 0 additions & 19 deletions service/gateway/Makefile

This file was deleted.

47 changes: 0 additions & 47 deletions service/gateway/api/api.go

This file was deleted.

25 changes: 0 additions & 25 deletions service/gateway/stack_config.yml

This file was deleted.

File renamed without changes.
8 changes: 8 additions & 0 deletions service/stackway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM alpine:3.10

ADD stack_config.yml /bin/stack_config.yml
ADD bin/stackway /bin/stackway

WORKDIR /bin
ENTRYPOINT [ "stackway" ]
CMD [ "--config", "stack_config.yml" ]
24 changes: 24 additions & 0 deletions service/stackway/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

GOPATH:=$(shell go env GOPATH)

.PHONY: proto
proto:
protoc --proto_path=${GOPATH}/src --stack_out=${GOPATH}/src --go_out=:${GOPATH}/src github.com/stack-labs/stack-rpc-plugins/service/stackway/api/proto/api.proto
protoc --proto_path=${GOPATH}/src --stack_out=${GOPATH}/src --go_out=:${GOPATH}/src github.com/stack-labs/stack-rpc-plugins/service/stackway/test/proto/test.proto

.PHONY: test
test:
go test -race -cover -v ./...

.PHONY: run
run:
go run main.go --config stack_config.yml

.PHONY: build
build:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags '-w' -o ./bin/stackway main.go

.PHONY: docker
docker: build
docker build . -t $(tag)

7 changes: 3 additions & 4 deletions service/gateway/README.md → service/stackway/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Gateway
# Stackway

`cmd`目录为网关简单用例,包括`yml`配置以及`plugin`的示范

```shell script
$ cd cmd
$ go run main.go plugin.go --config=stack_config.yml
```

- 如果作为单纯网关,不需要启动`server`,配置中`stack.server.protocol`可以使用`mock`
- `example`插件配置可以自己定义,示范的配置层级为`gateway.example`,对应代码段:
- `cfg.Get("gateway", "example").Scan(&conf)`
- `example`插件配置可以自己定义,示范的配置层级为`stackway.example`,对应代码段:
- `cfg.Get("stackway", "example").Scan(&conf)`
46 changes: 46 additions & 0 deletions service/stackway/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package api

import (
"github.com/stack-labs/stack-rpc"
"github.com/stack-labs/stack-rpc/pkg/cli"
)

// api stackway options
func Options() (options []stack.Option) {
flags := []cli.Flag{
cli.StringFlag{
Name: "stackway_name",
Usage: "Stackway name",
EnvVar: "STACK_STACKWAY_NAME",
},
cli.StringFlag{
Name: "stackway_address",
Usage: "Set the stackway address e.g 0.0.0.0:8080",
EnvVar: "STACK_STACKWAY_ADDRESS",
},
cli.StringFlag{
Name: "stackway_handler",
Usage: "Specify the request handler to be used for mapping HTTP requests to services; {api, event, http, rpc}",
EnvVar: "STACK_STACKWAY_HANDLER",
},
cli.StringFlag{
Name: "stackway_namespace",
Usage: "Set the namespace used by the stackway e.g. stack.rpc.api",
EnvVar: "STACK_STACKWAY_NAMESPACE",
},
cli.StringFlag{
Name: "stackway_resolver",
Usage: "Set the hostname resolver used by the stackway {host, path, grpc}",
EnvVar: "STACK_STACKWAY_RESOLVER",
},
cli.BoolFlag{
Name: "stackway_enable_rpc",
Usage: "Enable call the backend directly via /rpc",
EnvVar: "STACK_STACKWAY_ENABLE_RPC",
},
}

options = append(options, stack.Flags(flags...))

return
}
19 changes: 9 additions & 10 deletions service/gateway/api/http.go → service/stackway/api/http.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Package api is an API Gateway
package api

import (
Expand All @@ -7,7 +6,7 @@ import (

"github.com/gorilla/mux"
"github.com/stack-labs/stack-rpc"
gwServer "github.com/stack-labs/stack-rpc-plugins/service/gateway/server"
gwServer "github.com/stack-labs/stack-rpc-plugins/service/stackway/server"
ahandler "github.com/stack-labs/stack-rpc/api/handler"
aapi "github.com/stack-labs/stack-rpc/api/handler/api"
"github.com/stack-labs/stack-rpc/api/handler/event"
Expand All @@ -28,17 +27,17 @@ import (
stackConfig "github.com/stack-labs/stack-rpc/config"
"github.com/stack-labs/stack-rpc/util/log"

"github.com/stack-labs/stack-rpc-plugins/service/gateway/handler"
"github.com/stack-labs/stack-rpc-plugins/service/gateway/helper"
"github.com/stack-labs/stack-rpc-plugins/service/gateway/plugin"
"github.com/stack-labs/stack-rpc-plugins/service/stackway/handler"
"github.com/stack-labs/stack-rpc-plugins/service/stackway/helper"
"github.com/stack-labs/stack-rpc-plugins/service/stackway/plugin"
)

type config struct {
Server *stackConfig.Server `json:"server"`
Gateway *gateway `json:"gateway"`
Server *stackConfig.Server `json:"server"`
Stackway *stackway `json:"stackway"`
}

type gateway struct {
type stackway struct {
Address string `json:"address"`
Handler string `json:"handler"`
Resolver string `json:"resolver"`
Expand Down Expand Up @@ -66,7 +65,7 @@ func newDefaultConfig() *config {
Server: &stackConfig.Server{
Address: ":8080",
},
Gateway: &gateway{
Stackway: &stackway{
Handler: "meta",
Resolver: "stack",
RPCPath: "/rpc",
Expand Down Expand Up @@ -113,7 +112,7 @@ func (s *httpServer) Start() error {
}
}

gwConf := conf.Gateway
gwConf := conf.Stackway
address := conf.Server.Address
if len(gwConf.Address) > 0 {
address = gwConf.Address
Expand Down
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
4 changes: 2 additions & 2 deletions service/gateway/go.mod → service/stackway/go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/stack-labs/stack-rpc-plugins/service/gateway
module github.com/stack-labs/stack-rpc-plugins/service/stackway

go 1.14

replace (
github.com/coreos/bbolt => go.etcd.io/bbolt v1.3.4
github.com/stack-labs/stack-rpc v1.0.0 => ../../../stack-rpc
github.com/stack-labs/stack-rpc v0.0.0 => ../../../stack-rpc
google.golang.org/grpc => google.golang.org/grpc v1.26.0
)

Expand Down
5 changes: 3 additions & 2 deletions service/gateway/go.sum → service/stackway/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e/go.mod
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
github.com/stack-labs/stack-rpc v1.0.0-rc2 h1:6cD5j9Hp1tqMXF7rnvjoPfiq2ILu6K5L6WIo+luUqB8=
github.com/stack-labs/stack-rpc v1.0.0-rc2/go.mod h1:Wyvz2jT9SbryJ1tfDNV86wXMEGOi+xF2zlXXnBW1f2A=
github.com/stack-labs/stack-rpc v1.0.0 h1:YGg7H+iwaVEKyu82xH/H8/ywOSiDNEJ9Sg9IdeOdtsM=
github.com/stack-labs/stack-rpc v1.0.0/go.mod h1:Am8wYA4vCnpq5qkhNon1xlcmdAUUIxWRJ2DJTQbes7I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
Expand All @@ -446,6 +446,7 @@ github.com/xeipuuv/gojsonschema v0.0.0-20180618132009-1d523034197f/go.mod h1:5yf
github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4myDekKRoLuqhs=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v1.0.0/go.mod h1:IoImgRak9i3zJyuxOKUP1v4UZd1tMoKkq/Cimt1uhCg=
go.etcd.io/bbolt v1.3.4 h1:hi1bXHMVrlQh6WwxAy+qZCV/SYIlqo+Ushwdpa4tAKg=
go.etcd.io/bbolt v1.3.4/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
Expand Down
Loading

0 comments on commit 1290d98

Please sign in to comment.