示例#1
0
文件: sub.go 项目: strogo/gizmo
func Init() {
	flag.Parse()

	var cfg *Config
	config.LoadJSONFile("./config.json", &cfg)
	config.SetLogOverride(cfg.Log)

	if *cfg.Log != "" {
		lf, err := logrotate.NewFile(*cfg.Log)
		if err != nil {
			Log.Fatalf("unable to access log file: %s", err)
		}
		Log.Out = lf
		Log.Formatter = &logrus.JSONFormatter{}
	} else {
		Log.Out = os.Stderr
	}

	pubsub.Log = Log

	if cfg.GraphiteHost != nil {
		initMetrics(*cfg.GraphiteHost)
	}

	client = nyt.NewClient(cfg.MostPopularToken, cfg.SemanticToken)

	var err error
	sub, err = pubsub.NewSQSSubscriber(cfg.SQS)
	if err != nil {
		Log.Fatal("unable to init pb subs SQS: ", err)
	}
}
示例#2
0
文件: sub.go 项目: ycaihua/gizmo
func Init() {
	var cfg *Config
	config.LoadJSONFile("./config.json", &cfg)
	config.SetLogOverride(cfg.Log)

	if *cfg.Log != "" {
		lf, err := logrotate.NewFile(*cfg.Log)
		if err != nil {
			Log.Fatalf("unable to access log file: %s", err)
		}
		Log.Out = lf
		Log.Formatter = &logrus.JSONFormatter{}
	} else {
		Log.Out = os.Stderr
	}

	pubsub.Log = Log

	var err error
	cfg.Metrics.Prefix = metricsNamespace()
	metrics, err = cfg.Metrics.NewProvider()
	if err != nil {
		Log.Fatal("unable to init metrics: ", err)
	}

	client = nyt.NewClient(cfg.MostPopularToken, cfg.SemanticToken)

	sub, err = aws.NewSubscriber(cfg.SQS)
	if err != nil {
		Log.Fatal("unable to init SQS: ", err)
	}
}
示例#3
0
文件: boltdb.go 项目: slok/khronos
// LoadBoltDBConfig loads boltdb env and jsonfile config
func (b *BoltDB) LoadBoltDBConfig(cfg *AppConfig) {
	if cfg.ConfigFilePath != "" {
		config.LoadJSONFile(cfg.ConfigFilePath, b)
	}

	config.LoadEnvConfig(b)

	logrus.Infof("Boltdb database path: %s", cfg.BoltDBPath)
	logrus.Infof("Boltdb timeout set to: %ds", cfg.BoltDBTimeoutSeconds)
}
示例#4
0
文件: config.go 项目: ycaihua/gizmo
// NewConfig will attempt to unmarshal the contents
// of the given JSON string source into a Config struct.
// The value of fileName can be either the path to a JSON
// file or a path to a JSON string found in Consul's Key
// Value storage (using the format consul:path/to/JSON/string).
// If the value of fileName is empty, a blank Config will
// be returned.
func NewConfig(fileName string) *Config {
	var c Config
	if fileName == "" {
		return &c
	}
	if strings.HasPrefix(fileName, "consul") {
		return config.LoadJSONFromConsulKV(fileName, &c).(*Config)
	}
	config.LoadJSONFile(fileName, &c)
	return &c
}
示例#5
0
文件: main.go 项目: strogo/gizmo
func main() {
	// showing 1 way of managing gizmo/config: importing from a local file
	var cfg *service.Config
	config.LoadJSONFile("./config.json", &cfg)

	server.Init("nyt-most-popular-json-proxy", cfg.Server)

	err := server.Register(service.NewJSONService(cfg))
	if err != nil {
		server.Log.Fatal("unable to register service: ", err)
	}

	err = server.Run()
	if err != nil {
		server.Log.Fatal("server encountered a fatal error: ", err)
	}
}
示例#6
0
func main() {
	var cfg *service.Config
	config.LoadJSONFile("./config.json", &cfg)
	server.Init("gizmo-boilerplate", cfg.Server)
	dbSql, err := cfg.MySQL.DB()
	if err != nil {
		server.Log.Fatal("unable to connect to mysql ", err)
	}
	cfg.DB, _ = gorm.Open("mysql", dbSql)
	mongoSess := cfg.MongoDB.MustMaster()
	cfg.Mongo = mongoSess.DB(cfg.MongoDB.DB)
	err = server.Register(service.NewJSONService(cfg))
	if err != nil {
		server.Log.Fatal("unable to register service: ", err)
	}

	err = server.Run()
	if err != nil {
		server.Log.Fatal("server encountered a fatal error: ", err)
	}
}
示例#7
0
文件: khronos.go 项目: slok/khronos
// LoadKhronosConfig Loads the configuration for the application
func (k *Khronos) LoadKhronosConfig(cfg *AppConfig) {

	if cfg.ConfigFilePath != "" {
		config.LoadJSONFile(cfg.ConfigFilePath, k)
	}

	config.LoadEnvConfig(k)

	// Load defaults
	k.LoadDefaults()

	// Check storage Engine
	valid := false
	for _, v := range ValidStorageEngines {
		if v == k.StorageEngine {
			valid = true
			break
		}
	}
	if !valid {
		logrus.Fatal("Incorrect storage engine")
	}

	logrus.Infof("Using '%s' storage engine", cfg.StorageEngine)
	logrus.Infof("Set result buffer length to %d", cfg.ResultBufferLen)

	if k.DontScheduleJobsStart {
		logrus.Warning("Not loading jobs on startup")
	} else {
		logrus.Infof("Loading jobs on startup active")
	}

	if k.APIDisableSecurity {
		logrus.Warning("Security of the API is disabled!")
	}
}
示例#8
0
文件: config.go 项目: slok/khronos
func (a *AppConfig) loadConfigFromFile() {
	config.LoadJSONFile(a.ConfigFilePath, a)
	config.LoadJSONFile(a.ConfigFilePath, a.Server)
}