This repository has been archived on 2024-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
orion/cmd/server/route.go

38 lines
980 B
Go
Raw Normal View History

2018-12-06 22:12:32 +01:00
package main
import (
"net/http"
2019-02-12 10:17:06 +01:00
"forge.cadoles.com/wpetit/goweb/middleware/container"
2018-12-06 22:12:32 +01:00
"forge.cadoles.com/wpetit/goweb/service/template"
2019-02-12 10:17:06 +01:00
"forge.cadoles.com/wpetit/goweb/static"
"github.com/go-chi/chi"
2018-12-06 22:12:32 +01:00
"forge.cadoles.com/Pyxis/orion/cmd/server/jsonrpc"
)
2019-02-12 10:17:06 +01:00
func configureRoutes(r *chi.Mux) {
r.Get("/", serveHomepage)
r.Get("/modules", serveModulesList)
r.Post("/rpc", handleJSONRPC)
r.Get("/**", static.Dir(conf.AssetDir, "", r.NotFoundHandler()))
}
2018-12-06 22:12:32 +01:00
func serveHomepage(w http.ResponseWriter, r *http.Request) {
2019-02-12 10:17:06 +01:00
http.Redirect(w, r, "/modules", http.StatusFound)
}
func serveModulesList(w http.ResponseWriter, r *http.Request) {
ctn := container.Must(r.Context())
templateService := template.Must(ctn)
if err := templateService.RenderPage(w, "modules_list.html.tmpl", nil); err != nil {
2018-12-06 22:12:32 +01:00
panic(err)
}
}
func handleJSONRPC(w http.ResponseWriter, r *http.Request) {
2019-02-12 10:17:06 +01:00
ctn := container.Must(r.Context())
rpcServer := jsonrpc.Must(ctn)
2018-12-06 22:12:32 +01:00
rpcServer.ServeHTTP(w, r)
}