48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package serverimp
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
msg "github.com/tech/sendico/pkg/messaging"
|
|
"github.com/tech/sendico/pkg/server/grpcapp"
|
|
"go.uber.org/zap"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
const defaultMetricsAddress = ":9405"
|
|
|
|
type config struct {
|
|
Runtime *grpcapp.RuntimeConfig `yaml:"runtime"`
|
|
Messaging *msg.Config `yaml:"messaging"`
|
|
Metrics *metricsConfig `yaml:"metrics"`
|
|
}
|
|
|
|
type metricsConfig struct {
|
|
Address string `yaml:"address"`
|
|
}
|
|
|
|
func (i *Imp) loadConfig() (*config, error) {
|
|
data, err := os.ReadFile(i.file)
|
|
if err != nil {
|
|
i.logger.Error("Could not read configuration file", zap.String("config_file", i.file), zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
cfg := &config{}
|
|
if err := yaml.Unmarshal(data, cfg); err != nil {
|
|
i.logger.Error("Failed to parse configuration", zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
if cfg.Runtime == nil {
|
|
cfg.Runtime = &grpcapp.RuntimeConfig{ShutdownTimeoutSeconds: 15}
|
|
}
|
|
|
|
if cfg.Metrics != nil && strings.TrimSpace(cfg.Metrics.Address) == "" {
|
|
cfg.Metrics.Address = defaultMetricsAddress
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|