github.com/grafviktor/keep-my-secret@v0.9.10-0.20230908165355-19f35cce90e5/internal/config/config.go (about) 1 // Package config - contains application configuration structures 2 package config 3 4 import "github.com/grafviktor/keep-my-secret/internal/storage" 5 6 // EnvConfig is reqyured 7 type EnvConfig struct { 8 // Secret which is used for signing cookies 9 Secret string `env:"APP_SECRET" envDefault:"romeo romeo whiskey"` 10 // ServerAddr defines host and port where server is running 11 ServerAddr string `env:"SERVER_ADDRESS" envDefault:"localhost:8080"` 12 // PSQL connection string (DSN) 13 DSN string `env:"DSN" envDefault:"./kms.db"` 14 // HTTPS TLS certificate path 15 HTTPSCertPath string `env:"TLS_CERT_PATH" envDefault:"./tls/cert.pem"` 16 // HTTPS TLS key path 17 HTTPSKeyPath string `env:"TLS_KEY_PATH" envDefault:"./tls/key.pem"` 18 // Self-explanatory 19 Domain string `env:"DOMAIN" envDefault:"localhost"` 20 // ClientURL is used to define browser path to the client application 21 ClientURL string `env:"CLIENT_URL" envDefault:"/"` 22 // DevMode enables CORS 23 DevMode bool `env:"DEV" envDefault:"false"` 24 } 25 26 type AppConfig struct { 27 ServerAddr string 28 // PSQL connection string (DSN) 29 DSN string 30 // HTTPS TLS certificate path 31 HTTPSCertPath string 32 // HTTPS TLS key path 33 HTTPSKeyPath string 34 // Client application relative path 35 ClientAppURL string 36 // Secret which is used for signing cookies 37 Secret string 38 // The entity which issued the certificate. Normally just domain name. See JWT docuymentation 39 JWTIssuer string 40 // JWT consumers. Normally just domain name. See JWT documentation 41 JWTAudience string 42 // Domain name where the cookie with token is valid 43 CookieDomain string 44 // Only SQL is supported 45 StorageType storage.Type 46 // If devmode is enabled, then CORS requests are allowed 47 DevMode bool 48 } 49 50 // New creates new App config instance with pre-defined parameters 51 func New(ec EnvConfig) AppConfig { 52 return AppConfig{ 53 ClientAppURL: ec.ClientURL, 54 CookieDomain: ec.Domain, 55 DSN: ec.DSN, 56 HTTPSCertPath: ec.HTTPSCertPath, 57 HTTPSKeyPath: ec.HTTPSKeyPath, 58 JWTAudience: ec.Domain, 59 JWTIssuer: ec.Domain, 60 Secret: ec.Secret, 61 ServerAddr: ec.ServerAddr, 62 StorageType: storage.TypeSQL, 63 DevMode: ec.DevMode, 64 } 65 }