mirror of
https://github.com/nxshock/trayweather.git
synced 2025-07-02 00:23:43 +05:00
Code upload
This commit is contained in:
parent
2880e52a08
commit
b146c2bc76
18 changed files with 215 additions and 0 deletions
38
config.go
Normal file
38
config.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/ilyakaznacheev/cleanenv"
|
||||
"github.com/ncruces/zenity"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
CityName string `toml:"CityName" env:"CITY_NAME"`
|
||||
UpdatePeriod time.Duration `toml:"UpdatePeriod", env:"UPDATE_PERIOD"`
|
||||
}
|
||||
|
||||
var config Config
|
||||
|
||||
func init() {
|
||||
log.SetFlags(0)
|
||||
|
||||
err := cleanenv.ReadConfig("config.toml", &config)
|
||||
if err != nil {
|
||||
zenity.Notify("Ошибка при чтении настроек из файла config.toml:\n" + err.Error())
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if config.CityName == "" {
|
||||
zenity.Notify("Город (поле CityName) не может быть пустым.")
|
||||
log.Fatalln("Город (поле CityName) не может быть пустым.")
|
||||
}
|
||||
|
||||
log.Println(config.UpdatePeriod)
|
||||
|
||||
if config.UpdatePeriod < time.Minute {
|
||||
log.Printf("Частота обновлений слишком низкая (%s), будет установлено значение в одну минуту.")
|
||||
config.UpdatePeriod = time.Minute
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue