mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-10 18:56:55 +02:00
fix(lint): improve styling and fix lint errors
This commit is contained in:
@@ -47,10 +47,10 @@ var _ entrypoint.Entrypoint = &Entrypoint{}
|
||||
|
||||
var emptyCfg Config
|
||||
|
||||
func NewTestEntrypoint(t testing.TB, cfg *Config) *Entrypoint {
|
||||
t.Helper()
|
||||
func NewTestEntrypoint(tb testing.TB, cfg *Config) *Entrypoint {
|
||||
tb.Helper()
|
||||
|
||||
testTask := task.GetTestTask(t)
|
||||
testTask := task.GetTestTask(tb)
|
||||
ep := NewEntrypoint(testTask, cfg)
|
||||
entrypoint.SetCtx(testTask, ep)
|
||||
return ep
|
||||
@@ -160,6 +160,7 @@ func (ep *Entrypoint) SetAccessLogger(parent task.Parent, cfg *accesslog.Request
|
||||
}
|
||||
|
||||
func findRouteAnyDomain(routes HTTPRoutes, host string) types.HTTPRoute {
|
||||
//nolint:modernize
|
||||
idx := strings.IndexByte(host, '.')
|
||||
if idx != -1 {
|
||||
target := host[:idx]
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/yusing/goutils/server"
|
||||
)
|
||||
|
||||
// httpServer is a server that listens on a given address and serves HTTP routes.
|
||||
// HTTPServer is a server that listens on a given address and serves HTTP routes.
|
||||
type HTTPServer interface {
|
||||
Listen(addr string, proto HTTPProto) error
|
||||
AddRoute(route types.HTTPRoute)
|
||||
@@ -109,6 +109,8 @@ func (srv *httpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
rec := accesslog.GetResponseRecorder(w)
|
||||
w = rec
|
||||
defer func() {
|
||||
// there is no body to close
|
||||
//nolint:bodyclose
|
||||
srv.ep.accessLogger.LogRequest(r, rec.Response())
|
||||
accesslog.PutResponseRecorder(rec)
|
||||
}()
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestShortLinkMatcher_FQDNAlias(t *testing.T) {
|
||||
matcher.AddRoute("app.domain.com")
|
||||
|
||||
t.Run("exact path", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -28,7 +28,7 @@ func TestShortLinkMatcher_FQDNAlias(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("with path remainder", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app/foo/bar", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app/foo/bar", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestShortLinkMatcher_FQDNAlias(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("with query", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app/foo?x=y&z=1", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app/foo?x=y&z=1", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestShortLinkMatcher_SubdomainAlias(t *testing.T) {
|
||||
matcher.AddRoute("app")
|
||||
|
||||
t.Run("exact path", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestShortLinkMatcher_SubdomainAlias(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("with path remainder", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app/foo/bar", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app/foo/bar", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -78,7 +78,7 @@ func TestShortLinkMatcher_NotFound(t *testing.T) {
|
||||
matcher.AddRoute("app")
|
||||
|
||||
t.Run("missing key", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -86,7 +86,7 @@ func TestShortLinkMatcher_NotFound(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("unknown key", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/unknown", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/unknown", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -103,13 +103,13 @@ func TestShortLinkMatcher_AddDelRoute(t *testing.T) {
|
||||
matcher.AddRoute("app2.domain.com")
|
||||
|
||||
t.Run("both routes work", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app1", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app1", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||
assert.Equal(t, "https://app1.example.com/", w.Header().Get("Location"))
|
||||
|
||||
req = httptest.NewRequest("GET", "/app2.domain.com", nil)
|
||||
req = httptest.NewRequest(http.MethodGet, "/app2.domain.com", nil)
|
||||
w = httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||
@@ -119,12 +119,12 @@ func TestShortLinkMatcher_AddDelRoute(t *testing.T) {
|
||||
t.Run("delete route", func(t *testing.T) {
|
||||
matcher.DelRoute("app1")
|
||||
|
||||
req := httptest.NewRequest("GET", "/app1", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app1", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusNotFound, w.Code)
|
||||
|
||||
req = httptest.NewRequest("GET", "/app2.domain.com", nil)
|
||||
req = httptest.NewRequest(http.MethodGet, "/app2.domain.com", nil)
|
||||
w = httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusTemporaryRedirect, w.Code)
|
||||
@@ -140,7 +140,7 @@ func TestShortLinkMatcher_NoDefaultDomainSuffix(t *testing.T) {
|
||||
t.Run("subdomain alias ignored", func(t *testing.T) {
|
||||
matcher.AddRoute("app")
|
||||
|
||||
req := httptest.NewRequest("GET", "/app", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -150,7 +150,7 @@ func TestShortLinkMatcher_NoDefaultDomainSuffix(t *testing.T) {
|
||||
t.Run("FQDN alias still works", func(t *testing.T) {
|
||||
matcher.AddRoute("app.domain.com")
|
||||
|
||||
req := httptest.NewRequest("GET", "/app.domain.com", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app.domain.com", nil)
|
||||
w := httptest.NewRecorder()
|
||||
matcher.ServeHTTP(w, req)
|
||||
|
||||
@@ -169,7 +169,7 @@ func TestEntrypoint_ShortLinkDispatch(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Run("shortlink host", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app", nil)
|
||||
req.Host = common.ShortLinkPrefix
|
||||
w := httptest.NewRecorder()
|
||||
server.ServeHTTP(w, req)
|
||||
@@ -179,7 +179,7 @@ func TestEntrypoint_ShortLinkDispatch(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("shortlink host with port", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app", nil)
|
||||
req.Host = common.ShortLinkPrefix + ":8080"
|
||||
w := httptest.NewRecorder()
|
||||
server.ServeHTTP(w, req)
|
||||
@@ -189,7 +189,7 @@ func TestEntrypoint_ShortLinkDispatch(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("normal host", func(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/app", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/app", nil)
|
||||
req.Host = "app.example.com"
|
||||
w := httptest.NewRecorder()
|
||||
server.ServeHTTP(w, req)
|
||||
|
||||
Reference in New Issue
Block a user