mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-09-03 20:13:32 +00:00
✨ Add Cassandra support and update README.md
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
CASSANDRA_USER=user
|
||||
CASSANDRA_PASSWORD=password
|
||||
CASSANDRA_KEYSPACE=ohmyurl
|
||||
CASSANDRA_DB=url
|
||||
CASSANDRA_CLUSTERS=ohmyurl-cassandra-1:9042,ohmyurl-cassandra-2:9042,ohmyurl-cassandra-3:9042
|
||||
LISTEN_PORT_CREATE=8080
|
||||
LISTEN_PORT_FORWARD=8081
|
||||
FORWARD_DOMAIN=http://localhost/
|
||||
CREATE_DOMAIN=http://127.0.0.1
|
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -28,6 +29,16 @@ type PostgresConfig struct {
|
||||
DBNAME string
|
||||
}
|
||||
|
||||
type CassandraConfig struct {
|
||||
USER string
|
||||
PASSWORD string
|
||||
KEYSPACE string
|
||||
CLUSTERS []string
|
||||
APP_LABEL string
|
||||
URL_START_ID int
|
||||
URL_END_ID int
|
||||
}
|
||||
|
||||
func GetAppConfig() *AppConfig {
|
||||
return &AppConfig{
|
||||
LISTEN_PORT_CREATE: GetEnvOrPanic("LISTEN_PORT_CREATE"),
|
||||
@@ -55,6 +66,18 @@ func GetPostgresConfig() *PostgresConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func GetCassandraConfig() *CassandraConfig {
|
||||
return &CassandraConfig{
|
||||
USER: GetEnvOrPanic("CASSANDRA_USER"),
|
||||
PASSWORD: GetEnvOrPanic("CASSANDRA_PASSWORD"),
|
||||
CLUSTERS: strings.Split(GetEnvOrPanic("CASSANDRA_CLUSTERS"), ","),
|
||||
KEYSPACE: GetEnvOrPanic("CASSANDRA_KEYSPACE"),
|
||||
APP_LABEL: GetEnvOrPanic("CASSANDRA_APP_LABEL"),
|
||||
URL_START_ID: Str2IntOrPanic(GetEnvOrPanic("CASSANDRA_URL_START_ID")),
|
||||
URL_END_ID: Str2IntOrPanic(GetEnvOrPanic("CASSANDRA_URL_END_ID")),
|
||||
}
|
||||
}
|
||||
|
||||
func GetDB() DBName {
|
||||
dbName := strings.ToLower(GetEnvOrPanic("DB"))
|
||||
switch dbName {
|
||||
@@ -84,3 +107,11 @@ func GetEnvOrPanic(key string) string {
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func Str2IntOrPanic(value string) int {
|
||||
i, err := strconv.Atoi(value)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
Reference in New Issue
Block a user