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/main.go

45 lines
750 B
Go
Raw Normal View History

2018-09-17 14:17:54 +02:00
package main
import (
"fmt"
"log"
"net/http"
"forge.cadoles.com/Pyxis/orion/cmd/server/rpc"
2018-09-17 14:17:54 +02:00
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
)
var (
conf = newDefaultConfig()
jsonrpc = rpc.NewServer()
2018-09-17 14:17:54 +02:00
)
func main() {
if err := overwriteFromEnv(conf); err != nil {
log.Fatal(err)
}
r := chi.NewRouter()
r.Use(middleware.Recoverer)
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
r.Post("/rpc", handleRPC)
2018-09-17 14:17:54 +02:00
hostStr := fmt.Sprintf("%s:%s", conf.HTTPHost, conf.HTTPPort)
log.Printf("listening on http://%s", hostStr)
if err := http.ListenAndServe(hostStr, r); err != nil {
log.Fatal(err)
}
}
func handleRPC(w http.ResponseWriter, r *http.Request) {
jsonrpc.ServeHTTP(w, r)
}