6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-07-03 00:33:38 +00:00
prologic-saltyim/internal/api.go
James Mills be4b4a5e9d Add a basic structure for a go-app PWA + integrated Broker (#36)
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
2022-03-21 22:27:35 +00:00

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(`{}`))
}
}