-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
60 lines (52 loc) · 1.35 KB
/
main.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
/*
Test Service for Jive-SDK written in Go Lang
*/
package main
import (
"fmt"
"net/http"
"encoding/json"
"github.com/jivesoftware/jive-sdk-go-gpm"
)
var clientID string
var clientSecret string
/*
// Use this initializing function if clientID and clientSecret will be stored
// in a DB or file and passed in procedurally or any activities before runtime
func init {
// initialization code here
}
*/
func main (){
http.HandleFunc("/register", func(rw http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
data := jive_sdk.Payload{}
err := decoder.Decode(&data)
if err != nil {
fmt.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
}
statusCode := jive_sdk.IsValidRegistraton(data, clientSecret)
if statusCode{
rw.WriteHeader(http.StatusNoContent)
}else{
rw.WriteHeader(http.StatusForbidden)
}
})
http.HandleFunc("/unregister", func(rw http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body)
data := jive_sdk.Payload{}
err := decoder.Decode(&data)
if err != nil {
fmt.Println(err)
rw.WriteHeader(http.StatusInternalServerError)
}
statusCode := jive_sdk.IsValidRegistraton(data, clientSecret)
if statusCode{
rw.WriteHeader(http.StatusNoContent)
}else{
rw.WriteHeader(http.StatusForbidden)
}
})
http.ListenAndServe(":8090", nil)
}