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

34 lines
815 B
Go
Raw Normal View History

2018-12-06 22:12:32 +01:00
package main
import (
"net/http"
"forge.cadoles.com/wpetit/goweb/middleware"
"forge.cadoles.com/wpetit/goweb/service"
"forge.cadoles.com/wpetit/goweb/service/template"
"forge.cadoles.com/Pyxis/orion/cmd/server/jsonrpc"
)
func serveHomepage(w http.ResponseWriter, r *http.Request) {
container := getServiceContainer(r)
templateService := template.Must(container)
if err := templateService.RenderPage(w, "home.html.tmpl", nil); err != nil {
panic(err)
}
}
func handleJSONRPC(w http.ResponseWriter, r *http.Request) {
container := getServiceContainer(r)
rpcServer := jsonrpc.Must(container)
rpcServer.ServeHTTP(w, r)
}
func getServiceContainer(r *http.Request) *service.Container {
container, err := middleware.GetServiceContainer(r.Context())
if err != nil {
panic(err)
}
return container
}