diff options
Diffstat (limited to 'model/utils.go')
-rw-r--r-- | model/utils.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/model/utils.go b/model/utils.go index 681ade870..6d6eb452d 100644 --- a/model/utils.go +++ b/model/utils.go @@ -17,6 +17,7 @@ import ( "time" ) +type StringInterface map[string]interface{} type StringMap map[string]string type StringArray []string type EncryptStringMap map[string]string @@ -125,6 +126,25 @@ func ArrayFromJson(data io.Reader) []string { } } +func StringInterfaceToJson(objmap map[string]interface{}) string { + if b, err := json.Marshal(objmap); err != nil { + return "" + } else { + return string(b) + } +} + +func StringInterfaceFromJson(data io.Reader) map[string]interface{} { + decoder := json.NewDecoder(data) + + var objmap map[string]interface{} + if err := decoder.Decode(&objmap); err != nil { + return make(map[string]interface{}) + } else { + return objmap + } +} + func IsLower(s string) bool { if strings.ToLower(s) == s { return true @@ -242,8 +262,8 @@ func Etag(parts ...interface{}) string { } var validHashtag = regexp.MustCompile(`^(#[A-Za-z]+[A-Za-z0-9_\-]*[A-Za-z0-9])$`) -var puncStart = regexp.MustCompile(`^[.,()&$!\[\]{}"':;\\]+`) -var puncEnd = regexp.MustCompile(`[.,()&$#!\[\]{}"';\\]+$`) +var puncStart = regexp.MustCompile(`^[.,()&$!\[\]{}':;\\]+`) +var puncEnd = regexp.MustCompile(`[.,()&$#!\[\]{}';\\]+$`) func ParseHashtags(text string) (string, string) { words := strings.Fields(text) |