Skip to content

Commit

Permalink
Configをconfigパッケージのグローバル変数へ
Browse files Browse the repository at this point in the history
  • Loading branch information
Crow314 committed Nov 4, 2020
1 parent 04c43e2 commit 7ca44ac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions cmd/lottery_app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ func main() {
colog.Register()

// Load Config file
cfg := config.LoadConfig()
config.LoadConfig()

// Model Initialization
model.Init(cfg)
model.Init()

new(server.Server).Up(cfg)
new(server.Server).Up()
}
9 changes: 4 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ type Config struct {
} `yaml:"resource_path"`
}

func LoadConfig() Config {
var ConfigData Config

func LoadConfig() {
f, err := os.Open("conf/config.yaml")
util.CheckFatalError(err)
defer f.Close()

var cfg Config
err = yaml.NewDecoder(f).Decode(&cfg)
err = yaml.NewDecoder(f).Decode(&ConfigData)
util.CheckFatalError(err)

return cfg
}
6 changes: 3 additions & 3 deletions pkg/model/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"lottery_back/pkg/config"
)

func Init(config config.Config) {
loadApplicants(config)
loadPrizes(config)
func Init() {
loadApplicants(config.ConfigData)
loadPrizes(config.ConfigData)
initResults()
}
4 changes: 2 additions & 2 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type Server struct {
}

// Up start server
func (server *Server) Up(cfg config.Config) {
func (server *Server) Up() {
server.Engine = gin.Default()
server.WsApp = GenerateWsApp()

// CORS setup
corsConfig := cors.DefaultConfig()
corsConfig.AllowOrigins = cfg.Server.Host
corsConfig.AllowOrigins = config.ConfigData.Server.Host
server.Engine.Use(cors.New(corsConfig))

server.setRoutes()
Expand Down

0 comments on commit 7ca44ac

Please sign in to comment.