forked from TF2Stadium/Helen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responseHelpers.go
37 lines (29 loc) · 855 Bytes
/
responseHelpers.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
package controllerhelpers
import (
"fmt"
"net/http"
"github.com/TF2Stadium/Helen/config"
"github.com/TF2Stadium/Helen/helpers"
"github.com/bitly/go-simplejson"
)
func SendJSON(w http.ResponseWriter, json *simplejson.Json) {
w.Header().Add("Content-Type", "application/json")
val, _ := json.String()
fmt.Fprintf(w, val)
}
func BuildSuccessJSON(data *simplejson.Json) *simplejson.Json {
j := simplejson.New()
j.Set("success", true)
j.Set("data", data)
return j
}
func BuildFailureJSON(message string, code int) *simplejson.Json {
e := helpers.NewTPError(message, code)
return e.ErrorJSON()
}
func BuildMissingArgJSON(arg string) *simplejson.Json {
return BuildFailureJSON(fmt.Sprintf("Missing argument: '%s'", arg), 0)
}
func RedirectHome(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, config.Constants.Domain, 303)
}