add initial project structure with configuration, models, and API key authentication
This commit is contained in:
34
internal/config/config.go
Normal file
34
internal/config/config.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Port string
|
||||
DSN string
|
||||
APIKeys []string
|
||||
}
|
||||
|
||||
func Load() *Config {
|
||||
port := os.Getenv("PORT")
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
|
||||
raw := os.Getenv("API_KEYS")
|
||||
var keys []string
|
||||
for _, k := range strings.Split(raw, ",") {
|
||||
k = strings.TrimSpace(k)
|
||||
if k != "" {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
}
|
||||
|
||||
return &Config{
|
||||
Port: port,
|
||||
DSN: os.Getenv("DB_DSN"),
|
||||
APIKeys: keys,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user