diff --git a/msgr.go b/msgr.go index f849680..105be08 100644 --- a/msgr.go +++ b/msgr.go @@ -35,10 +35,12 @@ func msgrPostHandler(w http.ResponseWriter, req *http.Request, chs []MessageChan channel := req.FormValue("channel") msg := req.FormValue("msg") if channel == "" || msg == "" || req.Method != "POST" { + log.Printf("[warn] invalid request: method=%s channel=%s, msg=%s", req.Method, channel, msg) code := http.StatusBadRequest http.Error(w, http.StatusText(code), code) return } + log.Printf("[debug] post to channel=%s, msg=%s", channel, msg) for _, ch := range chs { ch.PostMsgr(req) } diff --git a/nopaste.go b/nopaste.go index d7bad5f..ae6b33f 100644 --- a/nopaste.go +++ b/nopaste.go @@ -20,6 +20,8 @@ const Root = "/np" var config *Config +var Debug = false + type nopasteContent struct { Text string Channel string @@ -125,6 +127,7 @@ func serveHandler(w http.ResponseWriter, req *http.Request, chs []MessageChan) { func saveContent(np nopasteContent, chs []MessageChan) (string, int) { if np.Text == "" { + log.Println("[warn] empty text") return Root, http.StatusFound } data := []byte(np.Text) diff --git a/slack.go b/slack.go index 3785d22..e28a8f6 100644 --- a/slack.go +++ b/slack.go @@ -3,7 +3,7 @@ package nopaste import ( "encoding/json" "fmt" - "io/ioutil" + "io" "log" "math" "net/http" @@ -47,6 +47,7 @@ func (ch SlackMessageChan) PostNopaste(np nopasteContent, url string) { IconURL: np.IconURL, LinkNames: np.LinkNames, } + log.Printf("[debug] post to slack: %#v", msg) select { case ch <- msg: default: @@ -70,6 +71,7 @@ func (ch SlackMessageChan) PostMsgr(req *http.Request) { if _notice := req.FormValue("notice"); _notice == "0" { msg.LinkNames = 1 } + log.Printf("[debug] post to slack: %#v", msg) select { case ch <- msg: default: @@ -95,7 +97,7 @@ func (a *SlackAgent) Post(m SlackMessage) error { if resp.StatusCode == http.StatusOK { return nil } - if body, err := ioutil.ReadAll(resp.Body); err == nil { + if body, err := io.ReadAll(resp.Body); err == nil { return fmt.Errorf("failed post to slack:%s", body) } else { return err