Files
oslstats/pkg/slapshotapi/config.go
2026-03-05 18:32:55 +11:00

24 lines
690 B
Go

// Package slapshotapi provides utilities for interacting with the slapshot public API
package slapshotapi
import (
"git.haelnorr.com/h/golib/env"
"github.com/pkg/errors"
)
type Config struct {
Environment string `ezconf:"SLAPSHOT_ENVIRONMENT,default:staging,description:API environment to connect to"`
Key string `ezconf:"SLAPSHOT_API_KEY,required,description:API Key for authorisation with the API"`
}
func ConfigFromEnv() (any, error) {
cfg := &Config{
Environment: env.String("SLAPSHOT_ENVIRONMENT", "staging"),
Key: env.String("SLAPSHOT_API_KEY", ""),
}
if cfg.Key == "" {
return nil, errors.New("Envar not set: SLAPSHOT_API_KEY")
}
return cfg, nil
}