-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_jwt_s3zip_results.go
49 lines (44 loc) · 1.25 KB
/
api_jwt_s3zip_results.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
package main
import (
"github.com/labstack/echo"
"net/http"
"io/ioutil"
"log"
"strings"
"github.com/labstack/echo-contrib/session"
)
func s3JwtResult(c echo.Context) (err error){
/**************** GET TOKEN FROM COOKIE ***************************/
cookie, err := c.Cookie("newJwtToken")
if err != nil {
return err
}
var bearer = "Bearer " + cookie.Value
/**************** GET UUIDS FROM SESSION ***************************/
sess, _ := session.Get("session", c)
allBodyUUIDs := sess.Values["allBodyUUIDs"]
/**************** ACCESS API WITH TOKEN ***************************/
client := &http.Client{}
// create new request with allbody set
//allbody contains uuids
req2 , err2:= http.NewRequest("POST", "https://api.s3zipper.com/v1/zipresult", strings.NewReader(allBodyUUIDs.(string)))
if err2 != nil {
log.Fatal("NewRequest: ", err2)
return err2
}
req2.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req2.Header.Set("Authorization", bearer)
// get response
resp3 ,err3 := client.Do(req2)
if err3 != nil{
log.Fatal("NewRequest: ", err3)
return err3
}
defer resp3.Body.Close()
// read body
body2, err4:= ioutil.ReadAll(resp3.Body)
if err4 != nil{
return err4
}
return c.String(http.StatusOK, string(body2[:]))
}