Exemplo n.º 1
0
Arquivo: sub.go Projeto: 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)
	}
}
Exemplo n.º 2
0
Arquivo: sub.go Projeto: 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)
	}
}
Exemplo n.º 3
0
// NewSimpleService will instantiate a SimpleService
// with the given configuration.
func NewSimpleService(cfg *Config) *SimpleService {
	return &SimpleService{
		nyt.NewClient(cfg.MostPopularToken, cfg.SemanticToken),
	}
}
Exemplo n.º 4
0
// NewRPCService will instantiate a RPCService
// with the given configuration.
func NewRPCService(cfg *Config) *RPCService {
	return &RPCService{
		nyt.NewClient(cfg.MostPopularToken, cfg.SemanticToken),
	}
}
Exemplo n.º 5
0
// NewMixedService will instantiate a MixedService
// with the given configuration.
func NewMixedService(cfg *Config) *MixedService {
	return &MixedService{
		nyt.NewClient(cfg.MostPopularToken, cfg.SemanticToken),
	}
}