diff options
author | Wim <wim@42.be> | 2016-05-15 23:02:30 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-05-15 23:02:30 +0200 |
commit | 59e6abcc11ed3a3548ffb02d1e455485672d8308 (patch) | |
tree | a5086741b8595d7eb33a0f41e7c109d064be33ef /vendor/github.com/mattermost/platform/model/utils.go | |
parent | 38e3bbe5c96eb84f3e223c44f801ee7e3308b2c1 (diff) | |
download | matterbridge-msglm-59e6abcc11ed3a3548ffb02d1e455485672d8308.tar.gz matterbridge-msglm-59e6abcc11ed3a3548ffb02d1e455485672d8308.tar.bz2 matterbridge-msglm-59e6abcc11ed3a3548ffb02d1e455485672d8308.zip |
Sync with mattermost 3.0
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 +} |