refactor(api): restructured API for type safety, maintainability and docs generation

- These changes makes the API incombatible with previous versions
- Added new types for error handling, success responses, and health checks.
- Updated health check logic to utilize the new types for better clarity and structure.
- Refactored existing handlers to improve response consistency and error handling.
- Updated Makefile to include a new target for generating API types from Swagger.
- Updated "new agent" API to respond an encrypted cert pair
This commit is contained in:
yusing
2025-08-16 13:04:05 +08:00
parent fce9ce21c9
commit 35a3e3fef6
149 changed files with 13173 additions and 2173 deletions

View File

@@ -5,11 +5,9 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/yusing/go-proxy/internal/common"
"github.com/yusing/go-proxy/internal/docker"
loadbalance "github.com/yusing/go-proxy/internal/net/gphttp/loadbalancer/types"
route "github.com/yusing/go-proxy/internal/route/types"
"github.com/yusing/go-proxy/internal/types"
expect "github.com/yusing/go-proxy/internal/utils/testing"
"github.com/yusing/go-proxy/internal/watcher/health"
)
func TestRouteValidate(t *testing.T) {
@@ -43,10 +41,10 @@ func TestRouteValidate(t *testing.T) {
Scheme: route.SchemeHTTP,
Host: "example.com",
Port: route.Port{Proxy: 80},
HealthCheck: &health.HealthCheckConfig{
HealthCheck: &types.HealthCheckConfig{
Disable: true,
},
LoadBalance: &loadbalance.Config{
LoadBalance: &types.LoadBalancerConfig{
Link: "test-link",
}, // Minimal LoadBalance config with non-empty Link will be checked by UseLoadBalance
}
@@ -99,9 +97,9 @@ func TestRouteValidate(t *testing.T) {
Host: "example.com",
Port: route.Port{Proxy: 80},
Metadata: Metadata{
Container: &docker.Container{
Container: &types.Container{
ContainerID: "test-id",
Image: &docker.ContainerImage{
Image: &types.ContainerImage{
Name: "test-image",
},
},
@@ -157,9 +155,9 @@ func TestDockerRouteDisallowAgent(t *testing.T) {
Port: route.Port{Proxy: 80},
Agent: "test-agent",
Metadata: Metadata{
Container: &docker.Container{
Container: &types.Container{
ContainerID: "test-id",
Image: &docker.ContainerImage{
Image: &types.ContainerImage{
Name: "test-image",
},
},