refactor: minor issue and documentation

This commit is contained in:
yusing
2026-02-07 21:01:04 +08:00
parent 58305a496f
commit 65cfa90c95
4 changed files with 9 additions and 11 deletions

View File

@@ -377,7 +377,7 @@ Routes can access the entrypoint from request context:
```go
// Set entrypoint in context
entrypoint.SetCtx(r.Context(), ep)
entrypoint.SetCtx(task, ep)
// Get entrypoint from context
if ep := entrypoint.FromCtx(r.Context()); ep != nil {

View File

@@ -230,7 +230,6 @@ func TestEntrypointBypassRoute(t *testing.T) {
portInt, err := strconv.Atoi(port)
expect.NoError(t, err)
expect.NoError(t, err)
entry := entrypoint.NewTestEntrypoint(t, nil)
_, err = route.NewStartedTestRoute(t, &route.Route{
Alias: "test-route",

View File

@@ -212,9 +212,9 @@ func TestRouteBindField(t *testing.T) {
t.Run("HTTPSchemeWithoutBind", func(t *testing.T) {
r := &Route{
Alias: "test-http",
Scheme: route.SchemeHTTPS,
Scheme: route.SchemeHTTP,
Host: "example.com",
Port: route.Port{Proxy: 443},
Port: route.Port{Proxy: 80},
}
err := r.Validate()
require.NoError(t, err, "Validate should not return error for HTTP route with bind")
@@ -225,9 +225,9 @@ func TestRouteBindField(t *testing.T) {
t.Run("HTTPSchemeWithBind", func(t *testing.T) {
r := &Route{
Alias: "test-http",
Scheme: route.SchemeHTTPS,
Scheme: route.SchemeHTTP,
Host: "example.com",
Port: route.Port{Proxy: 443},
Port: route.Port{Proxy: 80},
Bind: "0.0.0.0",
}
err := r.Validate()
@@ -239,15 +239,15 @@ func TestRouteBindField(t *testing.T) {
t.Run("HTTPSchemeWithBindAndPort", func(t *testing.T) {
r := &Route{
Alias: "test-http",
Scheme: route.SchemeHTTPS,
Scheme: route.SchemeHTTP,
Host: "example.com",
Port: route.Port{Listening: 8443, Proxy: 443},
Port: route.Port{Listening: 8080, Proxy: 80},
Bind: "0.0.0.0",
}
err := r.Validate()
require.NoError(t, err, "Validate should not return error for HTTP route with bind and port")
require.NotNil(t, r.LisURL, "LisURL should be set")
require.Equal(t, "https://0.0.0.0:8443", r.LisURL.String(), "LisURL should contain bind address and listening port")
require.Equal(t, "https://0.0.0.0:8080", r.LisURL.String(), "LisURL should contain bind address and listening port")
})
t.Run("TCPSchemeDefaultsToZeroBind", func(t *testing.T) {

View File

@@ -63,10 +63,9 @@ func NewUDPUDPStream(network, listenAddr, dstAddr string) (nettypes.Stream, erro
```go
type Stream interface {
ListenAndServe(ctx context.Context, preDial, onRead HookFunc)
ListenAndServe(ctx context.Context, preDial, onRead HookFunc) error
Close() error
LocalAddr() net.Addr
zerolog.LogObjectMarshaler
}
type HookFunc func(ctx context.Context) error