fix: proper configuration handling across submodules

This commit is contained in:
2025-08-26 00:19:43 -05:00
parent 165e32bbf6
commit a37fbeb224
12 changed files with 408 additions and 327 deletions

View File

@@ -8,57 +8,51 @@ import (
"github.com/redis/go-redis/v9"
)
var (
// Global variables that need to be accessible across packages
type Config struct {
Ctx context.Context
KV *redis.Client
Client http.Client
Cookies http.CookieJar
Client *http.Client
IsDevelopment bool
BaseURL string
Environment string
CentralTimeLocation *time.Location
IsClosing bool = false
)
}
const (
ICalTimestampFormatUtc = "20060102T150405Z"
ICalTimestampFormatLocal = "20060102T150405"
CentralTimezoneName = "America/Chicago"
CentralTimezoneName = "America/Chicago"
)
func init() {
Ctx = context.Background()
func New() (*Config, error) {
ctx := context.Background()
var err error
CentralTimeLocation, err = time.LoadLocation(CentralTimezoneName)
loc, err := time.LoadLocation(CentralTimezoneName)
if err != nil {
panic(err)
return nil, err
}
return &Config{
Ctx: ctx,
CentralTimeLocation: loc,
}, nil
}
// SetBaseURL sets the base URL for API requests
func SetBaseURL(url string) {
BaseURL = url
func (c *Config) SetBaseURL(url string) {
c.BaseURL = url
}
// SetEnvironment sets the environment
func SetEnvironment(env string) {
Environment = env
IsDevelopment = env == "development"
func (c *Config) SetEnvironment(env string) {
c.Environment = env
c.IsDevelopment = env == "development"
}
// SetClient sets the HTTP client
func SetClient(c http.Client) {
Client = c
}
// SetCookies sets the cookie jar
func SetCookies(cj http.CookieJar) {
Cookies = cj
func (c *Config) SetClient(client *http.Client) {
c.Client = client
}
// SetRedis sets the Redis client
func SetRedis(r *redis.Client) {
KV = r
func (c *Config) SetRedis(r *redis.Client) {
c.KV = r
}