admin

package
v0.24.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package admin implements a single-endpoint RPC-style Admin API for Madmail.

Architecture: All requests are POST /api/admin with a JSON body:

{
    "method": "GET|POST|PUT|DELETE|PATCH",
    "resource": "/admin/status",
    "headers": { "Authorization": "Bearer <token>" },
    "body": {}
}

Response format:

{
    "status": 200,
    "resource": "/admin/status",
    "body": { ... },
    "error": null
}

This design makes the API easier to hide behind reverse proxies, firewalls, or custom auth layers — one port, one path, one handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler is the main Admin API handler.

func NewHandler

func NewHandler(token string, logger log.Logger) *Handler

NewHandler creates a new Admin API handler.

func (*Handler) Register

func (h *Handler) Register(path string, handler ResourceHandler)

Register adds a resource handler for the given path.

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type Request

type Request struct {
	Method   string            `json:"method"`
	Resource string            `json:"resource"`
	Headers  map[string]string `json:"headers"`
	Body     json.RawMessage   `json:"body"`
}

Request is the JSON-RPC style request envelope.

type ResourceHandler

type ResourceHandler func(method string, body json.RawMessage) (interface{}, int, error)

ResourceHandler is the signature for individual resource handlers. It receives the parsed request and returns a response body and status code.

type Response

type Response struct {
	Status   int         `json:"status"`
	Resource string      `json:"resource"`
	Body     interface{} `json:"body"`
	Error    *string     `json:"error"`
}

Response is the JSON-RPC style response envelope.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL