From 9f69390771dcd66c37e429e44d000d54a1b4c314 Mon Sep 17 00:00:00 2001 From: txx Date: Sun, 30 Jun 2019 03:54:48 +0800 Subject: [PATCH] feat(block_fetcher): Add telegram report and use env to handle secret key --- block_fetcher.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/block_fetcher.go b/block_fetcher.go index b5b7c19..e953969 100644 --- a/block_fetcher.go +++ b/block_fetcher.go @@ -2,6 +2,9 @@ package main import ( "fmt" + "net/http" + "net/url" + "os" "time" ) @@ -10,8 +13,16 @@ func haveARest() { } func main() { + botKey := os.Getenv("LIBRA_BOT_KEY") + botSecret := os.Getenv("LIBRA_BOT_SECRET") + chatId := os.Getenv("LIBRA_BOT_CHAT_ID") + dbURL := os.Getenv("LIBRA_MYSQL_URL") + + telegramURL := fmt.Sprintf("https://api.telegram.org/%s:%s/sendMessage?chat_id=%s&parse_mode=markdown&text=", botKey, botSecret, chatId) + fmt.Println(telegramURL) + rpc := NewLibraRPC(nil) - db := NewDataBaseAdapter("root:test@(127.0.0.1:32773)/libra") + db := NewDataBaseAdapter(dbURL) db.migration() @@ -20,6 +31,8 @@ func main() { for { if errCnt > 10 { fmt.Printf("Max Retry Times") + + _, _ = http.Get(telegramURL + url.QueryEscape("libra block fetcher failed 10 times")) break }