func init() { // read variables from config file if conf, err := lib.GetConfig(); err == nil { apiToken = conf.ApiToken localPort = conf.LocalPort availableIds = conf.AvailableIds pHatBrightness = conf.PHatBrightness pHatScrollDelay = conf.PHatScrollDelay pHatRotateOrNot = conf.PHatRotate180Degrees telegramMonitorInterval = conf.TelegramMonitorInterval isVerbose = conf.IsVerbose // all keyboard buttons allKeyboards = [][]bot.KeyboardButton{ []bot.KeyboardButton{ bot.KeyboardButton{ Text: "/" + lib.CommandTime, }, bot.KeyboardButton{ Text: "/" + lib.CommandIP, }, bot.KeyboardButton{ Text: "/" + lib.CommandHelp, }, }, } // initialize other variables queue = make(chan string, QueueSize) } else { panic(err.Error()) } }
func main() { args := os.Args[1:] if len(args) > 0 { // read variables from config file if conf, err := lib.GetConfig(); err == nil { localPort := conf.LocalPort flag.Parse() var cmd, val string if showTime { cmd, val = lib.CommandTime, "" } else if showIp { cmd, val = lib.CommandIP, "" } else { cmd, val = "", strings.Join(args, " ") } if _, err := http.PostForm(fmt.Sprintf("http://localhost:%d", localPort), url.Values{ lib.ParamCommand: {cmd}, lib.ParamValue: {val}, }); err != nil { fmt.Println(fmt.Errorf("*** %s", err)) } } else { fmt.Println(fmt.Errorf("*** %s", err)) } } else { printUsage() } }