2021-04-15 03:42:24 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-chi/chi"
|
|
|
|
"github.com/go-chi/render"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2021-04-15 04:41:06 +00:00
|
|
|
func New() *API {
|
2021-04-15 03:42:24 +00:00
|
|
|
r := chi.NewRouter()
|
|
|
|
|
|
|
|
r.Use(render.SetContentType(render.ContentTypeJSON))
|
|
|
|
|
2021-04-15 04:41:06 +00:00
|
|
|
return &API{router: r}
|
|
|
|
}
|
2021-04-15 03:42:24 +00:00
|
|
|
|
2021-04-15 04:41:06 +00:00
|
|
|
type API struct {
|
|
|
|
router chi.Router
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) Router() chi.Router {
|
|
|
|
return a.router
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *API) Start() error {
|
|
|
|
return http.ListenAndServe(":8080", a.router)
|
2021-04-15 03:42:24 +00:00
|
|
|
}
|