-
Notifications
You must be signed in to change notification settings - Fork 0
/
agirun.go
42 lines (34 loc) · 1023 Bytes
/
agirun.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
package main
import (
"errors"
"io/ioutil"
"log"
"net/http"
)
func getUsername(w http.ResponseWriter, r *http.Request) string {
username, _ := handler.GetUserInfoFromRequest(w, r)
return username
}
func resolveVirtalPath(w http.ResponseWriter, r *http.Request, vpath string) (string, error) {
return runAGIContent(w, r, `sendResp(decodeAbsoluteVirtualPath("`+vpath+`"));`)
}
func runAGIContent(w http.ResponseWriter, r *http.Request, script string) (string, error) {
//Get username and token from request
_, token := handler.GetUserInfoFromRequest(w, r)
//Execute the AGI request on server side
resp, err := handler.RequestGatewayInterface(token, script)
if err != nil {
//Something went wrong when performing POST request
log.Println(err)
} else {
//Try to read the resp body
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
resp.Body.Close()
//Return the body content
return string(bodyBytes), nil
}
return "", errors.New("Unknown error occured")
}