34 lines
815 B
Go
34 lines
815 B
Go
|
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
|
||
|
}
|