two/internal/api/agent/server.go
GnomeZworc 327a359007
f-21: code: separate and create route fonction
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
2026-04-21 23:36:32 +02:00

33 lines
786 B
Go

package agentapi
import (
"log"
"net/http"
"git.g3e.fr/syonad/two/pkg/worker"
)
type Server struct {
queue *worker.Queue
}
func New(queue *worker.Queue) *Server {
return &Server{queue: queue}
}
func (s *Server) Start(address string) {
mux := http.NewServeMux()
mux.HandleFunc("/vpcs", s.VpcsHandler)
mux.HandleFunc("/vpcs/", s.VpcByNameHandler)
mux.HandleFunc("/subnets", s.SubnetsHandler)
mux.HandleFunc("/subnets/", s.SubnetByNameHandler)
log.Printf("API server listening on %s", address)
log.Fatal(http.ListenAndServe(address, logMiddleware(mux)))
}
func logMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s %s", r.RemoteAddr, r.Method, r.URL.Path)
next.ServeHTTP(w, r)
})
}