diff --git a/admin_info.go b/internal/admininfo/admininfo.go similarity index 82% rename from admin_info.go rename to internal/admininfo/admininfo.go index 0231475e5..663c88ce9 100644 --- a/admin_info.go +++ b/internal/admininfo/admininfo.go @@ -12,17 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -package caddy +package admininfo import ( "encoding/json" "net/http" "runtime" "runtime/debug" + + "github.com/caddyserver/caddy/v2" ) func init() { - RegisterModule(AdminInfo{}) + caddy.RegisterModule(AdminInfo{}) } // AdminInfo is a module that provides a GET /info endpoint on the @@ -31,17 +33,17 @@ func init() { type AdminInfo struct{} // CaddyModule returns the Caddy module information. -func (AdminInfo) CaddyModule() ModuleInfo { - return ModuleInfo{ +func (AdminInfo) CaddyModule() caddy.ModuleInfo { + return caddy.ModuleInfo{ ID: "admin.api.info", - New: func() Module { return new(AdminInfo) }, + New: func() caddy.Module { return new(AdminInfo) }, } } // Routes returns a route for the /info endpoint. -func (ai AdminInfo) Routes() []AdminRoute { - return []AdminRoute{ - {Pattern: "/info", Handler: AdminHandlerFunc(ai.handleInfo)}, +func (ai AdminInfo) Routes() []caddy.AdminRoute { + return []caddy.AdminRoute{ + {Pattern: "/info", Handler: caddy.AdminHandlerFunc(ai.handleInfo)}, } } @@ -58,13 +60,13 @@ type infoResponse struct { func (AdminInfo) handleInfo(w http.ResponseWriter, r *http.Request) error { if r.Method != http.MethodGet { w.Header().Set("Allow", http.MethodGet) - return APIError{ + return caddy.APIError{ HTTPStatus: http.StatusMethodNotAllowed, Message: "method not allowed", } } - simple, full := Version() + simple, full := caddy.Version() resp := infoResponse{ Version: simple, @@ -89,4 +91,4 @@ func (AdminInfo) handleInfo(w http.ResponseWriter, r *http.Request) error { } // Interface guards -var _ AdminRouter = (*AdminInfo)(nil) +var _ caddy.AdminRouter = (*AdminInfo)(nil) diff --git a/admin_info_test.go b/internal/admininfo/admininfo_test.go similarity index 96% rename from admin_info_test.go rename to internal/admininfo/admininfo_test.go index 96dc18bd4..05a4aa8e8 100644 --- a/admin_info_test.go +++ b/internal/admininfo/admininfo_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package caddy +package admininfo import ( "encoding/json" @@ -20,6 +20,8 @@ import ( "net/http/httptest" "runtime" "testing" + + "github.com/caddyserver/caddy/v2" ) func TestAdminInfoModule(t *testing.T) { @@ -83,7 +85,7 @@ func TestAdminInfoHandler(t *testing.T) { if err == nil { t.Fatal("expected error for POST method") } - apiErr, ok := err.(APIError) + apiErr, ok := err.(caddy.APIError) if !ok { t.Fatalf("expected APIError, got %T", err) } diff --git a/modules/standard/imports.go b/modules/standard/imports.go index 813c63d6c..58e32cd86 100644 --- a/modules/standard/imports.go +++ b/modules/standard/imports.go @@ -3,6 +3,7 @@ package standard import ( // standard Caddy modules _ "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" + _ "github.com/caddyserver/caddy/v2/internal/admininfo" _ "github.com/caddyserver/caddy/v2/modules/caddyevents" _ "github.com/caddyserver/caddy/v2/modules/caddyevents/eventsconfig" _ "github.com/caddyserver/caddy/v2/modules/caddyfs"