Skip to content

Commit 5610992

Browse files
authored
Merge pull request #82 from mutablelogic/v5
Added necessary functions
2 parents 0ff490f + 97b0bf6 commit 5610992

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

pkg/httpresponse/json.go

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ import (
1717
func 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

pkg/types/mime.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package 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

pkg/types/ptr.go

+26
Original file line numberDiff line numberDiff 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
2437
func 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
3763
func PtrBool(v *bool) bool {
3864
if v == nil {

pkg/types/string.go

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
import (
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+
}

0 commit comments

Comments
 (0)