File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed
Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ import (
1717func JSON (w http.ResponseWriter , code , indent int , v any ) error {
1818 // Set the default content type, write the header
1919 w .Header ().Set (types .ContentTypeHeader , types .ContentTypeJSON )
20+
21+ // Modify the status code if it is not already set
22+ if code == 0 {
23+ code = http .StatusInternalServerError
24+ }
25+
26+ // Write the status code
2027 w .WriteHeader (code )
2128
2229 // Create an encoder for the response
Original file line number Diff line number Diff line change 11package types
22
3- import "mime"
3+ import (
4+ "mime"
5+ )
46
57///////////////////////////////////////////////////////////////////////////////
68// GLOBALS
@@ -13,6 +15,7 @@ const (
1315 ContentTypeCSV = "text/csv"
1416 ContentTypeTextXml = "text/xml"
1517 ContentTypeTextPlain = "text/plain"
18+ ContentTypeFormData = "multipart/form-data"
1619 ContentTypeAny = "*/*"
1720)
1821
Original file line number Diff line number Diff line change @@ -20,6 +20,19 @@ func BoolPtr(v bool) *bool {
2020 return & v
2121}
2222
23+ // Int32Ptr returns a pointer to a int32
24+ func Int32Ptr (v int32 ) * int32 {
25+ return & v
26+ }
27+
28+ // PtrInt32 returns a int32 from a pointer
29+ func PtrInt32 (v * int32 ) int32 {
30+ if v == nil {
31+ return 0
32+ }
33+ return * v
34+ }
35+
2336// Uint64Ptr returns a pointer to a uint64
2437func Uint64Ptr (v uint64 ) * uint64 {
2538 return & v
@@ -33,6 +46,19 @@ func PtrUint64(v *uint64) uint64 {
3346 return * v
3447}
3548
49+ // Int64Ptr returns a pointer to a int64
50+ func Int64Ptr (v int64 ) * int64 {
51+ return & v
52+ }
53+
54+ // PtrInt64 returns a int64 from a pointer
55+ func PtrInt64 (v * int64 ) int64 {
56+ if v == nil {
57+ return 0
58+ }
59+ return * v
60+ }
61+
3662// PtrBool returns a bool from a pointer
3763func PtrBool (v * bool ) bool {
3864 if v == nil {
Original file line number Diff line number Diff line change 11package types
22
33import (
4+ "strconv"
45 "strings"
56 "unicode"
67)
@@ -53,3 +54,12 @@ func IsUppercase(s string) bool {
5354 }
5455 return true
5556}
57+
58+ // Unquote returns a string with the input string unquoted
59+ func Unquote (s string ) string {
60+ if str , err := strconv .Unquote (s ); err == nil {
61+ return str
62+ } else {
63+ return s
64+ }
65+ }
You can’t perform that action at this time.
0 commit comments