Skip to content
This repository has been archived by the owner on Jul 11, 2019. It is now read-only.

Commit

Permalink
resolved #1: specify config file path
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny committed Nov 5, 2015
1 parent d487c20 commit ed834a0
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"flag"
"fmt"
"os"
"path/filepath"

"github.com/Unknwon/goconfig"
"github.com/goftp/file-driver"
Expand All @@ -20,17 +22,33 @@ var (
)

var (
cfg *goconfig.ConfigFile
cfg *goconfig.ConfigFile
cfgPath string
customPath string
)

func main() {
flag.StringVar(&cfgPath, "config", "config.ini",
"config file path, default is config.ini and custom.ini")
flag.Parse()

if len(cfgPath) <= 0 {
cfgPath = "config.ini"
customPath = "custom.ini"
} else {
f, _ := filepath.Abs(cfgPath)
customPath = filepath.Join(filepath.Dir(f), "custom.ini")
}

var err error
cfg, err = goconfig.LoadConfigFile("config.ini", "custom.ini")
cfg, err = goconfig.LoadConfigFile(cfgPath, customPath)
if err != nil {
fmt.Println(err)
return
}

log.Info("Loaded config files:", cfgPath, customPath)

port, _ := cfg.Int("server", "port")
db, err := leveldb.OpenFile("./authperm.db", nil)
if err != nil {
Expand All @@ -39,13 +57,6 @@ func main() {
}

var auth = &ldbauth.LDBAuth{db}
/*if cfg.MustValue("auth", "type") == "xorm" {
panic("current is not supported yet")
//auth = xormauth.NewXormAuth(orm *xorm.Engine, allowAnony bool, perm os.FileMode)
} else {
}*/

var perm server.Perm
if cfg.MustValue("perm", "type") == "leveldb" {
perm = ldbperm.NewLDBPerm(db, "root", "root", os.ModePerm)
Expand Down

0 comments on commit ed834a0

Please sign in to comment.