forked from tigergraph/Restifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofile.go
More file actions
50 lines (47 loc) · 1.07 KB
/
profile.go
File metadata and controls
50 lines (47 loc) · 1.07 KB
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
package main
import (
"io/ioutil"
"net/http"
"github.com/Jeffail/gabs"
"github.com/gin-gonic/gin"
)
func profileHandler(c *gin.Context) {
r, _ := http.NewRequest("GET", "http://localhost:8123/gsql/simpleauth", nil)
r.Header.Set("authorization", c.Request.Header.Get("authorization"))
client := &http.Client{}
resp, err := client.Do(r)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, response{
Error: true,
Message: err.Error(),
})
return
}
if resp.StatusCode == http.StatusUnauthorized {
c.AbortWithStatusJSON(http.StatusBadRequest, response{
Error: true,
Message: "invalid username/password combination",
})
return
}
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, response{
Error: true,
Message: err.Error(),
})
return
}
jsonResp, err := gabs.ParseJSON(buf)
if err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, response{
Error: true,
Message: err.Error(),
})
return
}
c.JSON(200, response{
Error: err != nil,
Result: jsonResp.Data(),
})
}