Documentation ¶
Index ¶
- Variables
- func ParseRecord(str string, w http.ResponseWriter, req *http.Request, c Config) (record, error)
- func ParseURI(uri string, w http.ResponseWriter, r *http.Request, c Config) string
- func Redirect(w http.ResponseWriter, r *http.Request, c Config) error
- func UpstreamZone(r *http.Request) string
- type Config
- type Dockerv2
- type Fallback
- type Git
- type Gometa
- type Host
- type Image
- type Path
- type Prometheus
- type Proxy
- type ProxyResponse
- type Qr
- type RegexRecord
- type TXTDirect
Constants ¶
This section is empty.
Variables ¶
var ( // RequestsCount counts the total requests per host RequestsCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "txtdirect", Name: "redirect_count_total", Help: "Total requests per host", }, []string{"host"}) // RequestsByStatus counts the total returned statuses per host RequestsByStatus = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "txtdirect", Name: "redirect_status_count_total", Help: "Total returned statuses per host", }, []string{"host", "status"}) // RequestsCountBasedOnType counts the total requests for each host based on type RequestsCountBasedOnType = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "txtdirect", Name: "redirect_type_count_total", Help: "Total requests for each host based on type", }, []string{"host", "type"}) // FallbacksCount counts the total fallbacks triggered for each type FallbacksCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "txtdirect", Name: "fallback_type_count_total", Help: "Total fallbacks triggered for each type", }, []string{"host", "type", "fallback"}) // PathRedirectCount counts the total redirects per path for each host PathRedirectCount = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "txtdirect", Name: "redirect_path_count_total", Help: "Total redirects per path for each host", }, []string{"host", "path"}) )
var FromRegex = regexp.MustCompile("\\/\\$(\\d+)")
FromRegex parses the from= field
var GroupOrderRegex = regexp.MustCompile("P<([a-zA-Z]+[a-zA-Z0-9]*)>")
GroupOrderRegex finds the order of regex groups inside re=
var GroupRegex = regexp.MustCompile("P<[a-zA-Z]+[a-zA-Z0-9]*>")
GroupRegex parses the re= field to find the regex groups
var PathRegex = regexp.MustCompile("\\/([A-Za-z0-9-._~!$'()*+,;=:@]+)")
PathRegex is the default regex to parse request's path It can be replaced using the re= field in the records
var PlaceholderRegex = regexp.MustCompile("{[~>?]?\\w+}")
PlaceholderRegex finds the placeholders like {x}
Functions ¶
func ParseRecord ¶ added in v0.4.0
ParseRecord takes a string containing the DNS TXT record and returns a TXTDirect record struct instance. It will return an error if the DNS TXT record is not standard or if the record type is not enabled in the TXTDirect's config.
func ParseURI ¶ added in v0.3.0
ParseURI parses the given URI and triggers fallback if the URI isn't valid
func UpstreamZone ¶ added in v0.4.1
Types ¶
type Config ¶
type Config struct { Enable []string Redirect string Resolver string LogOutput string Prometheus Prometheus Qr Qr }
Config contains the middleware's configuration
func ParseConfig ¶ added in v0.4.0
func ParseConfig(c *caddy.Controller) (Config, error)
type Dockerv2 ¶ added in v0.3.0
type Dockerv2 struct {
// contains filtered or unexported fields
}
Dockerv2 keeps data for "dockerv2" type requests
func NewDockerv2 ¶ added in v0.3.0
NewDockerv2 returns a fresh instance of Dockerv2 struct
func (*Dockerv2) ParseRecordReference ¶ added in v0.5.1
func (*Dockerv2) ParseReference ¶ added in v0.5.1
type Fallback ¶ added in v0.3.0
type Fallback struct {
// contains filtered or unexported fields
}
Fallback keeps the data necessary for the fallback flow
type Git ¶ added in v0.4.0
type Git struct {
// contains filtered or unexported fields
}
Git keeps data for "git" type requests
func (*Git) ValidGitQuery ¶ added in v0.4.0
ValidGitQuery checks the User-Agent header to make sure the requests are coming from a Git client.
type Gometa ¶ added in v0.3.0
type Gometa struct {
// contains filtered or unexported fields
}
Gometa keeps data for "gometa" type requests
func (*Gometa) Serve ¶ added in v0.3.0
Serve executes a template on the given ResponseWriter that contains go-import meta tag
func (*Gometa) ValidQuery ¶ added in v0.3.0
ValidQuery checks the request query to make sure the requests are coming from the Go tool.
type Host ¶ added in v0.3.0
type Host struct {
// contains filtered or unexported fields
}
Host keeps data for "host" type requests
type Path ¶ added in v0.3.0
type Path struct {
// contains filtered or unexported fields
}
Path contains the data that are needed to redirect path requests
func (*Path) Redirect ¶ added in v0.3.0
func (p *Path) Redirect() *record
Redirect finds and returns the final record
func (*Path) RedirectRoot ¶ added in v0.3.0
RedirectRoot redirects the request to record's root= field if the path is empty or "/". If the root= field is empty too fallback will be triggered.
func (*Path) SpecificRecord ¶ added in v0.4.0
SpecificRecord finds the most specific match using the custom regexes from subzones It goes through all the custom regexes specified in each subzone and uses the most specific match to return the final record.
type Prometheus ¶ added in v0.3.0
type Prometheus struct { Enable bool Address string Path string PathWhitelist []string // contains filtered or unexported fields }
Prometheus contains Prometheus's configuration
func (*Prometheus) ParsePrometheus ¶ added in v0.3.0
func (p *Prometheus) ParsePrometheus(c *caddy.Controller, key, value string) error
ParsePrometheus parses the txtdirect config for Prometheus
func (*Prometheus) ServeHTTP ¶ added in v0.3.0
func (p *Prometheus) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
func (*Prometheus) SetDefaults ¶ added in v0.3.0
func (p *Prometheus) SetDefaults()
SetDefaults sets the default values for prometheus config if the fields are empty
func (*Prometheus) Setup ¶ added in v0.3.0
func (p *Prometheus) Setup(c *caddy.Controller)
Setup registers the metrics on startup and creates the promethues request handler
type Proxy ¶ added in v0.3.0
type Proxy struct {
// contains filtered or unexported fields
}
Proxy contains the data that are needed to proxy the request
type ProxyResponse ¶ added in v0.3.0
type ProxyResponse struct {
// contains filtered or unexported fields
}
ProxyResponse keeps the custom response writer data and is a custom implementation of net/http's default response writer
func (*ProxyResponse) Body ¶ added in v0.3.0
func (p *ProxyResponse) Body() []byte
Body returns response's body. This method should only get called after WriteBody()
func (*ProxyResponse) Header ¶ added in v0.3.0
func (p *ProxyResponse) Header() http.Header
Header returns response headers
func (*ProxyResponse) ReplaceBody ¶ added in v0.3.0
func (p *ProxyResponse) ReplaceBody(scheme, to, host string) error
ReplaceBody replaces the URIs inside the response body to use the request's host instead of the endpoint's host
func (*ProxyResponse) Write ¶ added in v0.3.0
func (p *ProxyResponse) Write(body []byte) (int, error)
func (*ProxyResponse) WriteBody ¶ added in v0.3.0
func (p *ProxyResponse) WriteBody() error
WriteBody writes the response body to custom response writer's body
func (*ProxyResponse) WriteHeader ¶ added in v0.3.0
func (p *ProxyResponse) WriteHeader(status int)
WriteHeader Writes the given status code to response
type Qr ¶ added in v0.3.0
type Qr struct { Enable bool Size int BackgroundColor string ForegroundColor string RecoveryLevel qrcode.RecoveryLevel // contains filtered or unexported fields }
Qr contains Qr code generator's configuration
func (*Qr) ParseColors ¶ added in v0.3.0
ParseColors parses the hex colors in the QR config to color.Color instances
func (*Qr) ParseQr ¶ added in v0.3.0
func (qr *Qr) ParseQr(c *caddy.Controller) error
ParseQr parses the config for QR requests
func (*Qr) SetDefaults ¶ added in v0.3.0
func (qr *Qr) SetDefaults()
SetDefaults sets the default values for QR config
type RegexRecord ¶ added in v0.4.0
RegexRecord holds the TXT record and re= field of a predefined regex record
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package txtdirectmain contains the functions for starting TXTDirect.
|
Package txtdirectmain contains the functions for starting TXTDirect. |