Пример #1
0
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)
	}
}
Пример #2
0
// SetConfigOverrides will check the *CLI variables for any values
// and override the values in the given config if they are set.
// If LogCLI is set to "dev", the given `Log` pointer will be set to an
// empty string.
func SetConfigOverrides(c *Config) {
	// HTTPAccessLogCLI is a pointer to the value of the '-http-access-log' command line flag. It is meant to
	// declare an access log location for HTTP services.
	HTTPAccessLogCLI := flag.String("http-access-log", "", "HTTP access log location")
	// RPCAccessLogCLI is a pointer to the value of the '-rpc-access-log' command line flag. It is meant to
	// declare an acces log location for RPC services.
	RPCAccessLogCLI := flag.String("rpc-access-log", "", "RPC access log location")
	// HTTPPortCLI is a pointer to the value for the '-http' flag. It is meant to declare the port
	// number to serve HTTP services.
	HTTPPortCLI := flag.Int("http", 0, "Port to run an HTTP server on")
	// RPCPortCLI is a pointer to the value for the '-rpc' flag. It is meant to declare the port
	// number to serve RPC services.
	RPCPortCLI := flag.Int("rpc", 0, "Port to run an RPC server on")

	config.SetLogOverride(&c.Log)

	if *HTTPAccessLogCLI != "" {
		c.HTTPAccessLog = HTTPAccessLogCLI
	}

	if *RPCAccessLogCLI != "" {
		c.RPCAccessLog = RPCAccessLogCLI
	}

	if *HTTPPortCLI > 0 {
		c.HTTPPort = *HTTPPortCLI
	}

	if *RPCPortCLI > 0 {
		c.RPCPort = *RPCPortCLI
	}
}
Пример #3
0
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)
	}
}