mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-17 21:41:58 +00:00
admin: move /info endpoint into internal/admininfo
Keeps AdminInfo out of the root caddy package's public API. The module is registered via a blank import in modules/standard, since the root package can't import it without an import cycle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5cc146a7b1
commit
8b271d017d
3 changed files with 18 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue