mirror of
https://github.com/Xevion/banner.git
synced 2025-12-14 22:11:04 -06:00
fix: proper configuration handling across submodules
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user