diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 33 |
1 files changed, 22 insertions, 11 deletions
@@ -1,6 +1,7 @@ package main import ( + "flag" "html/template" "log" "net/http" @@ -8,7 +9,7 @@ import ( "strings" "time" - "github.com/virtyx-technologies/readenv" + "github.com/BurntSushi/toml" ) func main() { @@ -18,21 +19,30 @@ func main() { } type options struct { - Port string `env:"PORT"` - CacheExpiry time.Duration `env:"CACHE_EXPIRY"` - UpstreamTimeout time.Duration `env:"UPSTREAM_TIMEOUT"` - SourcehutUsername string `env:"SRHT_USERNAME"` - SourcehutToken string `env:"SRHT_TOKEN"` - GithubUsername string `env:"GITHUB_USERNAME"` - GithubToken string `env:"GITHUB_TOKEN"` - CanonicalPrefix string `env:"CANONICAL_PREFIX"` + BindAddress string `toml:"bind_address"` + CacheExpiry time.Duration `toml:"cache_expiry"` + UpstreamTimeout time.Duration `toml:"upstream_timeout"` + SourcehutUsername string `toml:"srht_username"` + SourcehutToken string `toml:"srht_token"` + GithubUsername string `toml:"github_username"` + GithubToken string `toml:"github_token"` + CanonicalPrefix string `toml:"canonical_prefix"` } func run() error { + cfgPath := flag.String("c", "", "path to configuration file") + flag.Parse() + + if cfgPath == nil || *cfgPath == "" { + flag.Usage() + os.Exit(1) + } + var opts options - if err := readenv.ReadEnv(&opts); err != nil { + if _, err := toml.DecodeFile(*cfgPath, &opts); err != nil { return err } + cache := &PackageCache{ CanonicalPrefix: opts.CanonicalPrefix, ExpireAfter: opts.CacheExpiry, @@ -44,7 +54,8 @@ func run() error { }, } handler := handlePackage(cache) - return http.ListenAndServe(":"+opts.Port, handler) + log.Printf("starting server to listen on %s...", opts.BindAddress) + return http.ListenAndServe(opts.BindAddress, handler) } func handlePackage(pkgs *PackageCache) http.HandlerFunc { |