NewServer creates a new Server instance.
(store *Store)
| 62 | |
| 63 | // NewServer creates a new Server instance. |
| 64 | func NewServer(store *Store) *Server { |
| 65 | ctx, cancel := context.WithCancel(context.Background()) |
| 66 | s := &Server{ |
| 67 | store: store, |
| 68 | SocketPerms: 0600, |
| 69 | ctx: ctx, |
| 70 | cancel: cancel, |
| 71 | logger: slog.Default().With(LogKeySystem, LogSystemServer), |
| 72 | } |
| 73 | |
| 74 | mux := http.NewServeMux() |
| 75 | mux.HandleFunc("POST /start", s.handleStart) |
| 76 | mux.HandleFunc("POST /stop", s.handleStop) |
| 77 | mux.HandleFunc("GET /txid", s.handleTXID) |
| 78 | mux.HandleFunc("POST /register", s.handleRegister) |
| 79 | mux.HandleFunc("POST /unregister", s.handleUnregister) |
| 80 | mux.HandleFunc("POST /sync", s.handleSync) |
| 81 | mux.HandleFunc("GET /list", s.handleList) |
| 82 | mux.HandleFunc("GET /info", s.handleInfo) |
| 83 | mux.HandleFunc("GET /debug/sync-status", s.handleSyncStatus) |
| 84 | |
| 85 | // pprof endpoints |
| 86 | mux.HandleFunc("GET /debug/pprof/", pprof.Index) |
| 87 | mux.HandleFunc("GET /debug/pprof/cmdline", pprof.Cmdline) |
| 88 | mux.HandleFunc("GET /debug/pprof/profile", pprof.Profile) |
| 89 | mux.HandleFunc("GET /debug/pprof/symbol", pprof.Symbol) |
| 90 | mux.HandleFunc("GET /debug/pprof/trace", pprof.Trace) |
| 91 | |
| 92 | s.httpServer = &http.Server{Handler: mux} |
| 93 | |
| 94 | return s |
| 95 | } |
| 96 | |
| 97 | // Start begins listening for control connections. |
| 98 | func (s *Server) Start() error { |
no outgoing calls