Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
チャットワークのメッセージをRedisに突っ込むやつ
package main
import (
"encoding/json"
"github.com/garyburd/redigo/redis"
"io/ioutil"
"log"
"net/http"
)
type accountData struct {
AccountID int64 `json:"account_id"`
Name string `json:"name"`
AvatarImageUrl string `json:"avatar_image_url"`
}
type messageData struct {
MessageId int64 `json:"message_id"`
Accont accountData `json:"account"`
Body string `json:"body"`
SendTime int64 `json:"send_time"`
UpdateTime int64 `json:"update_time"`
}
type JsonData struct {
Message []messageData
}
func main() {
req, _ := http.NewRequest("GET", "https://api.chatwork.com/v1/rooms/room_id/messages", nil)
req.Header.Set("X-ChatWorkToken", "token")
client := new(http.Client)
resp, _ := client.Do(req)
defer resp.Body.Close()
byteArray, _ := ioutil.ReadAll(resp.Body)
if string(byteArray) == "" {
log.Fatal("Empty!")
}
messageKey := make([]messageData, 0)
err := json.Unmarshal(byteArray, &messageKey)
if err != nil {
log.Fatal(err)
}
conn, _ := redis.Dial("tcp", "redis_Server")
defer conn.Close()
for _, value := range messageKey {
log.Println(value.MessageId)
b, _ := json.Marshal(value)
conn.Do("SET", value.MessageId, b)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment