Skip to content

Commit

Permalink
gateway: update hosts api
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Mar 15, 2018
1 parent 6541fd1 commit 14aae10
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 372 deletions.
24 changes: 14 additions & 10 deletions gateway/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ import (

// Config app config
type Config struct {
EnableHttp bool `yaml:"enable_http"`
EnableSocket bool `yaml:"enable_socket"`
OuterHttpServer short.OuterHttpSrvConfig `yaml:"outer_http_server"`
OuterSocketServer ant.SrvConfig `yaml:"outer_socket_server"`
InnerSocketServer ant.SrvConfig `yaml:"inner_socket_server"`
InnerSocketClient ant.CliConfig `yaml:"inner_socket_client"`
Etcd etcd.EasyConfig `yaml:"etcd"`
Redis redis.Config `yaml:"redis"`
EnableHttp bool `yaml:"enable_http"`
EnableSocket bool `yaml:"enable_socket"`
OuterHttpServer short.HttpSrvConfig `yaml:"outer_http_server"`
OuterSocketServer ant.SrvConfig `yaml:"outer_socket_server"`
InnerSocketServer ant.SrvConfig `yaml:"inner_socket_server"`
InnerSocketClient ant.CliConfig `yaml:"inner_socket_client"`
Etcd etcd.EasyConfig `yaml:"etcd"`
Redis redis.Config `yaml:"redis"`
}

// NewConfig creates a default config.
func NewConfig() *Config {
return &Config{
EnableHttp: true,
EnableSocket: true,
OuterHttpServer: short.OuterHttpSrvConfig{
OuterHttpServer: short.HttpSrvConfig{
ListenAddress: "0.0.0.0:5000",
AllowCross: false,
},
Expand Down Expand Up @@ -68,7 +68,11 @@ func NewConfig() *Config {

// Reload Bi-directionally synchronizes config between YAML file and memory.
func (c *Config) Reload(bind cfgo.BindFunc) error {
return bind()
err := bind()
if err == nil {
c.OuterHttpServer.OuterIpPort()
}
return err
}

// check the config
Expand Down
20 changes: 19 additions & 1 deletion gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ import (
"github.com/henrylee2cn/teleport/socket"
"github.com/xiaoenai/ants/gateway/logic"
"github.com/xiaoenai/ants/gateway/logic/client"
"github.com/xiaoenai/ants/gateway/logic/hosts"
short "github.com/xiaoenai/ants/gateway/logic/http"
long "github.com/xiaoenai/ants/gateway/logic/socket"
"github.com/xiaoenai/ants/gateway/sdk"
"github.com/xiaoenai/ants/gateway/types"
)

Expand All @@ -48,6 +50,9 @@ func Run(cfg Config, biz *types.Business, protoFunc socket.ProtoFunc) error {
}
logic.SetBusiness(biz)

// sdk
sdk.SetApiVersion(logic.ApiVersion())

// protocol
if protoFunc == nil {
protoFunc = socket.NewFastProtoFunc
Expand All @@ -59,21 +64,34 @@ func Run(cfg Config, biz *types.Business, protoFunc socket.ProtoFunc) error {
protoFunc,
etcdClient,
)

var (
httpAddr string
outerSocketAddr string
innerSocketAddr string
)
// HTTP server
if cfg.EnableHttp {
httpAddr = cfg.OuterHttpServer.OuterIpPort()
go short.Serve(cfg.OuterHttpServer)
}

// TCP socket server
if cfg.EnableSocket {
outerSocketAddr = cfg.OuterSocketServer.OuterIpPort()
innerSocketAddr = cfg.InnerSocketServer.InnerIpPort()
go long.Serve(
cfg.OuterSocketServer,
cfg.InnerSocketServer,
protoFunc,
)
}

hosts.Start(
httpAddr,
outerSocketAddr,
innerSocketAddr,
)

select {}
}

Expand Down

0 comments on commit 14aae10

Please sign in to comment.