本文整理汇总了Golang中github.com/astaxie/beego/config.NewConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewConfig函数的具体用法?Golang NewConfig怎么用?Golang NewConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getConfig
func getConfig() (conf config.Configer, err error) {
home := os.Getenv("HOME")
if home != "" {
homePath := filepath.Join(home, ".dockyard", "containerops.conf")
conf, err = config.NewConfig("ini", homePath)
}
if err != nil {
conf, err = config.NewConfig("ini", "conf/containerops.conf")
}
return
}
示例2: amazons3getconfig
func amazons3getconfig(conffile string) (err error) {
conf, err := config.NewConfig("ini", conffile)
if err != nil {
return err
}
g_amazons3Endpoint = conf.String("amazons3cloud::endpoint")
if g_amazons3Endpoint == "" {
return errors.New("read config file's endpoint failed!")
}
g_amazons3Bucket = conf.String("amazons3cloud::bucket")
if g_amazons3Bucket == "" {
return errors.New("read config file's bucket failed!")
}
g_amazons3AccessKeyID = conf.String("amazons3cloud::accessKeyID")
if g_amazons3AccessKeyID == "" {
return errors.New("read config file's accessKeyID failed!")
}
g_amazons3AccessKeySecret = conf.String("amazons3cloud::accessKeysecret")
if g_amazons3AccessKeySecret == "" {
return errors.New("read config file's accessKeysecret failed!")
}
return nil
}
示例3: Get
func (this *Configuration) Get() config.ConfigContainer {
data, error := config.NewConfig("yaml", "./conf/app.yml")
if error != nil {
log.Fatal(error)
}
return data
}
示例4: qiniugetconfig
func qiniugetconfig(conffile string) (err error) {
var conf config.ConfigContainer
conf, err = config.NewConfig("ini", conffile)
if err != nil {
return err
}
g_qiniuEndpoint = conf.String("qiniucloud::endpoint")
if g_qiniuEndpoint == "" {
return errors.New("read config file's endpoint failed!")
}
g_qiniuBucket = conf.String("qiniucloud::bucket")
if g_qiniuBucket == "" {
return errors.New("read config file's bucket failed!")
}
g_qiniuAccessKeyID = conf.String("qiniucloud::accessKeyID")
if g_qiniuAccessKeyID == "" {
return errors.New("read config file's accessKeyID failed!")
}
g_qiniuAccessKeySecret = conf.String("qiniucloud::accessKeysecret")
if g_qiniuAccessKeySecret == "" {
return errors.New("read config file's accessKeysecret failed!")
}
return nil
}
示例5: init
func init() {
cmd, err := notify.NewCmd("telegram-cli", "-C")
if err != nil {
log.Fatal("NewCmd error", err)
}
botConf = Conf{
Limit: 10,
Url: "localhost",
Rpms: 500,
Cmd: cmd,
}
//Init Data Mapper
c, err := beeconf.NewConfig("ini", "../../conf/app.conf")
if err != nil {
log.Fatal(err)
}
TestConfig, err := conf.Initialize("test", c)
if err != nil {
log.Fatal(err)
}
if err := M.DbOpen(TestConfig.Db); err != nil {
log.Fatal(err)
}
M.PrepareTables(&M.Cand{})
Tfn, _ := i18n.Tfunc("en-us", "en-us", "en-us")
M.T = Tfn
}
示例6: main
func main() {
tracelog.StartFile(tracelog.LevelTrace, "logs", 1)
tracelog.Started("main", "Initializing Postgres")
var confName string = os.Getenv("BOOKS_CONF")
if len(confName) == 0 {
confName = "default"
}
s := []string{"conf/db/", confName, ".json"}
jsonconf, err := config.NewConfig("json", strings.Join(s, ""))
if err != nil {
tracelog.Errorf(err, "main", "config.NewConfig", "Failed to find config", strings.Join(s, ""))
}
var User string = jsonconf.String("User")
var Pass string = jsonconf.String("Pass")
var DBName string = jsonconf.String("DBName")
var buffer bytes.Buffer
buffer.WriteString("user=")
buffer.WriteString(User)
buffer.WriteString(" password=")
buffer.WriteString(Pass)
buffer.WriteString(" dbname=")
buffer.WriteString(DBName)
s2 := []string{"user=", User, " password=", Pass, " dbname=", DBName, " sslmode=disable"}
orm.RegisterDriver("postgres", orm.DR_Postgres)
orm.RegisterDataBase("default", "postgres", strings.Join(s2, ""))
beego.SetStaticPath("/images", "static/images")
beego.SetStaticPath("/css", "static/css")
beego.SetStaticPath("/js", "static/js")
beego.SetStaticPath("/fonts", "static/fonts")
beego.SetStaticPath("/partials", "static/partials")
beego.EnableAdmin = true
orm.RunCommand()
beego.Run()
}
示例7: init
func init() {
duangcfg, err := config.NewConfig("ini", "conf/duang.conf")
if err != nil {
fmt.Println(err)
return
}
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%s:%[email protected]%s/%s?charset=utf8", duangcfg.String("db_user"), duangcfg.String("db_pass"), duangcfg.String("db_addr"), duangcfg.String("db_name")))
orm.RegisterModel(
new(Unit),
new(UnitParameter),
new(Dockerd),
new(Ip),
new(Container),
//new(Frontend),
//new(Backend),
)
force, err := duangcfg.Bool("db_dropifexist")
if err != nil {
force = false
}
verbose := true
err = orm.RunSyncdb("default", force, verbose)
if err != nil {
beego.Error(err)
}
}
示例8: Test_upyunsave
func Test_upyunsave(t *testing.T) {
var err error
var conf config.ConfigContainer
var url string
conf, err = config.NewConfig("ini", "../../../conf/containerops.conf")
if err != nil {
t.Error(err)
}
d := new(UpyunDrv)
err = d.ReadConfig(conf)
if err != nil {
t.Error(err)
}
file := "upyun_test.go"
url, err = upyunsave(file)
if err != nil {
t.Error(err)
}
_, err = http.Get(url)
if err != nil {
t.Error(err)
}
}
示例9: newAppConfig
func newAppConfig(appConfigProvider, appConfigPath string) (*beegoAppConfig, error) {
ac, err := config.NewConfig(appConfigProvider, appConfigPath)
if err != nil {
return nil, err
}
return &beegoAppConfig{ac}, nil
}
示例10: initORM
func initORM() {
if ormInitiated {
return
}
appConf, err := config.NewConfig("ini", "conf/app.conf")
if err != nil {
panic(err)
}
dbAddr := appConf.String("admin::dbAddr")
dbUser := appConf.String("admin::dbUser")
dbPass := appConf.String("admin::dbPass")
controllers.ALI_YUN_AK_ID = appConf.String("admin::akId")
controllers.ALI_YUN_AK_KEY = appConf.String("admin::akKey")
controllers.QQ_OAUTH_CONSUMER_KEY = appConf.String("admin::qqOAuthConsumerKey")
clientId := appConf.String("admin::clientId")
clientSecret := appConf.String("admin::clientSecret")
controllers.BASIC_AUTH_AUTHORIZATION = utils.Base64(clientId + ":" + clientSecret)
controllers.VISITOR_TOKEN = appConf.String("admin::visitorToken")
orm.RegisterDriver("mymysql", orm.DRMySQL)
conn := fmt.Sprintf("%s:%[email protected](%s)/beego_unit_test?charset=utf8mb4", dbUser, dbPass, dbAddr)
orm.RegisterDataBase("default", "mysql", conn)
ormInitiated = true
}
示例11: NewConfig
func NewConfig(file string) (Configure, error) {
appConfigPath, isCurrentDir, err := findAppConfPath(file)
if err != nil {
return nil, err
}
configer, err := config.NewConfig("ini", appConfigPath)
if err != nil {
return nil, err
}
var runMode string
if isCurrentDir == false {
runMode = "test"
} else if envRunMode := os.Getenv("BEEGO_RUNMODE"); envRunMode != "" {
runMode = envRunMode
} else if configRunMode := configer.String("RunMode"); configRunMode != "" {
runMode = configRunMode
} else {
runMode = "dev"
}
return &configureImplement{
runMode: runMode,
configer: configer,
}, nil
}
示例12: Get
func (c *ZhouBianWifiWXController) Get() {
op := c.Input().Get("op")
switch op {
case "location":
latitude := c.Input().Get("latitude")
longitude := c.Input().Get("longitude")
c.Data["latitude"] = latitude
c.Data["longitude"] = longitude
beego.Debug("latitude:", latitude)
beego.Debug("longitude:", longitude)
getWifi(longitude, latitude, c)
c.TplName = "zhoubianwifi.html"
return
}
appId := ""
iniconf, err := config.NewConfig("json", "conf/myconfig.json")
if err != nil {
beego.Debug(err)
} else {
appId = iniconf.String("qax580::appid")
}
timestamp := time.Now().Unix()
noncestr := getNonceStr(16, KC_RAND_KIND_ALL)
c.Data["AppId"] = appId
c.Data["TimesTamp"] = timestamp
c.Data["NonceStr"] = noncestr
getWifiWxJsToken(noncestr, timestamp, c)
c.TplName = "zhoubianwifiwx.html"
// getWifi("116.366324", "39.905859", c)
// c.TplName = "zhoubianwifi.html"
}
示例13: initDb
func initDb() {
iniconf, err := config.NewConfig("ini", "conf/app.conf")
if err != nil {
beego.Error(err)
}
driverName := iniconf.String("orm::driver_name")
dataSource := iniconf.String("orm::data_source")
maxIdle, _ := iniconf.Int("orm::max_idle_conn")
maxOpen, _ := iniconf.Int("orm::max_open_conn")
// set default database
err = orm.RegisterDataBase("default", driverName, dataSource, maxIdle, maxOpen)
if err != nil {
beego.Error(err)
}
// orm.Debug = true
//orm.RunCommand() //执行命令行的
err = orm.RunSyncdb("default", false, false) //建表的
////数据库别名,不强制建数据库,打印建表过程
if err != nil {
beego.Error(err)
}
}
示例14: readConfig
func readConfig() {
jsonconf, err := config.NewConfig("json", "conf/config.json")
if err != nil {
panic(err)
}
BlogInfo = make(map[string]string)
BlogInfo["title"] = jsonconf.String("blog::title")
BlogInfo["subtitle"] = jsonconf.String("blog::subtitle")
fmt.Println(BlogInfo)
admin = new(User)
admin.Email = jsonconf.String("admin::email")
admin.Username = jsonconf.String("admin::username")
admin.Password = jsonconf.String("admin::password")
_, err = c_users.RemoveAll(bson.M{})
if err != nil {
panic(err)
}
AddUser(admin)
h := md5.New()
h.Write([]byte(admin.Email))
BlogInfo["avatarhash"] = fmt.Sprintf("%x", h.Sum(nil))
}
示例15: ConnectDB
func ConnectDB(env string) {
DBconf, err := config.NewConfig("ini", "config/database.conf")
if err != nil {
panic(err)
}
config, err := DBconf.GetSection(env)
if err != nil {
panic(err)
}
DB, err = gorm.Open("postgres", "host="+config["host"]+" user="+config["user"]+" dbname="+config["dbname"]+" sslmode=disable")
if err != nil {
log.Fatalln(err)
return
}
switch env {
case "dev":
// DB.LogMode(true)
case "test":
loadFixtures()
}
}