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

@@ -4,11 +4,12 @@ import (
"strings"
"github.com/docker/docker/api/types/container"
"github.com/yusing/go-proxy/internal/types"
"github.com/yusing/go-proxy/internal/utils/strutils"
)
type containerHelper struct {
*container.SummaryTrimmed
*container.Summary
}
// getDeleteLabel gets the value of a label and then deletes it from the container.
@@ -40,10 +41,10 @@ func (c containerHelper) getMounts() []string {
return m
}
func (c containerHelper) parseImage() *ContainerImage {
func (c containerHelper) parseImage() *types.ContainerImage {
colonSep := strutils.SplitRune(c.Image, ':')
slashSep := strutils.SplitRune(colonSep[0], '/')
im := new(ContainerImage)
im := new(types.ContainerImage)
if len(slashSep) > 1 {
im.Author = strings.Join(slashSep[:len(slashSep)-1], "/")
im.Name = slashSep[len(slashSep)-1]
@@ -59,8 +60,8 @@ func (c containerHelper) parseImage() *ContainerImage {
return im
}
func (c containerHelper) getPublicPortMapping() PortMapping {
res := make(PortMapping)
func (c containerHelper) getPublicPortMapping() types.PortMapping {
res := make(types.PortMapping)
for _, v := range c.Ports {
if v.PublicPort == 0 {
continue
@@ -70,8 +71,8 @@ func (c containerHelper) getPublicPortMapping() PortMapping {
return res
}
func (c containerHelper) getPrivatePortMapping() PortMapping {
res := make(PortMapping)
func (c containerHelper) getPrivatePortMapping() types.PortMapping {
res := make(types.PortMapping)
for _, v := range c.Ports {
res[int(v.PrivatePort)] = v
}