-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
54 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"gateway/internal/app" | ||
"gateway/internal/config" | ||
"github.com/huerni/gmitex/core/discovery" | ||
"github.com/huerni/gmitex/core/gateway" | ||
) | ||
|
||
func main() { | ||
discovery.EnableDiscovery() | ||
server := core.NewAPIGatewayServer() | ||
server.Start() | ||
discovery.EnableDiscovery(config.GetRegisterCenter()) | ||
server := core.NewAPIGatewayServer(config.GetServerConfig()) | ||
server.Start(config.GetGatewayRouter()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
server: | ||
port: 8790 | ||
contextPath: / | ||
timeout: 10 | ||
host: | ||
registerCenter: | ||
refreshFrequency: 30 | ||
# eureka: | ||
# serviceUrls: [ http://localhost:8761 ] | ||
etcd: | ||
prefix: test | ||
endpoints: ["127.0.0.1:2379"] | ||
|
||
gateway: | ||
routers: | ||
gmitest: | ||
path: /api/v1/gmitest/** | ||
serviceId: gmitest | ||
stripPrefix: false | ||
timeout: 30 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,44 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/huerni/gmitex/pkg/config" | ||
"github.com/zeromicro/go-zero/core/conf" | ||
"github.com/huerni/gmitex/core/gateway/config" | ||
"gopkg.in/yaml.v2" | ||
"io/ioutil" | ||
|
||
"github.com/huerni/gmitex/core/logger" | ||
) | ||
|
||
type Config struct { | ||
Prefix string `json:"prefix"` | ||
var appConfig = &AppConfig{} | ||
|
||
Etcd config.EtcdConf `json:"etcd,option"` | ||
Mysql config.MysqlConf `json:"mysql,option"` | ||
} | ||
type AppConfig struct { | ||
// eureka 配置信息 | ||
RegisterCenter *config.RegisterCenter `yaml:"registerCenter"` | ||
var ( | ||
Cfg *Config | ||
) | ||
// 路由配置信息 | ||
GatewayRouter *config.Routers `yaml:"gateway"` | ||
func InitConfig(filePath string) (*Config, error) { | ||
if Cfg == nil { | ||
Cfg = &Config{} | ||
conf.MustLoad(filePath, Cfg) | ||
err := FigureConf(Cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
// web 服务配置信息 | ||
Server *config.ServerConfig `yaml:"server"` | ||
} | ||
|
||
return Cfg, nil | ||
func GetServerConfig() *config.ServerConfig { | ||
return appConfig.Server | ||
} | ||
|
||
func GetConfig() *Config { | ||
return Cfg | ||
func GetGatewayRouter() *config.Routers { | ||
return appConfig.GatewayRouter | ||
} | ||
|
||
func FigureConf(c *Config) error { | ||
err := c.Etcd.FigureConfig() | ||
if err != nil { | ||
return err | ||
} | ||
func GetRegisterCenter() *config.RegisterCenter { | ||
return appConfig.RegisterCenter | ||
} | ||
|
||
err = c.Mysql.FigureConfig() | ||
func init() { | ||
logger.Info("加载路由配置信息") | ||
data, err := ioutil.ReadFile("etc/properties.yml") | ||
if err != nil { | ||
return err | ||
logger.Error("从 conf/properties.yml 配置文件中加载配置信息失败") | ||
} | ||
|
||
return nil | ||
yaml.Unmarshal(data, appConfig) | ||
logger.Info("路由配置信息解析完成") | ||
} |