Documentation ¶
Index ¶
- Constants
- Variables
- func AssertDeleteRecordConstraints(obj DeleteRecord) error
- func AssertDeleteRecordRequired(obj DeleteRecord) error
- func AssertGravityObjConstraints(obj GravityObj) error
- func AssertGravityObjRequired(obj GravityObj) error
- func AssertRecordConstraints(obj Record) error
- func AssertRecordRequired(obj Record) error
- func AssertRecurseInterfaceRequired[T any](obj interface{}, callback func(T) error) error
- func AssertRecurseValueRequired[T any](value reflect.Value, callback func(T) error) error
- func AssertStatusConstraints(obj Status) error
- func AssertStatusRequired(obj Status) error
- func AssertUdpTcpConstraints(obj UdpTcp) error
- func AssertUdpTcpRequired(obj UdpTcp) error
- func DefaultErrorHandler(w http.ResponseWriter, r *http.Request, err error, result *ImplResponse)
- func EncodeJSONResponse(i interface{}, status *int, w http.ResponseWriter) error
- func IsZeroValue(val interface{}) bool
- func Logger(inner http.Handler, name string) http.Handler
- func NewRouter(routers ...Router) *mux.Router
- func ReadFormFileToTempFile(r *http.Request, key string) (*os.File, error)
- func ReadFormFilesToTempFiles(r *http.Request, key string) ([]*os.File, error)
- type Constraint
- type DefaultAPIController
- func (c *DefaultAPIController) GravityGet(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) GravityIdDelete(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) GravityPatch(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) GravityPost(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) OverridesListGet(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) RecordsDelete(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) RecordsGet(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) RecordsPost(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) Routes() Routes
- func (c *DefaultAPIController) StatusActionPost(w http.ResponseWriter, r *http.Request)
- func (c *DefaultAPIController) StatusGet(w http.ResponseWriter, r *http.Request)
- type DefaultAPIOption
- type DefaultAPIRouter
- type DefaultAPIService
- func (s *DefaultAPIService) GravityGet(ctx context.Context) (ImplResponse, error)
- func (s *DefaultAPIService) GravityIdDelete(ctx context.Context, id int32) (ImplResponse, error)
- func (s *DefaultAPIService) GravityPatch(ctx context.Context) (ImplResponse, error)
- func (s *DefaultAPIService) GravityPost(ctx context.Context, gravityObj GravityObj) (ImplResponse, error)
- func (s *DefaultAPIService) OverridesListGet(ctx context.Context, list string) (ImplResponse, error)
- func (s *DefaultAPIService) RecordsDelete(ctx context.Context, record DeleteRecord) (ImplResponse, error)
- func (s *DefaultAPIService) RecordsGet(ctx context.Context) (ImplResponse, error)
- func (s *DefaultAPIService) RecordsPost(ctx context.Context, record Record) (ImplResponse, error)
- func (s *DefaultAPIService) StatusActionPost(ctx context.Context, action string) (ImplResponse, error)
- func (s *DefaultAPIService) StatusGet(ctx context.Context) (ImplResponse, error)
- type DefaultAPIServicer
- type DeleteRecord
- type ErrorHandler
- type GravityObj
- type ImplResponse
- type Number
- type Operation
- type ParseString
- type ParsingError
- type Record
- type RequiredError
- type Route
- type Router
- type Routes
- type Status
- type UdpTcp
Constants ¶
const CNAME_FILE = "/etc/dnsmasq.d/05-pihole-custom-cname.conf"
const EMPTY_LIST = "Not showing empty list"
const LIST_REGEX = `\d: (.+) \((.*), last modified (.*)\)$`
const PIHOLE_EXECUTABLE = "/usr/local/bin/pihole"
const SQLLITE_DATABASE = "/etc/pihole/gravity.db"
const SQLLITE_EXECUTABLE = "/usr/bin/sqlite3"
const TYPEA_FILE = "/etc/pihole/custom.list"
Variables ¶
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 ¶
AssertRecordConstraints checks if the values respects the defined constraints
func AssertRecordRequired ¶
AssertRecordRequired checks if the required fields are not zero-ed
func AssertRecurseInterfaceRequired ¶
AssertRecurseInterfaceRequired recursively checks each struct in a slice against the callback. This method traverse nested slices in a preorder fashion.
func AssertRecurseValueRequired ¶
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 ¶
AssertStatusConstraints checks if the values respects the defined constraints
func AssertStatusRequired ¶
AssertStatusRequired checks if the required fields are not zero-ed
func AssertUdpTcpConstraints ¶
AssertUdpTcpConstraints checks if the values respects the defined constraints
func AssertUdpTcpRequired ¶
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 ReadFormFileToTempFile ¶
ReadFormFileToTempFile reads file data from a request form and writes it to a temporary file
Types ¶
type Constraint ¶
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 Operation ¶
func WithDefaultOrParse ¶
func WithDefaultOrParse[T Number | string | bool](def T, parse ParseString[T]) Operation[T]
func WithRequire ¶
func WithRequire[T Number | string | bool](parse ParseString[T]) Operation[T]
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 ¶
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