Version 0.0.1

main
Muhammad Daffa 2021-09-13 16:54:23 +07:00 committed by GitHub
parent f3ed98e46f
commit c6985d3191
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module notifier
go 1.16

41
main.go Normal file
View File

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