Moved github PAT and storage path to env vars

This commit is contained in:
2026-03-30 22:02:39 +02:00
parent b1079efe58
commit bdf7d4f468
10 changed files with 35 additions and 32 deletions
+1 -13
View File
@@ -6,11 +6,6 @@ import (
"gopkg.in/yaml.v3"
)
type GlobalConfig struct {
GithubPat string `yaml:"github_pat"`
StoragePath string `yaml:"storage_path"`
}
type SiteConfig struct {
Name string `yaml:"name"`
Repo string `yaml:"repo"`
@@ -23,8 +18,7 @@ type SiteConfig struct {
}
type Config struct {
Global GlobalConfig `yaml:"global"`
Sites []SiteConfig `yaml:"sites"`
Sites []SiteConfig `yaml:"sites"`
}
type Error struct {
@@ -37,12 +31,6 @@ func (c Error) Error() string {
}
func validateConfig(config *Config) error {
if config.Global.GithubPat == "" {
return &Error{Field: "global.github_pat", Message: "GitHub PAT is required"}
}
if config.Global.StoragePath == "" {
return &Error{Field: "global.storage_path", Message: "Storage path is required"}
}
for i, site := range config.Sites {
if site.Name == "" {
return &Error{Field: "sites[" + string(i) + "].name", Message: "Name is required"}
+21 -5
View File
@@ -1,10 +1,14 @@
package envconfig
import "os"
import (
"os"
)
type EnvConfig struct {
Port string
ConfigDir string
Port string
ConfigDir string
GithubPat string
StoragePath string
}
func Load() EnvConfig {
@@ -18,8 +22,20 @@ func Load() EnvConfig {
configDir = "./"
}
githubPat := os.Getenv("GITHUB_PAT")
if githubPat == "" {
githubPat = ""
}
storagePath := os.Getenv("STORAGE_PATH")
if storagePath == "" {
storagePath = "./storage"
}
return EnvConfig{
Port: port,
ConfigDir: configDir,
Port: port,
ConfigDir: configDir,
GithubPat: githubPat,
StoragePath: storagePath,
}
}