Add Cassandra support and update README.md

This commit is contained in:
2024-03-10 22:33:35 +04:00
parent fa999fea14
commit 89237193f4
12 changed files with 335 additions and 1 deletions

View File

@ -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
}