openapi

package
v0.0.0-...-6186a43 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const CNAME_FILE = "/etc/dnsmasq.d/05-pihole-custom-cname.conf"
View Source
const EMPTY_LIST = "Not showing empty list"
View Source
const LIST_REGEX = `\d: (.+) \((.*), last modified (.*)\)$`
View Source
const PIHOLE_EXECUTABLE = "/usr/local/bin/pihole"
View Source
const SQLLITE_DATABASE = "/etc/pihole/gravity.db"
View Source
const SQLLITE_EXECUTABLE = "/usr/bin/sqlite3"
View Source
const TYPEA_FILE = "/etc/pihole/custom.list"

Variables

View Source
var (
	// ErrTypeAssertionError is thrown when type an interface does not match the asserted type
	ErrTypeAssertionError = errors.New("unable to assert type")
)

Functions

func AssertDeleteRecordConstraints

func AssertDeleteRecordConstraints(obj DeleteRecord) error

AssertDeleteRecordConstraints checks if the values respects the defined constraints

func AssertDeleteRecordRequired

func AssertDeleteRecordRequired(obj DeleteRecord) error

AssertDeleteRecordRequired checks if the required fields are not zero-ed

func AssertGravityObjConstraints

func AssertGravityObjConstraints(obj GravityObj) error

AssertGravityObjConstraints checks if the values respects the defined constraints

func AssertGravityObjRequired

func AssertGravityObjRequired(obj GravityObj) error

AssertGravityObjRequired checks if the required fields are not zero-ed

func AssertRecordConstraints

func AssertRecordConstraints(obj Record) error

AssertRecordConstraints checks if the values respects the defined constraints

func AssertRecordRequired

func AssertRecordRequired(obj Record) error

AssertRecordRequired checks if the required fields are not zero-ed

func AssertRecurseInterfaceRequired

func AssertRecurseInterfaceRequired[T any](obj interface{}, callback func(T) error) error

AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. This method traverse nested slices in a preorder fashion.

func AssertRecurseValueRequired

func AssertRecurseValueRequired[T any](value reflect.Value, callback func(T) error) error

AssertRecurseValueRequired checks each struct in the nested slice against the callback. This method traverse nested slices in a preorder fashion. ErrTypeAssertionError is thrown if the underlying struct does not match type T.

func AssertStatusConstraints

func AssertStatusConstraints(obj Status) error

AssertStatusConstraints checks if the values respects the defined constraints

func AssertStatusRequired

func AssertStatusRequired(obj Status) error

AssertStatusRequired checks if the required fields are not zero-ed

func AssertUdpTcpConstraints

func AssertUdpTcpConstraints(obj UdpTcp) error

AssertUdpTcpConstraints checks if the values respects the defined constraints

func AssertUdpTcpRequired

func AssertUdpTcpRequired(obj UdpTcp) error

AssertUdpTcpRequired checks if the required fields are not zero-ed

func DefaultErrorHandler

func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

DefaultErrorHandler defines the default logic on how to handle errors from the controller. Any errors from parsing request params will return a StatusBadRequest. Otherwise, the error code originating from the servicer will be used.

func EncodeJSONResponse

func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error

EncodeJSONResponse uses the json encoder to write an interface to the http response with an optional status code

func IsZeroValue

func IsZeroValue(val interface{}) bool

IsZeroValue checks if the val is the zero-ed value.

func Logger

func Logger(inner http.Handler, name string) http.Handler

func NewRouter

func NewRouter(routers ...Router) *mux.Router

NewRouter creates a new router for any number of api routers

func ReadFormFileToTempFile

func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)

ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file

func ReadFormFilesToTempFiles

func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)

ReadFormFilesToTempFiles reads files array data from a request form and writes it to a temporary files

Types

type Constraint

type Constraint[T Number | string | bool] func(actual T) error

func WithMaximum

func WithMaximum[T Number](expected T) Constraint[T]

func WithMinimum

func WithMinimum[T Number](expected T) Constraint[T]

type DefaultAPIController

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

DefaultAPIController binds http requests to an api service and writes the service results to the http response

func (*DefaultAPIController) GravityGet

func (c *DefaultAPIController) GravityGet(w http.ResponseWriter, r *http.Request)

GravityGet -

func (*DefaultAPIController) GravityIdDelete

func (c *DefaultAPIController) GravityIdDelete(w http.ResponseWriter, r *http.Request)

GravityIdDelete -

func (*DefaultAPIController) GravityPatch

func (c *DefaultAPIController) GravityPatch(w http.ResponseWriter, r *http.Request)

GravityPatch -

func (*DefaultAPIController) GravityPost

func (c *DefaultAPIController) GravityPost(w http.ResponseWriter, r *http.Request)

GravityPost -

func (*DefaultAPIController) OverridesListGet

func (c *DefaultAPIController) OverridesListGet(w http.ResponseWriter, r *http.Request)

OverridesListGet -

func (*DefaultAPIController) RecordsDelete

func (c *DefaultAPIController) RecordsDelete(w http.ResponseWriter, r *http.Request)

RecordsDelete -

func (*DefaultAPIController) RecordsGet

func (c *DefaultAPIController) RecordsGet(w http.ResponseWriter, r *http.Request)

RecordsGet -

func (*DefaultAPIController) RecordsPost

func (c *DefaultAPIController) RecordsPost(w http.ResponseWriter, r *http.Request)

RecordsPost -

func (*DefaultAPIController) Routes

func (c *DefaultAPIController) Routes() Routes

Routes returns all the api routes for the DefaultAPIController

func (*DefaultAPIController) StatusActionPost

func (c *DefaultAPIController) StatusActionPost(w http.ResponseWriter, r *http.Request)

StatusActionPost -

func (*DefaultAPIController) StatusGet

func (c *DefaultAPIController) StatusGet(w http.ResponseWriter, r *http.Request)

StatusGet -

type DefaultAPIOption

type DefaultAPIOption func(*DefaultAPIController)

DefaultAPIOption for how the controller is set up.

func WithDefaultAPIErrorHandler

func WithDefaultAPIErrorHandler(h ErrorHandler) DefaultAPIOption

WithDefaultAPIErrorHandler inject ErrorHandler into controller

type DefaultAPIRouter

type DefaultAPIRouter interface {
	GravityGet(http.ResponseWriter, *http.Request)
	GravityIdDelete(http.ResponseWriter, *http.Request)
	GravityPatch(http.ResponseWriter, *http.Request)
	GravityPost(http.ResponseWriter, *http.Request)
	OverridesListGet(http.ResponseWriter, *http.Request)
	RecordsDelete(http.ResponseWriter, *http.Request)
	RecordsGet(http.ResponseWriter, *http.Request)
	RecordsPost(http.ResponseWriter, *http.Request)
	StatusActionPost(http.ResponseWriter, *http.Request)
	StatusGet(http.ResponseWriter, *http.Request)
}

DefaultAPIRouter defines the required methods for binding the api requests to a responses for the DefaultAPI The DefaultAPIRouter implementation should parse necessary information from the http request, pass the data to a DefaultAPIServicer to perform the required actions, then write the service results to the http response.

type DefaultAPIService

type DefaultAPIService struct {
}

DefaultAPIService is a service that implements the logic for the DefaultAPIServicer This service should implement the business logic for every endpoint for the DefaultAPI API. Include any external packages or services that will be required by this service.

func (*DefaultAPIService) GravityGet

func (s *DefaultAPIService) GravityGet(ctx context.Context) (ImplResponse, error)

GravityGet -

func (*DefaultAPIService) GravityIdDelete

func (s *DefaultAPIService) GravityIdDelete(ctx context.Context, id int32) (ImplResponse, error)

GravityIdDelete -

func (*DefaultAPIService) GravityPatch

func (s *DefaultAPIService) GravityPatch(ctx context.Context) (ImplResponse, error)

GravityPatch -

func (*DefaultAPIService) GravityPost

func (s *DefaultAPIService) GravityPost(ctx context.Context, gravityObj GravityObj) (ImplResponse, error)

GravityPost -

func (*DefaultAPIService) OverridesListGet

func (s *DefaultAPIService) OverridesListGet(ctx context.Context, list string) (ImplResponse, error)

func (*DefaultAPIService) RecordsDelete

func (s *DefaultAPIService) RecordsDelete(ctx context.Context, record DeleteRecord) (ImplResponse, error)

RecordsDelete

func (*DefaultAPIService) RecordsGet

func (s *DefaultAPIService) RecordsGet(ctx context.Context) (ImplResponse, error)

RecordsGet

func (*DefaultAPIService) RecordsPost

func (s *DefaultAPIService) RecordsPost(ctx context.Context, record Record) (ImplResponse, error)

RecordsPost

func (*DefaultAPIService) StatusActionPost

func (s *DefaultAPIService) StatusActionPost(ctx context.Context, action string) (ImplResponse, error)

StatusActionPost

func (*DefaultAPIService) StatusGet

func (s *DefaultAPIService) StatusGet(ctx context.Context) (ImplResponse, error)

StatusGet -

type DefaultAPIServicer

type DefaultAPIServicer interface {
	GravityGet(context.Context) (ImplResponse, error)
	GravityIdDelete(context.Context, int32) (ImplResponse, error)
	GravityPatch(context.Context) (ImplResponse, error)
	GravityPost(context.Context, GravityObj) (ImplResponse, error)
	OverridesListGet(context.Context, string) (ImplResponse, error)
	RecordsDelete(context.Context, DeleteRecord) (ImplResponse, error)
	RecordsGet(context.Context) (ImplResponse, error)
	RecordsPost(context.Context, Record) (ImplResponse, error)
	StatusActionPost(context.Context, string) (ImplResponse, error)
	StatusGet(context.Context) (ImplResponse, error)
}

DefaultAPIServicer defines the api actions for the DefaultAPI service This interface intended to stay up to date with the openapi yaml used to generate it, while the service implementation can be ignored with the .openapi-generator-ignore file and updated with the logic required for the API.

func NewDefaultAPIService

func NewDefaultAPIService() DefaultAPIServicer

NewDefaultAPIService creates a default api service

type DeleteRecord

type DeleteRecord struct {

	// CNAME or A
	Type string `json:"type"`

	// The domain to resolve
	Domain string `json:"domain"`
}

func (*DeleteRecord) UnmarshalJSON

func (m *DeleteRecord) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data while respecting defaults if specified.

type ErrorHandler

type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)

ErrorHandler defines the required method for handling error. You may implement it and inject this into a controller if you would like errors to be handled differently from the DefaultErrorHandler

type GravityObj

type GravityObj struct {
	Id int32 `json:"id,omitempty"`

	Address string `json:"address"`

	Comment string `json:"comment,omitempty"`
}

func (*GravityObj) UnmarshalJSON

func (m *GravityObj) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data while respecting defaults if specified.

type ImplResponse

type ImplResponse struct {
	Code int
	Body interface{}
}

ImplResponse defines an implementation response with error code and the associated body

func Response

func Response(code int, body interface{}) ImplResponse

Response return a ImplResponse struct filled

type Number

type Number interface {
	~int32 | ~int64 | ~float32 | ~float64
}

type Operation

type Operation[T Number | string | bool] func(actual string) (T, bool, error)

func WithDefaultOrParse

func WithDefaultOrParse[T Number | string | bool](def T, parse ParseString[T]) Operation[T]

func WithParse

func WithParse[T Number | string | bool](parse ParseString[T]) Operation[T]

func WithRequire

func WithRequire[T Number | string | bool](parse ParseString[T]) Operation[T]

type ParseString

type ParseString[T Number | string | bool] func(v string) (T, error)

type ParsingError

type ParsingError struct {
	Err error
}

ParsingError indicates that an error has occurred when parsing request parameters

func (*ParsingError) Error

func (e *ParsingError) Error() string

func (*ParsingError) Unwrap

func (e *ParsingError) Unwrap() error

type Record

type Record struct {

	// CNAME or A
	Type string `json:"type"`

	// The domain to resolve
	Domain string `json:"domain"`

	// The destination IP or DNS record
	Destination string `json:"destination"`
}

func (*Record) UnmarshalJSON

func (m *Record) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data while respecting defaults if specified.

type RequiredError

type RequiredError struct {
	Field string
}

RequiredError indicates that an error has occurred when parsing request parameters

func (*RequiredError) Error

func (e *RequiredError) Error() string

type Route

type Route struct {
	Method      string
	Pattern     string
	HandlerFunc http.HandlerFunc
}

A Route defines the parameters for an api endpoint

type Router

type Router interface {
	Routes() Routes
}

Router defines the required methods for retrieving api routes

func NewDefaultAPIController

func NewDefaultAPIController(s DefaultAPIServicer, opts ...DefaultAPIOption) Router

NewDefaultAPIController creates a default api controller

type Routes

type Routes map[string]Route

Routes is a map of defined api endpoints

type Status

type Status struct {
	Listening bool `json:"listening"`

	Ipv4 UdpTcp `json:"ipv4"`

	Ipv6 UdpTcp `json:"ipv6"`

	Blocking bool `json:"blocking"`
}

func (*Status) UnmarshalJSON

func (m *Status) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data while respecting defaults if specified.

type UdpTcp

type UdpTcp struct {
	Udp bool `json:"udp"`

	Tcp bool `json:"tcp"`
}

func (*UdpTcp) UnmarshalJSON

func (m *UdpTcp) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data while respecting defaults if specified.

Jump to

Keyboard shortcuts

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