Go printer-farm manager (Wave 1, Redmine #855). Cloudron-deployable, OIDC via platform provider planned; Moonraker/OctoPrint/Bambu adapters + Dolibarr connector are the next milestones. Dockerfile: multi-stage, non-root, no Node anywhere in the chain.
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
// Package server wires the HTTP surface: health, dashboard, and (coming)
|
|
// the printer/job APIs. See Redmine #855 for the component design.
|
|
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"net/http"
|
|
)
|
|
|
|
type Config struct {
|
|
Addr string
|
|
DBPath string
|
|
}
|
|
|
|
type Server struct {
|
|
cfg Config
|
|
mux *http.ServeMux
|
|
}
|
|
|
|
func New(cfg Config) *Server {
|
|
s := &Server{cfg: cfg, mux: http.NewServeMux()}
|
|
s.mux.HandleFunc("/healthz", s.health)
|
|
s.mux.HandleFunc("/", s.index)
|
|
return s
|
|
}
|
|
|
|
func (s *Server) Run() error {
|
|
return http.ListenAndServe(s.cfg.Addr, s.mux)
|
|
}
|
|
|
|
func (s *Server) health(w http.ResponseWriter, _ *http.Request) {
|
|
w.WriteHeader(http.StatusOK)
|
|
fmt.Fprintln(w, "ok")
|
|
}
|
|
|
|
// index is the farm dashboard placeholder. The real board (printer cards,
|
|
// job queue, batch view) lands with the printer adapters.
|
|
func (s *Server) index(w http.ResponseWriter, _ *http.Request) {
|
|
t, err := template.ParseFiles("web/templates/index.html")
|
|
if err != nil {
|
|
http.Error(w, "template: "+err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
_ = t.Execute(w, map[string]string{"Toolset": "farmd 0.1.0-dev"})
|
|
}
|