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.
2018-09-17 14:17:54 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2018-09-24 08:49:21 +02:00
|
|
|
"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 (
|
2018-09-24 08:49:21 +02:00
|
|
|
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)
|
|
|
|
|
2018-09-24 08:49:21 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-09-24 08:49:21 +02:00
|
|
|
|
|
|
|
func handleRPC(w http.ResponseWriter, r *http.Request) {
|
|
|
|
jsonrpc.ServeHTTP(w, r)
|
|
|
|
}
|