merge: main branch

This commit is contained in:
yusing
2025-04-24 15:02:31 +08:00
parent 806184e98b
commit 663a107c06
107 changed files with 3047 additions and 2034 deletions

View File

@@ -1,4 +1,4 @@
package types
package route
import (
"time"

View File

@@ -1,27 +1,27 @@
package types_test
package route_test
import (
"testing"
"time"
. "github.com/yusing/go-proxy/internal/route"
"github.com/yusing/go-proxy/internal/route/types"
route "github.com/yusing/go-proxy/internal/route/types"
"github.com/yusing/go-proxy/internal/utils"
. "github.com/yusing/go-proxy/internal/utils/testing"
expect "github.com/yusing/go-proxy/internal/utils/testing"
)
func TestHTTPConfigDeserialize(t *testing.T) {
tests := []struct {
name string
input map[string]any
expected types.HTTPConfig
expected route.HTTPConfig
}{
{
name: "no_tls_verify",
input: map[string]any{
"no_tls_verify": "true",
},
expected: types.HTTPConfig{
expected: route.HTTPConfig{
NoTLSVerify: true,
},
},
@@ -30,7 +30,7 @@ func TestHTTPConfigDeserialize(t *testing.T) {
input: map[string]any{
"response_header_timeout": "1s",
},
expected: types.HTTPConfig{
expected: route.HTTPConfig{
ResponseHeaderTimeout: 1 * time.Second,
},
},
@@ -39,11 +39,12 @@ func TestHTTPConfigDeserialize(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := Route{}
tt.input["host"] = "internal"
err := utils.Deserialize(tt.input, &cfg)
if err != nil {
ExpectNoError(t, err)
expect.NoError(t, err)
}
ExpectEqual(t, cfg.HTTPConfig, tt.expected)
expect.Equal(t, cfg.HTTPConfig, tt.expected)
})
}
}

View File

@@ -1,4 +1,4 @@
package types
package route
import (
"strconv"

View File

@@ -1,4 +1,4 @@
package types
package route
import (
"errors"

View File

@@ -1,53 +0,0 @@
package types
import (
"net/http"
"github.com/yusing/go-proxy/agent/pkg/agent"
"github.com/yusing/go-proxy/internal/docker"
idlewatcher "github.com/yusing/go-proxy/internal/docker/idlewatcher/types"
"github.com/yusing/go-proxy/internal/homepage"
net "github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/task"
"github.com/yusing/go-proxy/internal/watcher/health"
loadbalance "github.com/yusing/go-proxy/internal/net/gphttp/loadbalancer/types"
)
type (
//nolint:interfacebloat // this is for avoiding circular imports
Route interface {
task.TaskStarter
task.TaskFinisher
ProviderName() string
TargetName() string
TargetURL() *net.URL
HealthMonitor() health.HealthMonitor
Started() bool
IdlewatcherConfig() *idlewatcher.Config
HealthCheckConfig() *health.HealthCheckConfig
LoadBalanceConfig() *loadbalance.Config
HomepageConfig() *homepage.ItemConfig
HomepageItem() *homepage.Item
ContainerInfo() *docker.Container
Agent() *agent.AgentConfig
IsDocker() bool
IsAgent() bool
UseLoadBalance() bool
UseIdleWatcher() bool
UseHealthCheck() bool
UseAccessLog() bool
}
HTTPRoute interface {
Route
http.Handler
}
StreamRoute interface {
Route
net.Stream
}
)

View File

@@ -1,4 +1,4 @@
package types
package route
type RouteType string

View File

@@ -1,4 +1,4 @@
package types
package route
import (
"github.com/yusing/go-proxy/internal/gperr"