Add APIv4 /system/ping endpoint (#5443)
Этот коммит содержится в:
коммит произвёл
George Goldberg
родитель
eadf37ad7a
Коммит
48b785aded
@@ -143,6 +143,7 @@ func InitApi(full bool) {
|
|||||||
InitTeam()
|
InitTeam()
|
||||||
InitChannel()
|
InitChannel()
|
||||||
InitPost()
|
InitPost()
|
||||||
|
InitSystem()
|
||||||
|
|
||||||
app.Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
|
app.Srv.Router.Handle("/api/v4/{anything:.*}", http.HandlerFunc(Handle404))
|
||||||
|
|
||||||
|
|||||||
21
api4/system.go
Обычный файл
21
api4/system.go
Обычный файл
@@ -0,0 +1,21 @@
|
|||||||
|
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See License.txt for license information.
|
||||||
|
|
||||||
|
package api4
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
l4g "github.com/alecthomas/log4go"
|
||||||
|
"github.com/mattermost/platform/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
func InitSystem() {
|
||||||
|
l4g.Debug(utils.T("api.system.init.debug"))
|
||||||
|
|
||||||
|
BaseRoutes.System.Handle("/ping", ApiHandler(getSystemPing)).Methods("GET")
|
||||||
|
}
|
||||||
|
|
||||||
|
func getSystemPing(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
ReturnStatusOK(w)
|
||||||
|
}
|
||||||
18
api4/system_test.go
Обычный файл
18
api4/system_test.go
Обычный файл
@@ -0,0 +1,18 @@
|
|||||||
|
package api4
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetPing(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer TearDown()
|
||||||
|
Client := th.Client
|
||||||
|
|
||||||
|
b, _ := Client.GetPing()
|
||||||
|
if b == false {
|
||||||
|
t.Fatal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -112,6 +112,10 @@ func (c *Client4) GetPostRoute(postId string) string {
|
|||||||
return fmt.Sprintf(c.GetPostsRoute()+"/%v", postId)
|
return fmt.Sprintf(c.GetPostsRoute()+"/%v", postId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) GetSystemRoute() string {
|
||||||
|
return fmt.Sprintf("/system")
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
|
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
|
||||||
return c.DoApiRequest(http.MethodGet, url, "", etag)
|
return c.DoApiRequest(http.MethodGet, url, "", etag)
|
||||||
}
|
}
|
||||||
@@ -570,5 +574,14 @@ func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client4) GetPing() (bool, *Response) {
|
||||||
|
if r, err := c.DoApiGet(c.GetSystemRoute()+"/ping", ""); err != nil {
|
||||||
|
return false, &Response{StatusCode: r.StatusCode, Error: err}
|
||||||
|
} else {
|
||||||
|
defer closeBody(r)
|
||||||
|
return CheckStatusOK(r), BuildResponse(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Files Section
|
// Files Section
|
||||||
// to be filled in..
|
// to be filled in..
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user