26 lines
512 B
Go
26 lines
512 B
Go
package application
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/sethvargo/go-envconfig"
|
|
)
|
|
|
|
type Config struct {
|
|
Debug bool `env:"DEBUG"`
|
|
DiscoveryPort uint16 `env:"DISCOVERY_PORT,default=4321"`
|
|
BroadcastInterval time.Duration `env:"BROADCAST_INTERVAL,default=5s"`
|
|
}
|
|
|
|
func NewConfig(ctx context.Context) (Config, error) {
|
|
cfg := Config{}
|
|
|
|
if err := envconfig.Process(ctx, &cfg); err != nil {
|
|
return Config{}, fmt.Errorf("process envs: %w", err)
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|