mirror of
https://github.com/versia-pub/versia-go.git
synced 2026-03-12 20:19:15 +01:00
chore: init
This commit is contained in:
commit
320715f3e7
174 changed files with 42083 additions and 0 deletions
55
config/config.go
Normal file
55
config/config.go
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"os"
|
||||
|
||||
"git.devminer.xyz/devminer/unitel"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
PublicAddress *url.URL
|
||||
InstanceName string
|
||||
InstanceDescription *string
|
||||
|
||||
NATSURI string
|
||||
DatabaseURI string
|
||||
|
||||
Telemetry unitel.Opts
|
||||
}
|
||||
|
||||
var C Config
|
||||
|
||||
func Load() {
|
||||
if err := godotenv.Load(".env.local", ".env"); err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to load .env file")
|
||||
}
|
||||
|
||||
publicAddress, err := url.Parse(os.Getenv("PUBLIC_ADDRESS"))
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Failed to parse PUBLIC_ADDRESS")
|
||||
}
|
||||
|
||||
C = Config{
|
||||
PublicAddress: publicAddress,
|
||||
InstanceName: os.Getenv("INSTANCE_NAME"),
|
||||
InstanceDescription: optionalEnvStr("INSTANCE_DESCRIPTION"),
|
||||
|
||||
NATSURI: os.Getenv("NATS_URI"),
|
||||
DatabaseURI: os.Getenv("DATABASE_URI"),
|
||||
|
||||
Telemetry: unitel.ParseOpts("versia-go"),
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func optionalEnvStr(key string) *string {
|
||||
value := os.Getenv(key)
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
return &value
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue