public-ip-tracker/tracker/config/config.go

29 lines
572 B
Go
Raw Normal View History

package config
import (
"encoding/json"
"fmt"
"os"
)
type TelegramConfig struct {
ChannelID int64 `json:"channel_id"`
Token string `json:"token"`
}
type Config struct {
Telegram *TelegramConfig `json:"telegram"`
}
func New(filepath string) (*Config, error) {
content, err := os.ReadFile(filepath)
if err != nil {
return nil, fmt.Errorf("failed to read config file %q: %w", filepath, err)
}
var conf Config
if err := json.Unmarshal(content, &conf); err != nil {
return nil, fmt.Errorf("failed to parse config file: %w", err)
}
return &conf, nil
}