public-ip-tracker/tracker/config/config.go
Melora Hugues 54de3b84cd
All checks were successful
continuous-integration/drone/push Build is passing
Add link to Telegram
Ref #2

This commit adds a link to a Go Telegram API to send messages to a given
telegram channel provided with a JSON config file. At the moment the
program sends a simple status message to the bot when starting up, but
this allows testing whether the link to Telegram is correctly working.
2023-01-25 20:42:43 +01:00

28 lines
572 B
Go

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
}