utils

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: GPL-3.0 Imports: 9 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FastRedirect

func FastRedirect(rw http.ResponseWriter, req *http.Request, url string, code int)

FastRedirect adds a location header, status code and if the method is get, outputs the status text.

func GetBearer

func GetBearer(req *http.Request) string

GetBearer returns the bearer from the Authorization header or an empty string if the authorization is empty or doesn't start with Bearer.

func GetDomainWithoutPort

func GetDomainWithoutPort(domain string) string

GetDomainWithoutPort takes an input domain + port and outputs the domain without the port.

example.com:443 => example.com

func GetParentDomain

func GetParentDomain(domain string) (string, bool)

GetParentDomain returns the parent domain stripping off the subdomain.

www.example.com => example.com

func GetTopFqdn

func GetTopFqdn(domain string) (string, bool)

GetTopFqdn returns the top domain stripping off multiple layers of subdomains.

hello.world.example.com => example.com

func ReplaceSubdomainWithWildcard

func ReplaceSubdomainWithWildcard(domain string) (string, bool)

ReplaceSubdomainWithWildcard returns the domain with the subdomain replaced with a wildcard '*' character.

www.example.com => *.example.com

func RespondHttpStatus

func RespondHttpStatus(rw http.ResponseWriter, status int)

RespondHttpStatus outputs the status code and text using http.Error()

func RespondVioletError

func RespondVioletError(rw http.ResponseWriter, status int, msg string)

func RunBackgroundHttp

func RunBackgroundHttp(logger *log.Logger, s *http.Server)

RunBackgroundHttp runs a http server and logs when the server closes or errors.

func RunBackgroundHttps

func RunBackgroundHttps(logger *log.Logger, s *http.Server)

RunBackgroundHttps runs a http server with TLS encryption and logs when the server closes or errors.

func SplitDomainPort

func SplitDomainPort(host string, defaultPort int) (domain string, port int, ok bool)

SplitDomainPort takes an input host and default port then outputs the domain, port and true or empty values and false if the split failed

func SplitHostPath

func SplitHostPath(a string) (host, path string)

SplitHostPath extracts the host/path from the input

func SplitHostPathQuery

func SplitHostPathQuery(a string) (host, path, query string)

SplitHostPathQuery extracts the host/path?query from the input

Types

type AcmeChallengeProvider

type AcmeChallengeProvider interface {
	Get(domain, key string) string
	Put(domain, key, value string)
	Delete(domain, key string)
}

type AcmeChallenges

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

func NewAcmeChallenge

func NewAcmeChallenge() *AcmeChallenges

func (*AcmeChallenges) Delete

func (a *AcmeChallenges) Delete(domain, key string)

func (*AcmeChallenges) Get

func (a *AcmeChallenges) Get(domain, key string) string

func (*AcmeChallenges) Put

func (a *AcmeChallenges) Put(domain, key, value string)

type AcmeStorage

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

type CertProvider

type CertProvider interface {
	GetCertForDomain(domain string) *tls.Certificate
	Compile()
}

type Compilable

type Compilable interface {
	Compile()
}

Compilable is an interface for structs with an asynchronous compile method.

type DomainProvider

type DomainProvider interface {
	IsValid(host string) bool
	Put(domain string, active bool)
	Delete(domain string)
	Compile()
}

type MultiCompilable

type MultiCompilable []Compilable

MultiCompilable is a slice of multiple Compilable interfaces.

func (MultiCompilable) Compile

func (m MultiCompilable) Compile()

Compile loops over the slice of Compilable interfaces and calls Compile on each one.

Directories

Path Synopsis
Package fake contains fake structs used during tests
Package fake contains fake structs used during tests

Jump to

Keyboard shortcuts

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