Files
yoresee_codegen/internal/api/server.go
T
XingfenD 4e467e1136 feat: implement proto-gen platform
- Config loader with env var expansion and validation
- SQLite database with tasks and toolchain_versions tables
- Gitea REST API client for repository and branch operations
- K8s client for Job lifecycle management (with noop fallback for local dev)
- REST API: tasks CRUD, retry, plugins, version management
- Worker/scheduler with polling, concurrency control, and job tracking
- Static frontend: generate, tasks, settings pages
- Toolchain images: Go and Node.js Dockerfiles with entrypoint scripts
- Helm chart with deployment, service, configmap, ingress, PVC
- Multi-stage Dockerfile for service
- Unit tests for config, database, gitclient, k8s, api, worker
- E2E tests for idempotency, version switch, failure recovery
2026-08-10 16:54:30 +08:00

59 lines
1.3 KiB
Go

package api
import (
"log"
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"proto-gen/internal/config"
"proto-gen/internal/database"
"proto-gen/internal/gitclient"
)
type Server struct {
router *chi.Mux
db *database.DB
cfg *config.Config
git gitclient.GitClient
}
func NewServer(db *database.DB, cfg *config.Config, git gitclient.GitClient) *Server {
s := &Server{
router: chi.NewRouter(),
db: db,
cfg: cfg,
git: git,
}
s.routes()
return s
}
func (s *Server) routes() {
s.router.Use(middleware.Logger)
s.router.Use(middleware.Recoverer)
s.router.Use(middleware.Compress(5))
s.router.Route("/api/v1", func(r chi.Router) {
r.Post("/tasks", s.handleCreateTask)
r.Get("/tasks", s.handleListTasks)
r.Get("/tasks/{id}", s.handleGetTask)
r.Post("/tasks/{id}/retry", s.handleRetryTask)
r.Get("/plugins", s.handleListPlugins)
r.Get("/plugins/{lang}/versions", s.handleGetPluginVersion)
r.Put("/plugins/{lang}/versions", s.handleUpdatePluginVersion)
})
s.router.Handle("/*", http.FileServer(http.Dir("internal/static")))
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.router.ServeHTTP(w, r)
}
func (s *Server) Start(addr string) error {
log.Printf("server listening on %s", addr)
return http.ListenAndServe(addr, s.router)
}