mirror of
https://git.mills.io/saltyim/saltyim.git
synced 2024-07-03 00:33:38 +00:00
![James Mills](/assets/img/avatar_default.png)
Co-authored-by: James Mills <prologic@shortcircuit.net.au> Co-authored-by: Jon Lundy <jon@xuu.cc> Reviewed-on: https://git.mills.io/prologic/saltyim/pulls/36
41 lines
709 B
Go
41 lines
709 B
Go
package internal
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
"github.com/unrolled/render"
|
|
)
|
|
|
|
// API ...
|
|
type API struct {
|
|
router *Router
|
|
config *Config
|
|
db Store
|
|
|
|
r *render.Render
|
|
}
|
|
|
|
// NewAPI ...
|
|
func NewAPI(router *Router, config *Config, db Store) *API {
|
|
api := &API{router, config, db, render.New()}
|
|
|
|
api.initRoutes()
|
|
|
|
return api
|
|
}
|
|
|
|
func (a *API) initRoutes() {
|
|
router := a.router.Group("/api/v1")
|
|
|
|
router.GET("/ping", a.PingEndpoint())
|
|
}
|
|
|
|
// PingEndpoint ...
|
|
func (a *API) PingEndpoint() httprouter.Handle {
|
|
return func(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
_, _ = w.Write([]byte(`{}`))
|
|
}
|
|
}
|