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() +}