pihole

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2022 License: MIT Imports: 8 Imported by: 0

README

go-pihole

A Golang Pi-hole client

Requires Pi-hole Web Interface >= 5.11

Usage

import "github.com/ryanwholey/go-pihole"

client := pihole.New(pihole.Config{
	BaseURL:  "http://pi.hole"
	APIToken: "8c4e081d..."
})

record, err := client.LocalDNS.Create(context.Background(), "my-domain.com", "127.0.0.1")
if err != nil {
	log.Fatal(err)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClientValidation = errors.New("invalid client configuration")
View Source
var (
	ErrorLocalCNAMENotFound = errors.New("local CNAME record not found")
)
View Source
var (
	ErrorLocalDNSNotFound = errors.New("local dns record not found")
)

Functions

This section is empty.

Types

type AdBlocker added in v0.0.4

type AdBlocker interface {
	// Get returns the ad blocker status
	Get(ctx context.Context) (*AdBlockerStatus, error)

	// Update updates the ad blocker status (enabled, disabled)
	Update(ctx context.Context, opts AdBlockerStatusOptions) (*AdBlockerStatus, error)
}

type AdBlockerStatus added in v0.0.4

type AdBlockerStatus struct {
	Enabled bool
}

AdBlockerStatus is an object representing the ad blocker status

type AdBlockerStatusOptions added in v0.0.4

type AdBlockerStatusOptions struct {
	Enabled         bool
	DisabledSeconds int
}

type CNAMERecord

type CNAMERecord struct {
	Domain string
	Target string
}

type CNAMERecordList

type CNAMERecordList []CNAMERecord

type Client

type Client struct {
	LocalDNS   LocalDNS
	LocalCNAME LocalCNAME
	AdBlocker  AdBlocker
	Version    Version
	// contains filtered or unexported fields
}

func New

func New(config Config) *Client

New returns a new Pi-hole client

func (Client) Request

func (c Client) Request(ctx context.Context, vals url.Values) (*http.Request, error)

func (Client) Validate added in v0.0.3

func (c Client) Validate() error

type ComponentVersions added in v0.0.4

type ComponentVersions struct {
	CoreUpdate  bool   `json:"core_update,omitempty"`
	WebUpdate   bool   `json:"web_update,omitempty"`
	FTLUpdate   bool   `json:"FTL_update,omitempty"`
	CoreCurrent string `json:"core_current,omitempty"`
	WebCurrent  string `json:"web_current,omitempty"`
	FTLCurrent  string `json:"FTL_current,omitempty"`
	CoreLatest  string `json:"core_latest,omitempty"`
	WebLatest   string `json:"web_latest,omitempty"`
	FTLLatest   string `json:"FTL_latest,omitempty"`
	CoreBranch  string `json:"core_branch,omitempty"`
	WebBranch   string `json:"web_branch,omitempty"`
	FTLBranch   string `json:"FTL_branch,omitempty"`
}

type Config

type Config struct {
	BaseURL    string
	APIToken   string
	HttpClient *http.Client
	Headers    http.Header
}

type DNSRecord

type DNSRecord struct {
	IP     string
	Domain string
}

type DNSRecordList

type DNSRecordList []DNSRecord

type LocalCNAME added in v0.0.3

type LocalCNAME interface {
	// List all CNAME records.
	List(ctx context.Context) (CNAMERecordList, error)

	// Create a CNAME record.
	Create(ctx context.Context, domain string, target string) (*CNAMERecord, error)

	// Get a CNAME record by its domain.
	Get(ctx context.Context, domain string) (*CNAMERecord, error)

	// Delete a CNAME record by its domain.
	Delete(ctx context.Context, domain string) error
}

type LocalDNS added in v0.0.3

type LocalDNS interface {
	// List all DNS records.
	List(ctx context.Context) (DNSRecordList, error)

	// Create a DNS record.
	Create(ctx context.Context, domain string, IP string) (*DNSRecord, error)

	// Get a DNS record by its domain.
	Get(ctx context.Context, domain string) (*DNSRecord, error)

	// Delete a DNS record by its domain.
	Delete(ctx context.Context, domain string) error
}

type Version added in v0.0.4

type Version interface {
	// Get returns the Pi-hole server component versions
	Get(ctx context.Context) (*ComponentVersions, error)
}

Jump to

Keyboard shortcuts

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