File tree 4 files changed +47
-1
lines changed
4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,13 @@ import (
17
17
func JSON (w http.ResponseWriter , code , indent int , v any ) error {
18
18
// Set the default content type, write the header
19
19
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
20
27
w .WriteHeader (code )
21
28
22
29
// Create an encoder for the response
Original file line number Diff line number Diff line change 1
1
package types
2
2
3
- import "mime"
3
+ import (
4
+ "mime"
5
+ )
4
6
5
7
///////////////////////////////////////////////////////////////////////////////
6
8
// GLOBALS
@@ -13,6 +15,7 @@ const (
13
15
ContentTypeCSV = "text/csv"
14
16
ContentTypeTextXml = "text/xml"
15
17
ContentTypeTextPlain = "text/plain"
18
+ ContentTypeFormData = "multipart/form-data"
16
19
ContentTypeAny = "*/*"
17
20
)
18
21
Original file line number Diff line number Diff line change @@ -20,6 +20,19 @@ func BoolPtr(v bool) *bool {
20
20
return & v
21
21
}
22
22
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
+
23
36
// Uint64Ptr returns a pointer to a uint64
24
37
func Uint64Ptr (v uint64 ) * uint64 {
25
38
return & v
@@ -33,6 +46,19 @@ func PtrUint64(v *uint64) uint64 {
33
46
return * v
34
47
}
35
48
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
+
36
62
// PtrBool returns a bool from a pointer
37
63
func PtrBool (v * bool ) bool {
38
64
if v == nil {
Original file line number Diff line number Diff line change 1
1
package types
2
2
3
3
import (
4
+ "strconv"
4
5
"strings"
5
6
"unicode"
6
7
)
@@ -53,3 +54,12 @@ func IsUppercase(s string) bool {
53
54
}
54
55
return true
55
56
}
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