xhttp

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: AGPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTokenFromRequest

func ExtractTokenFromRequest(r *http.Request) (string, bool)

func JSONResponse

func JSONResponse(w http.ResponseWriter, closure func() (interface{}, error))

JSONResponse calls the closure and respond with data or error. If no error, but the interface is nil it will write "OK" to the response writer.

func WriteData

func WriteData(w http.ResponseWriter, data []byte)

func WriteJsonError

func WriteJsonError(w http.ResponseWriter, err error)

Types

type DomainConfig

type DomainConfig struct {
	Mode     string `yaml:"mode" valid:"required"`
	Name     string `yaml:"name" valid:"dns,required"`
	IssueSSL bool   `yaml:"issue_ssl,omitempty"`
	Schema   string `yaml:"schema,omitempty"`

	// Dir to store cached certificates, use sub-directory of cfgDir if possible.
	Dir string `yaml:"dir,omitempty" valid:"path"`
}

DomainConfig is the YAML version of the `adminAPI.DomainConfig` struct.

func (*DomainConfig) Validate

func (c *DomainConfig) Validate() error

type Issuer

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

Issuer should be named like certManager

func NewIssuer

func NewIssuer(opts IssuerOpts) (*Issuer, error)

func (*Issuer) TLSConfig

func (is *Issuer) TLSConfig() (*tls.Config, error)

TLSConfig issues new certificate via LE or loads one from a cache, if any. Returns TLS config for the http.Server using the issued cert.

type IssuerOpts

type IssuerOpts struct {
	Domain   string
	CacheDir string
	Email    string

	// Router of the http (not https!) server
	Router chi.Router
	// Restart callback fired when the valid certificate issued;
	// accepts the configuration of the new cert.
	Callback func(c *tls.Config)
}

type Middleware

type Middleware = func(http.Handler) http.Handler

type Option

type Option func(w *Server)

func WithCORS

func WithCORS() Option

func WithLogger

func WithLogger() Option

func WithMetrics

func WithMetrics() Option

func WithMiddleware

func WithMiddleware(mw Middleware) Option

func WithSSL

func WithSSL(cfg *tls.Config) Option

type SSLConfig

type SSLConfig struct {
	// ListenAddr for HTTPS server, default: ":443"
	ListenAddr string `yaml:"listen_addr" valid:"listen_addr,required"`
}

type Server

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

func New

func New(opts ...Option) *Server

func NewDefault

func NewDefault() *Server

func NewDefaultSSL

func NewDefaultSSL(cfg *tls.Config) *Server

func NewRedirectToSSL

func NewRedirectToSSL(toHost string) *Server

func (*Server) Router

func (w *Server) Router() chi.Router

Router exposes chi.Router for the external registration of handlers. usage:

h.Router().Get("/apt/path", myHandler)
h.Router().Post("/apt/verb", myOtherHandler)

func (*Server) Run

func (w *Server) Run(addr string) error

Run starts the http server asynchronously.

func (*Server) Running

func (w *Server) Running() bool

func (*Server) Shutdown

func (w *Server) Shutdown() error

Jump to

Keyboard shortcuts

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