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 }
func qcloudSetconfig(conf config.ConfigContainer) error { QcloudEndpoint = conf.String("qcloud::endpoint") if QcloudEndpoint == "" { return fmt.Errorf("Read endpoint of qcloud failed!") } QcloudAccessID = conf.String("qcloud::accessID") if QcloudAccessID == "" { return fmt.Errorf("Read accessID of qcloud failed!") } QcloudBucket = conf.String("qcloud::bucket") if QcloudBucket == "" { return fmt.Errorf("Read bucket qcloud failed!") } QcloudAccessKeyID = conf.String("qcloud::accessKeyID") if QcloudAccessKeyID == "" { return fmt.Errorf("Read accessKeyID of qcloud failed!") } QcloudAccessKeySecret = conf.String("qcloud::accessKeysecret") if QcloudAccessKeySecret == "" { return fmt.Errorf("Read accessKeysecret of qcloud failed!") } return nil }
func upgetconfig(conffile string) (err error) { var conf config.ConfigContainer conf, err = config.NewConfig("ini", conffile) if err != nil { return err } g_upEndpoint = conf.String("upCloud::endpoint") if g_upEndpoint == "" { return errors.New("read config file's endpoint failed!") } g_upBucket = conf.String("upCloud::bucket") if g_upBucket == "" { return errors.New("read config file's bucket failed!") } g_upUser = conf.String("upCloud::user") if g_upUser == "" { return errors.New("read config file's user failed!") } g_upPasswd = conf.String("upCloud::passwd") if g_upPasswd == "" { return errors.New("read config file's passwd failed!") } return nil }
//Parses Config to struct with beego AppConfig func ParseConfig(beeConf config.ConfigContainer, obj interface{}) error { val := reflect.ValueOf(obj) if !val.CanAddr() && val.Kind() != reflect.Ptr { return errors.New(NOT_PTR) } val = val.Elem() tp := val.Type() for i := 0; i < val.NumField(); i++ { //Get Config tag tag := tp.Field(i).Tag.Get(CONF_TAG) if tag == "" { continue } v := val.Field(i) //Type casting switch v.Interface().(type) { case bool: b, err := beeConf.Bool(tag) if err != nil { return err } v.SetBool(b) case int, int64: b, err := beeConf.Int(tag) if err != nil { return err } v.SetInt(int64(b)) case float64: b, err := beeConf.Float(tag) if err != nil { return err } v.SetFloat(b) case string: v.SetString(beeConf.String(tag)) default: return errors.New(UNSUPPORTED_TYPE) } } return nil }
func amazons3Setconfig(conf config.ConfigContainer) error { Amazons3Endpoint = conf.String("amazons3::endpoint") if Amazons3Endpoint == "" { return fmt.Errorf("Read endpoint of amazons3 failed!") } Amazons3Bucket = conf.String("amazons3::bucket") if Amazons3Bucket == "" { return fmt.Errorf("Read bucket of amazons3 failed!") } Amazons3AccessKeyID = conf.String("amazons3::accessKeyID") if Amazons3AccessKeyID == "" { return fmt.Errorf("Read accessKeyID of amazons3 failed!") } Amazons3AccessKeySecret = conf.String("amazons3::accessKeysecret") if Amazons3AccessKeySecret == "" { return fmt.Errorf("Read accessKeysecret of amazons3 failed!") } return nil }
func Initialize(env string, cc config.ConfigContainer) (r App, err error) { r.Db.Driver = cc.String(env + "::driver") r.Db.Postgres.Host = cc.String(env + "::pghost") r.Db.Postgres.Database = cc.String(env + "::pgdb") r.Db.Postgres.User = cc.String(env + "::pguser") r.Db.Postgres.Pass = cc.String(env + "::pgpass") r.Log.Dist = cc.String("log::dist") if r.Log.Dist == "file" { r.Log.File.Minutes, err = cc.Int("log::minutes") if err != nil { return } r.Log.File.Ext = cc.String("log::ext") r.Log.File.Folder = cc.String("log::folder") } return }