api

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 18 Imported by: 0

README

HTTP API

You can manage all blocks with basic HTTP API functions.

Authentication

API bearer token can be set on sdns config. If the token set, Authorization header should be send on API requests.

Example Header

Authorization: Bearer my_very_long_token

Actions

GET /api/v1/block/set/:key

It is used to create a new block.

request

curl http://localhost:8080/api/v1/block/set/domain.com

response

{"success":true}
GET /api/v1/block/get/:key

Used to request an existing block

request

curl http://localhost:8080/api/v1/block/get/domain.com

response

{"success":true}

or

{"error":"domain.com not found"}
GET /api/v1/block/exists/:key

It queries whether it has a block.

request

curl http://localhost:8080/api/v1/block/exists/domain.com

response

{"success":true}
GET /api/v1/block/remove/:key

Deletes the block.

request

curl http://localhost:8080/api/v1/block/remove/domain.com

response

{"success":true}
GET /api/v1/purge/domain/type

Purge a cached query.

request

curl http://localhost:8080/api/v1/purge/example.com/MX

response

{"success":true}
GET /metrics

Export the prometheus metrics.

Documentation

Overview

Copyright (c) 2019 Eduard Urbach

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

API type

func New

func New(cfg *config.Config) *API

New return new api

func (*API) Run

func (a *API) Run(ctx context.Context)

Run API server

type Context added in v1.3.2

type Context struct {
	Request *http.Request
	Writer  http.ResponseWriter
	Handler Handler
	Params  *Params
}

func (*Context) JSON added in v1.3.2

func (ctx *Context) JSON(code int, data any)

func (*Context) Param added in v1.3.2

func (ctx *Context) Param(key string) string

type Group added in v1.3.2

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

func (*Group) GET added in v1.3.2

func (g *Group) GET(path string, handle Handler)

func (*Group) Handle added in v1.3.2

func (g *Group) Handle(method, path string, handle Handler)

func (*Group) POST added in v1.3.2

func (g *Group) POST(path string, handle Handler)

type Handler added in v1.3.2

type Handler func(ctx *Context)

type Json added in v1.3.2

type Json map[string]any

type Param added in v1.3.2

type Param struct {
	Key   string
	Value string
}

type Params added in v1.3.2

type Params []Param

type Router added in v1.3.2

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

func NewRouter added in v1.3.2

func NewRouter() *Router

func (*Router) GET added in v1.3.2

func (rt *Router) GET(path string, handle Handler)

func (*Router) Group added in v1.3.2

func (rt *Router) Group(rp string) *Group

func (*Router) Handle added in v1.3.2

func (rt *Router) Handle(method, path string, handle Handler)

func (*Router) POST added in v1.3.2

func (rt *Router) POST(path string, handle Handler)

func (*Router) ServeHTTP added in v1.3.2

func (rt *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Tree added in v1.3.2

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

Tree represents a radix tree.

func (*Tree) Add added in v1.3.2

func (tree *Tree) Add(path string, data dataType)

Add adds a new element to the tree.

func (*Tree) Lookup added in v1.3.2

func (tree *Tree) Lookup(ctx *Context)

Lookup finds the data for the request path and assigns it to ctx.Handler, if available.

Jump to

Keyboard shortcuts

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