diff options
Diffstat (limited to 'vendor/github.com/mattermost/platform/model/utils.go')
-rw-r--r-- | vendor/github.com/mattermost/platform/model/utils.go | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/vendor/github.com/mattermost/platform/model/utils.go b/vendor/github.com/mattermost/platform/model/utils.go index 808c89e3..443a34bc 100644 --- a/vendor/github.com/mattermost/platform/model/utils.go +++ b/vendor/github.com/mattermost/platform/model/utils.go @@ -41,12 +41,18 @@ func (er *AppError) Error() string { } func (er *AppError) Translate(T goi18n.TranslateFunc) { - if len(er.Message) == 0 { - if er.params == nil { - er.Message = T(er.Id) - } else { - er.Message = T(er.Id, er.params) - } + if er.params == nil { + er.Message = T(er.Id) + } else { + er.Message = T(er.Id, er.params) + } +} + +func (er *AppError) SystemMessage(T goi18n.TranslateFunc) string { + if er.params == nil { + return T(er.Id) + } else { + return T(er.Id, er.params) } } @@ -75,6 +81,7 @@ func NewLocAppError(where string, id string, params map[string]interface{}, deta ap := &AppError{} ap.Id = id ap.params = params + ap.Message = id ap.Where = where ap.DetailedError = details ap.StatusCode = 500 @@ -171,6 +178,26 @@ func StringInterfaceFromJson(data io.Reader) map[string]interface{} { } } +func StringToJson(s string) string { + b, err := json.Marshal(s) + if err != nil { + return "" + } else { + return string(b) + } +} + +func StringFromJson(data io.Reader) string { + decoder := json.NewDecoder(data) + + var s string + if err := decoder.Decode(&s); err != nil { + return "" + } else { + return s + } +} + func IsLower(s string) bool { if strings.ToLower(s) == s { return true @@ -367,3 +394,29 @@ func IsValidHttpUrl(rawUrl string) bool { return true } + +func IsValidHttpsUrl(rawUrl string) bool { + if strings.Index(rawUrl, "https://") != 0 { + return false + } + + if _, err := url.ParseRequestURI(rawUrl); err != nil { + return false + } + + return true +} + +func IsSafeLink(link *string) bool { + if link != nil { + if IsValidHttpUrl(*link) { + return true + } else if strings.HasPrefix(*link, "/") { + return true + } else { + return false + } + } + + return true +} |