Example #1
0
// here, support a function that maps a given redis key to a dynamodb table key and value field
func NewDynamoModule(keymap KeyMapper) *DynamoModule {

	module := &DynamoModule{}
	cfgdir := "/etc"
	cfg := &module.config
	ok := logging.ReadModuleConfig(cfg, cfgdir, "dynamo") || logging.ReadModuleConfig(cfg, ".", "dynamo")

	sess := session.New(&aws.Config{Region: aws.String("ap-southeast-1")})

	if !ok {
		log.Println("failed to read dynamo config, using defaults")
	} else {
		sess = session.New(&aws.Config{
			Region:     aws.String(cfg.Server.Region),
			Endpoint:   aws.String(cfg.Server.Endpoint),
			DisableSSL: aws.Bool(cfg.Server.DisableSSL),
		})
	}

	module.client = dynamodb.New(sess)
	if keymap != nil {
		module.keyMapper = keymap
	} else {
		module.keyMapper = module.defaultMapper
	}

	if cfg.Server.CacheDuration > 0 {
		logging.Debug.Println("activiating cache, TTL", cfg.Server.CacheDuration)
		module.cache = cache.NewMemoryWithTTL(time.Duration(cfg.Server.CacheDuration) * time.Second)
	}

	return module
}
Example #2
0
func NewHelloWorldModule() *HelloWorldModule {

	var cfg Config

	ok := logging.ReadModuleConfig(&cfg, "config", "hello") || logging.ReadModuleConfig(&cfg, "files/etc/gosample", "hello")
	if !ok {
		// when the app is run with -e switch, this message will automatically be redirected to the log file specified
		log.Fatalln("failed to read config")
	}

	// this message only shows up if app is run with -debug option, so its great for debugging
	logging.Debug.Println("hello init called", cfg.Server.Name)

	// contohnya: caranya ciptakan nsq consumer
	nsqCfg := nsq.NewConfig()
	q := createNewConsumer(nsqCfg, "random-topic", "test", handler)
	q.SetLogger(log.New(os.Stderr, "nsq:", log.Ltime), nsq.LogLevelError)
	q.ConnectToNSQLookupd("nsqlookupd.local:4161")

	return &HelloWorldModule{
		cfg:       &cfg,
		something: "John Doe",
		stats:     expvar.NewInt("rpsStats"),
		q:         q,
	}

}
Example #3
0
// here, support a function that maps a given redis key to a dynamodb table key and value field
func NewDynamoModule(keymap store.KeyMapper) *DynamoModule {

	module := &DynamoModule{}
	cfgdir := "/etc"
	cfg := &module.config
	ok := logging.ReadModuleConfig(cfg, cfgdir, "dynamo") || logging.ReadModuleConfig(cfg, ".", "dynamo")

	sess := session.New(&aws.Config{Region: aws.String("ap-southeast-1")})

	if !ok {
		log.Println("failed to read dynamo config, using defaults")
	} else {
		sess = session.New(&aws.Config{
			Region:     aws.String(cfg.Server.Region),
			Endpoint:   aws.String(cfg.Server.Endpoint),
			DisableSSL: aws.Bool(cfg.Server.DisableSSL),
		})
	}

	module.client = dynamodb.New(sess)
	module.keyMapper = keymap

	return module
}