Skip to content

Instantly share code, notes, and snippets.

@conoro
Last active January 24, 2016 19:45
Show Gist options
  • Save conoro/3247950717d04d0d3f45 to your computer and use it in GitHub Desktop.
Save conoro/3247950717d04d0d3f45 to your computer and use it in GitHub Desktop.
An RSS feed subscription tool for Mattermost. Barely started. Does not work yet.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/SlyMarbo/rss"
)
type configuration struct {
MattermostURL string
}
func main() {
file, _ := os.Open("conf.json")
decoder := json.NewDecoder(file)
configuration := configuration{}
err := decoder.Decode(&configuration)
if err != nil {
fmt.Println("config error:", err)
}
fmt.Println(configuration.MattermostURL)
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
feedCmd := req.PostFormValue("text")
channelID := req.PostFormValue("channel_id")
teamDomain := req.PostFormValue("team_domain")
teamID := req.PostFormValue("team_id")
userID := req.PostFormValue("user_id")
fmt.Println(feedCmd)
fmt.Println(channelID)
fmt.Println(teamDomain)
fmt.Println(teamID)
fmt.Println(userID)
fmt.Fprintf(w, "{ \"text\": \"Thanks. Subscribed!\"}")
feed, error := rss.Fetch("http://laughingsquid.com/feed/")
if error != nil {
panic(error)
}
fmt.Println(feed)
var jsonStr = []byte(`{"channel":"@conor2", "text": "Direct Message from Golang"}`)
req, err := http.NewRequest("POST", configuration.MattermostURL, bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status)
fmt.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))
})
log.Fatal(http.ListenAndServe(":8333", nil))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment