-
Notifications
You must be signed in to change notification settings - Fork 7
/
rest-api.go
61 lines (52 loc) · 1.5 KB
/
rest-api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"encoding/json"
"log"
"net/http"
"time"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/test", Test)
router.HandleFunc("/hola/{name}", Hola)
log.Fatal(http.ListenAndServe(":8080", router))
}
func Test(w http.ResponseWriter, r *http.Request) {
response := HipChatResponse{Color: "yellow", Message: "This is a Test", Notify: "false", MessageFormat: "text"}
json.NewEncoder(w).Encode(response)
}
func Hola(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
response := HipChatResponse{Color: "yellow", Message: "Hola " + name, Notify: "false", MessageFormat: "text"}
json.NewEncoder(w).Encode(response)
}
type HipChatResponse struct {
Color string `json:"color"`
Message string `json:"message"`
Notify string `json:"notify"`
MessageFormat string `json:"message_format"`
}
type HipChatrequest struct {
Event string `json:"event"`
Item struct {
Message struct {
Date time.Time `json:"date"`
From struct {
ID int `json:"id"`
MentionName string `json:"mention_name"`
Name string `json:"name"`
} `json:"from"`
ID string `json:"id"`
Mentions []interface{} `json:"mentions"`
Message string `json:"message"`
Type string `json:"type"`
} `json:"message"`
Room struct {
ID int `json:"id"`
Name string `json:"name"`
} `json:"room"`
} `json:"item"`
WebhookID int `json:"webhook_id"`
}