cfg

package
Version: v0.0.0-...-f715ac0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package cfg contains the configuration and related global states.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Load

func Load(path string) error

Load a config file from path

Types

type AddrT

type AddrT struct {
	Host string
	Port int
	IPv6 bool
}

AddrT is an IP or hostname

func (*AddrT) String

func (a *AddrT) String() string

Get it as a string: host:port

type ConfigT

type ConfigT struct {
	ControlListen *AddrT
	DNSListen     *AddrT
	DNSForward    *AddrT
	HTTPListen    *AddrT
	HTTPSListen   *AddrT
	RootCert      string
	RootKey       string
	User          *UserT
	Chroot        string
	CacheHosts    int64
	CacheDNS      int64
	Color         bool
	Verbose       int

	// A list of the various sources; this only contains the hosts defined with
	// the "host" keyword in the config.
	Hostlists     [][]string
	Unhostlists   [][]string
	Regexplists   [][]string
	Unregexplists [][]string
	Hosts         []string
	Unhosts       []string
	Regexps       []string
	Unregexps     []string
	Surrogates    [][]string
}

ConfigT holds the configuration.

var Config ConfigT

Config of the application.

func (ConfigT) ChrootDir

func (c ConfigT) ChrootDir(path string) string

ChrootDir prefixes a path with the chroot dir.

func (*ConfigT) Compile

func (c *ConfigT) Compile()

Compile all the sources in one file, saves some memory and makes lookups a bit faster

func (*ConfigT) ReadHosts

func (c *ConfigT) ReadHosts()

ReadHosts the hosts information in to the various variables (Hosts, Regexps, etc.)

func (*ConfigT) ReadHostsLists

func (c *ConfigT) ReadHostsLists()

ReadHostsLists reads the hosts lists.

type HostList

type HostList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HostList is a static hosts added with hostlist/host. The key is the hostname, the (optional) value is a surrogate script to serve.

var (
	// Hosts are all the loaded hosts.
	Hosts HostList
)

func (*HostList) Add

func (l *HostList) Add(hosts ...string)

Add hosts.

func (*HostList) Dump

func (l *HostList) Dump(w io.Writer)

Dump all keys to the writer.

func (*HostList) Get

func (l *HostList) Get(k string) (string, bool)

Get a single item.

func (*HostList) Len

func (l *HostList) Len() int

Len returns the length of the map.

func (*HostList) Purge

func (l *HostList) Purge()

Purge the entire list

func (*HostList) Remove

func (l *HostList) Remove(hosts ...string)

Remove hosts.

func (*HostList) SetScript

func (l *HostList) SetScript(host, script string)

SetScript sets the surrogate script for a host.

type OverrideList

type OverrideList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

OverrideList are all the hosts the user told us to override.

The value is expiry timestamp.

var Override OverrideList

Override these hosts and regexps.

func (*OverrideList) Delete

func (l *OverrideList) Delete(keys ...string)

Delete items.

func (*OverrideList) Dump

func (l *OverrideList) Dump(w io.Writer)

Dump all keys to the writer.

func (*OverrideList) Get

func (l *OverrideList) Get(k string) (int64, bool)

Get a single item.

func (*OverrideList) Purge

func (l *OverrideList) Purge()

Purge the entire list

func (*OverrideList) Store

func (l *OverrideList) Store(k string, expire int64)

Store an item.

type RegexpList

type RegexpList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RegexpList is a list of all regexp blocks.

Pre-compiling the surrogate scripts isn't possible here.

var (
	// Regexps are all the loaded regexps.
	Regexps RegexpList
)

func (*RegexpList) Add

func (l *RegexpList) Add(regexps ...string)

Add regexps.

func (*RegexpList) Dump

func (l *RegexpList) Dump(w io.Writer)

Dump all keys to the writer.

func (*RegexpList) Len

func (l *RegexpList) Len() int

Len returns the length of the list.

func (*RegexpList) Match

func (l *RegexpList) Match(name string) bool

Match the name against all the regexps.

func (*RegexpList) Purge

func (l *RegexpList) Purge()

Purge the entire list

func (*RegexpList) Remove

func (l *RegexpList) Remove(regexps ...string)

Remove regexps.

type SurrogateEntry

type SurrogateEntry struct {
	*regexp.Regexp
	// contains filtered or unexported fields
}

SurrogateEntry will serve the script if the regexp matches.

type SurrogateList

type SurrogateList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

SurrogateList is the list of surrogate scripts to use.

var (
	// Surrogates are all the surrogate scripts.
	Surrogates SurrogateList
)

func (*SurrogateList) Add

func (l *SurrogateList) Add(scripts ...[]string)

Add new surrogates. The first list entry is the host regexp, the second the script.

func (*SurrogateList) Find

func (l *SurrogateList) Find(host string) (script string, success bool)

Find a surrogate.

func (*SurrogateList) Purge

func (l *SurrogateList) Purge()

Purge the entire list

type UserT

type UserT struct {
	user.User

	// the user.User.{Uid,Gid} are strings, not ints :-/
	UID int
	GID int
}

UserT is a system user

Jump to

Keyboard shortcuts

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