mirror of
https://github.com/aykhans/oh-my-url.git
synced 2025-07-05 17:52:36 +00:00
✨ Add Cassandra support and update README.md
This commit is contained in:
@ -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