package web import ( "fmt" "net/http" "nugitea/internal/auth" "nugitea/internal/user" ) // Server represents the web server type Server struct { userStore *user.Store auth *auth.Authenticator } // NewServer creates a new web server func NewServer() *Server { return &Server{ userStore: user.NewStore(), } } // SetupRoutes sets up all HTTP routes func (s *Server) SetupRoutes() http.Handler { mux := http.NewServeMux() // Public routes mux.HandleFunc("/", HomeHandler) mux.HandleFunc("/login", s.LoginHandler) mux.HandleFunc("/logout", s.LogoutHandler) // Protected routes mux.Handle("/dashboard", auth.RequireAuth(auth.MockAuthenticate)(s.DashboardHandler)) mux.Handle("/users", auth.RequireAuth(auth.MockAuthenticate)(s.UsersHandler)) return mux } // HomeHandler handles the home page func HomeHandler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "
This is a minimal Git server.
") } // LoginHandler handles login requests func (s *Server) LoginHandler(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { // Show login form fmt.Fprintf(w, `Welcome to your dashboard.
") } // UsersHandler handles the users page func (s *Server) UsersHandler(w http.ResponseWriter, r *http.Request) { users := s.userStore.GetAllUsers() w.Header().Set("Content-Type", "text/html") fmt.Fprintf(w, "