dd060fd34a
- Fix openapi.yaml: quote bearerAuth description that contained unquoted `: ` plain-scalar YAML
- Add server/api/cfg-{types,server,client}.yaml — oapi-codegen v2 config for three split outputs
- Add server/api/gen/gen.go — three //go:generate directives; run `make generate`
- Generate server/api/gen/{types,server,client}.gen.go from the contract (all 15 operations)
- Add github.com/oapi-codegen/runtime v1.4.1 to go.mod (runtime types needed by generated code)
- Add server/internal/httpapi/unimplemented.go — UnimplementedServer satisfies gen.ServerInterface;
every method writes HTTP 501 + {code,message_zh,message_en} JSON body (no dep on task-1f apierr)
- Update server/cmd/server/main.go — mount /v1 API via gen.HandlerFromMuxWithBaseURL; keep /healthz
- Update server/Makefile — `generate` target now runs `go generate ./...`;
add `check-generate` CI guard (regenerate + git diff --exit-code)
- Add server/internal/httpapi/unimplemented_test.go — 19 httptest cases covering all 15 API routes
(501+body), undefined routes (404), and /healthz isolation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
111 lines
4.1 KiB
Go
111 lines
4.1 KiB
Go
// Package httpapi contains HTTP API handler stubs for the Pangolin v1 API.
|
|
// All endpoints return HTTP 501 with a structured bilingual error body until
|
|
// real business logic is wired in (tasks #2-#8).
|
|
package httpapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
openapi_types "github.com/oapi-codegen/runtime/types"
|
|
|
|
"github.com/wangjia/pangolin/server/api/gen"
|
|
)
|
|
|
|
// notImplError is the fixed JSON error body returned by every 501 stub.
|
|
// Intentionally hand-written here (not from internal/apierr) so that this
|
|
// package stays free of dependencies on task-1f which runs in parallel.
|
|
var notImplError = struct {
|
|
Code string `json:"code"`
|
|
MessageZH string `json:"message_zh"`
|
|
MessageEn string `json:"message_en"`
|
|
}{
|
|
Code: "NOT_IMPLEMENTED",
|
|
MessageZH: "接口尚未实现",
|
|
MessageEn: "Not implemented yet",
|
|
}
|
|
|
|
// writeNotImpl writes a 501 Not Implemented response with the structured error body.
|
|
func writeNotImpl(w http.ResponseWriter) {
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(http.StatusNotImplemented)
|
|
_ = json.NewEncoder(w).Encode(notImplError)
|
|
}
|
|
|
|
// UnimplementedServer satisfies gen.ServerInterface and returns 501 for every
|
|
// endpoint. Individual methods should be replaced as each module is implemented.
|
|
type UnimplementedServer struct{}
|
|
|
|
// Compile-time assertion: UnimplementedServer must satisfy ServerInterface.
|
|
var _ gen.ServerInterface = (*UnimplementedServer)(nil)
|
|
|
|
// ── Auth ─────────────────────────────────────────────────────────────────────
|
|
|
|
func (s *UnimplementedServer) SendVerificationCode(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) Register(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) Login(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) RefreshToken(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
// ── Account ──────────────────────────────────────────────────────────────────
|
|
|
|
func (s *UnimplementedServer) GetMe(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) ListDevices(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) DeleteDevice(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
// ── Commerce ─────────────────────────────────────────────────────────────────
|
|
|
|
func (s *UnimplementedServer) RedeemCode(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) AdsUnlock(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) ListPlans(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
// ── Nodes ────────────────────────────────────────────────────────────────────
|
|
|
|
func (s *UnimplementedServer) ListNodes(w http.ResponseWriter, r *http.Request, params gen.ListNodesParams) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) ConnectNode(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) DisconnectNode(w http.ResponseWriter, r *http.Request, id openapi_types.UUID) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
// ── Usage & Notices ──────────────────────────────────────────────────────────
|
|
|
|
func (s *UnimplementedServer) GetUsage(w http.ResponseWriter, r *http.Request, params gen.GetUsageParams) {
|
|
writeNotImpl(w)
|
|
}
|
|
|
|
func (s *UnimplementedServer) ListNotices(w http.ResponseWriter, r *http.Request) {
|
|
writeNotImpl(w)
|
|
}
|