Beispiel #1
0
func init() {
	switch os.Getenv("StorageEngine") {
	case "s3":
		secret := os.Getenv("AWS_SECRET_KEY")
		access := os.Getenv("AWS_ACCESS_KEY")
		bucket := os.Getenv("AWS_BUCKET")
		region := os.Getenv("AWS_REGION")
		content := "application/json; charset=utf-8"

		store = storage.S3(secret, access, bucket, region, content)

	case "folder":
		store = storage.Folder("/tmp/storage")

	case "redis":
		store = storage.Redis(os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT"))

	case "memcache":
		hosts := strings.Split(os.Getenv("MEMCACHE_HOSTS"), ",")
		store = storage.Memcache(hosts)

	default:
		store = storage.Local()
	}
}
Beispiel #2
0
func init() {
	var err error

	switch os.Getenv("STORAGE_ENGINE") {
	case "s3":
		secret := os.Getenv("AWS_SECRET_KEY")
		access := os.Getenv("AWS_ACCESS_KEY")
		bucket := os.Getenv("AWS_BUCKET")
		region := os.Getenv("AWS_REGION")
		content := "application/json; charset=utf-8"
		prefix := "test/storage"

		store, err = storage.S3(access, secret, bucket, region, content, prefix)
		// all keys will be surrounded by the prefix value and content
		// extension (if recognized) like: "test/storage/name.json"

	case "folder":
		store, err = storage.Folder(os.Getenv("FOLDER_STORAGE_PATH"))

	case "redis":
		store = storage.Redis(os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT"))

	case "memcached":
		hosts := strings.Split(os.Getenv("MEMCACHED_HOSTS"), ",")
		store = storage.Memcached(hosts)

	case "bolt":
		store, err = storage.Bolt(os.Getenv("BOLTDB_FILE_PATH"))

	case "dynamodb":
		secret := os.Getenv("AWS_SECRET_KEY")
		access := os.Getenv("AWS_ACCESS_KEY")
		region := os.Getenv("AWS_REGION")
		table := os.Getenv("DYNAMODB_TABLE")

		store, err = storage.DynamoDB(access, secret, region, table)

	case "elasticsearch":
		host := os.Getenv("ES_HOST")
		scheme := os.Getenv("ES_SCHEME")
		index := os.Getenv("ES_INDEX")
		namespace := os.Getenv("APP_NAME")
		awsSecret := os.Getenv("AWS_SECRET_KEY")
		awsKey := os.Getenv("AWS_ACCESS_KEY")

		store, err = storage.ElasticSearch(host, scheme, index, namespace, awsKey, awsSecret)

	default:
		store = storage.Local()
	}

	if err != nil {
		// Handle the error appropriately.
		// You may not want to panic in your application.
		panic(err.Error())
	}
}