Skip to content

Commit

Permalink
Move flag define to main package
Browse files Browse the repository at this point in the history
  • Loading branch information
xwjdsh committed Dec 1, 2017
1 parent ab2edde commit cb49cb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import (
"github.com/go-ignite/ignite/utils"
)

var confPath = flag.String("c", "./conf/config.toml", "config file")

func main() {
flag.Parse()
utils.InitConf()
utils.InitConf(*confPath)
initRouter()
}

Expand Down
11 changes: 3 additions & 8 deletions utils/conf.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package utils

import (
"flag"
"fmt"
"os"
"strconv"

toml "github.com/pelletier/go-toml"
)

var (
conf = flag.String("c", "./conf/config.toml", "config file")
)

var (
// for app config
APP_Address string
Expand All @@ -28,10 +23,10 @@ var (
HOST_From, HOST_To int
)

func InitConf() {
func InitConf(confPath string) {
//Check config file
if _, err := os.Stat(*conf); !os.IsNotExist(err) {
if config, err := toml.LoadFile(*conf); err == nil {
if _, err := os.Stat(confPath); !os.IsNotExist(err) {
if config, err := toml.LoadFile(confPath); err == nil {
APP_Address = config.Get("app.address").(string)

SS_Image = config.Get("ss.image").(string)
Expand Down

0 comments on commit cb49cb1

Please sign in to comment.