CheqBooq/config/config.go

41 lines
808 B
Go

package config
import (
"fmt"
"local/args"
"os"
"strings"
)
var (
Port string
Public string
StoreAddr string
StoreNS string
Page int
)
func init() {
New()
}
func New() {
if strings.Contains(fmt.Sprint(os.Args), "-test") {
return
}
as := args.NewArgSet()
as.Append(args.INT, "p", "port to listen on", 52222)
as.Append(args.INT, "page", "page size for requests", 20)
as.Append(args.STRING, "d", "dir with public files", "./public")
as.Append(args.STRING, "s", "mongodb address", "localhost:27017")
as.Append(args.STRING, "ns", "mongodb database", "cheqbooq")
if err := as.Parse(); err != nil {
panic(err)
}
Port = fmt.Sprintf(":%d", as.GetInt("p"))
Page = as.GetInt("page")
Public = as.GetString("d")
StoreAddr = as.GetString("s")
StoreNS = as.GetString("ns")
}