From c6985d3191c18c350093b6a498eb54f703e254a8 Mon Sep 17 00:00:00 2001 From: Muhammad Daffa <36522826+daffainfo@users.noreply.github.com> Date: Mon, 13 Sep 2021 16:54:23 +0700 Subject: [PATCH] Version 0.0.1 --- go.mod | 3 +++ main.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 go.mod create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..b9461ed --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module notifier + +go 1.16 diff --git a/main.go b/main.go new file mode 100644 index 0000000..a3c56ac --- /dev/null +++ b/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "bufio" + "log" + "net/http" + "net/url" + "os" + "strings" +) + +var apikey = "xxxxx" + +func curl_line() { + s := bufio.NewScanner(os.Stdin) + if s.Err() != nil { + log.Fatal(s.Err()) + } + for s.Scan() { + params := url.Values{} + params.Add("message", s.Text()) + body := strings.NewReader(params.Encode()) + req, err := http.NewRequest("POST", "https://notify-api.line.me/api/notify", body) + if err != nil { + log.Fatal(err) + } + req.Header.Set("Authorization", "Bearer "+apikey) + req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + + resp, err := http.DefaultClient.Do(req) + if err != nil { + log.Fatal(err) + } + defer resp.Body.Close() + } + +} + +func main() { + curl_line() +}