Skip to content

Commit

Permalink
추후 SendImage 함수 추가를 위해 Send를 SendText로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
juunini committed Aug 19, 2020
1 parent c0aeb9d commit 501b4bb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# simple go line notify

[![GoDoc](https://godoc.org/github.com/juunini/simple-go-line-notify/notify?status.svg)](https://godoc.org/github.com/juunini/simple-go-line-notify/notify)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/juunini/simple-go-line-notify/notify)](https://pkg.go.dev/github.com/juunini/simple-go-line-notify/notify)
[![Build Status](https://travis-ci.org/juunini/simple-go-line-notify.svg?branch=master)](https://travis-ci.org/juunini/simple-go-line-notify)
[![Go Report Card](https://goreportcard.com/badge/github.com/juunini/simple-go-line-notify)](https://goreportcard.com/report/github.com/juunini/simple-go-line-notify)

Expand All @@ -15,7 +15,7 @@ func main() {
bearer := "29jWoO****p70eK3AKA********ooHfusvDP6***ZmR"
message := "hello, world!"

if err := notify.Send(bearer, message); err != nil {
if err := notify.SendText(bearer, message); err != nil {
panic(err)
}
}
Expand Down
11 changes: 8 additions & 3 deletions notify/send.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// Use Line Notify REST API
//
// See Also
//
// https://engineering.linecorp.com/en/blog/using-line-notify-to-send-messages-to-line-from-the-command-line/
package notify

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"strings"
)

func Send(Bearer, message string) (err error) {
// SendText : send line notify simple text
func SendText(Bearer, message string) (err error) {
req, err := http.NewRequest("POST", "https://notify-api.line.me/api/notify", strings.NewReader(url.Values{"message": []string{message}}.Encode()))
if err != nil {
return
Expand Down Expand Up @@ -39,7 +44,7 @@ func Send(Bearer, message string) (err error) {
defer res.Body.Close()

if body.Status != 200 {
err = errors.New(fmt.Sprintf("%d: %s", body.Status, body.Message))
err = fmt.Errorf("%d: %s", body.Status, body.Message)
}
return
}
12 changes: 12 additions & 0 deletions notify/send_examples_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package notify_test

import "github.com/juunini/simple-go-line-notify/notify"

func ExampleSendText() {
bearer := "29jWoO****p70eK3AKA********ooHfusvDP6***ZmR"
message := "hello, world!"

if err := notify.SendText(bearer, message); err != nil {
panic(err)
}
}

0 comments on commit 501b4bb

Please sign in to comment.