diff options
author | Corey Hulen <corey@hulen.com> | 2016-05-24 14:31:30 -0700 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-05-24 14:31:30 -0700 |
commit | 09863c0b80610f2f3a35cf3caa7c5b66a0c3878e (patch) | |
tree | dcce1b5c0fa62a9da2b25a99862af5ba30306901 /api/general.go | |
parent | 4ae7128ecb66cdddeb9d40a24970c6552814c18b (diff) | |
download | chat-09863c0b80610f2f3a35cf3caa7c5b66a0c3878e.tar.gz chat-09863c0b80610f2f3a35cf3caa7c5b66a0c3878e.tar.bz2 chat-09863c0b80610f2f3a35cf3caa7c5b66a0c3878e.zip |
Adding APIs to reload config, recycle db connections and ping server (#3096)
* Adding APIs to reload config, recycle db connections and ping server
* Fixing unit test
* Adding unit tests
Diffstat (limited to 'api/general.go')
-rw-r--r-- | api/general.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/api/general.go b/api/general.go new file mode 100644 index 000000000..0adc36d9f --- /dev/null +++ b/api/general.go @@ -0,0 +1,56 @@ +// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package api + +import ( + "fmt" + "net/http" + + l4g "github.com/alecthomas/log4go" + + "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" +) + +func InitGeneral() { + l4g.Debug(utils.T("api.general.init.debug")) + + BaseRoutes.General.Handle("/client_props", ApiAppHandler(getClientConfig)).Methods("GET") + BaseRoutes.General.Handle("/log_client", ApiAppHandler(logClient)).Methods("POST") + BaseRoutes.General.Handle("/ping", ApiAppHandler(ping)).Methods("GET") + +} + +func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) { + w.Write([]byte(model.MapToJson(utils.ClientCfg))) +} + +func logClient(c *Context, w http.ResponseWriter, r *http.Request) { + m := model.MapFromJson(r.Body) + + lvl := m["level"] + msg := m["message"] + + if len(msg) > 400 { + msg = msg[0:399] + } + + if lvl == "ERROR" { + err := &model.AppError{} + err.Message = msg + err.Id = msg + err.Where = "client" + c.LogError(err) + } + + ReturnStatusOK(w) +} + +func ping(c *Context, w http.ResponseWriter, r *http.Request) { + m := make(map[string]string) + m["version"] = model.CurrentVersion + m["server_time"] = fmt.Sprintf("%v", model.GetMillis()) + m["node_id"] = "" + w.Write([]byte(model.MapToJson(m))) +} |