utils

package module
v0.2.11 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 23 Imported by: 45

README

WebTeleport Utils

go.dev reference License

Documentation

Index

Constants

View Source
const NOT_FOUND_TEMPLATE = `Not found: {{.Host}}`
View Source
const WellKnownHealthPath = "/.well-known/health"

Variables

View Source
var AllowAllCorsMiddleware = func(next http.Handler) http.Handler {
	return cors.AllowAll().Handler(next)
}
View Source
var GzipMiddleware = handlers.CompressHandler

Functions

func AsURL added in v0.2.4

func AsURL(s string) string

AsURL expands :port and hostname to http://localhost:port & http://hostname respectively

func CompactHeadersMiddleware added in v0.0.5

func CompactHeadersMiddleware(next http.Handler, keys []string) http.Handler

func EnvAltSvc added in v0.0.4

func EnvAltSvc(fallback string) string

func EnvCert added in v0.0.4

func EnvCert(fallback string) string

func EnvHTTPPort added in v0.2.7

func EnvHTTPPort(fallback string) string

func EnvHost added in v0.0.4

func EnvHost(fallback string) string

func EnvKey added in v0.0.4

func EnvKey(fallback string) string

func EnvPort added in v0.0.4

func EnvPort(fallback string) string

func EnvUDPPort added in v0.0.6

func EnvUDPPort(fallback string) string

func EnvUI added in v0.0.4

func EnvUI(fallback string) string

func ExtractURLPort

func ExtractURLPort(u *url.URL) string

ExtractURLPort returns the :port part from URL.Host (host[:port])

An empty string is returned if no port is found

func Formatter added in v0.0.7

func Formatter(writer io.Writer, params handlers.LogFormatterParams)

func GinLoggerMiddleware added in v0.1.0

func GinLoggerMiddleware(next http.Handler) http.Handler

func Graft

func Graft(base, alt string) string

Graft returns Host(base):Port(alt)

assuming - base is host[:port] - alt is [host]:port

func HostNotFoundHandler added in v0.0.7

func HostNotFoundHandler() http.Handler
func Hyperlink(name, url string) string

Print Hyperlink via OSC 8 ansi sequence. The syntax is: 'OSC 8 ; params ; url ST text OSC 8 ; ; ST' for more info see https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda

func InterceptMiddleware added in v0.1.4

func InterceptMiddleware(next http.Handler) http.Handler

InterceptMiddleware prints request & response info to stdout

func Isatty added in v0.1.8

func Isatty() bool

func Jupyter added in v0.0.7

func Jupyter(next http.Handler) http.Handler

VSCode web edition makes cors request to /hub/api endpoint in order to determine if the backend api is a JupyterHub or JupyterLab/JupyterServer

If the Access-Control-Allow-Origin header is absent, the request will not make through. Here we add this header to make VSCode web happy

Tested on: - github.dev - vscode.dev - insider.vscode.dev

Needs to have Jupyter extension installed

- /login is used to check if server has authentication enabled - /hub/api is used to check if server is JupyterHub

with authentication disabled, the /login endpoint won't respond with cors header so we need to manually add it to make vscode-web happy

jupyter server doesn't have the /hub/api endpoint, so the same hack needs to be applied

func LoggingMiddleware added in v0.0.7

func LoggingMiddleware(next http.Handler) http.Handler

func LookupEnv added in v0.0.7

func LookupEnv(key string) *string

func LookupEnvPort added in v0.0.7

func LookupEnvPort(key string) *string

func LookupHostTXT added in v0.1.8

func LookupHostTXT(domain, server string) ([]string, error)
func MaybeHyperlink(l string) string

MaybeHyperlink turns input into ANSI hyperlink when stdin is a tty

func ParseBasicAuth added in v0.1.6

func ParseBasicAuth(auth string) (username, password string, ok bool)

func ParseDomainCandidates added in v0.0.8

func ParseDomainCandidates(p string) []string

ParseDomainCandidates splits a path string like /a/b/cd/😏 into a list of subdomains: [a, b, cd, 😏]

when result is empty, a random subdomain will be assigned by the server

func ReverseProxy added in v0.0.7

func ReverseProxy(addr string) http.Handler

ReverseProxy

func ReverseProxyLogger added in v0.2.11

func ReverseProxyLogger() *log.Logger

func ToIdna

func ToIdna(s string) string

ToIdna converts a string to its idna form at best effort Should only be used on the hostname part without port

func UnwrapInnermost added in v0.2.6

func UnwrapInnermost(err error) error

func WellKnownHealthMiddleware added in v0.0.7

func WellKnownHealthMiddleware(next http.Handler) http.Handler

Types

type AugmentedHandler added in v0.0.7

type AugmentedHandler interface {
	http.Handler
	PkgPath() string
}

type Body added in v0.1.4

type Body struct {
	io.ReadCloser
	Writer io.Writer
}

func (*Body) Read added in v0.1.4

func (b *Body) Read(p []byte) (int, error)

type GinLogger added in v0.1.0

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

func (*GinLogger) ServeHTTP added in v0.1.0

func (m *GinLogger) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Interceptor added in v0.1.4

type Interceptor struct {
	http.ResponseWriter
	StatusCode int
}

func (*Interceptor) Flush added in v0.1.7

func (w *Interceptor) Flush()

func (*Interceptor) Hijack added in v0.1.6

func (w *Interceptor) Hijack() (net.Conn, *bufio.ReadWriter, error)

func (*Interceptor) WriteHeader added in v0.1.4

func (w *Interceptor) WriteHeader(statusCode int)

type LogFormatter added in v0.1.0

type LogFormatter func(params LogFormatterParams) string

type LogFormatterParams added in v0.1.0

type LogFormatterParams struct {
	Request      *http.Request
	TimeStamp    time.Time
	StatusCode   int
	Latency      time.Duration
	ClientIP     string
	Host         string
	Method       string
	Proto        string
	Path         string
	ErrorMessage string
	BodySize     int
	Keys         map[string]interface{}
}

func (*LogFormatterParams) IsOutputColor added in v0.1.0

func (p *LogFormatterParams) IsOutputColor() bool

func (*LogFormatterParams) MethodColor added in v0.1.0

func (p *LogFormatterParams) MethodColor() string

func (*LogFormatterParams) ResetColor added in v0.1.0

func (p *LogFormatterParams) ResetColor() string

func (*LogFormatterParams) StatusCodeColor added in v0.1.0

func (p *LogFormatterParams) StatusCodeColor() string

type LogWriter added in v0.1.0

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

func (*LogWriter) Write added in v0.1.0

func (lw *LogWriter) Write(p []byte) (n int, err error)

type NotFoundData added in v0.0.7

type NotFoundData struct {
	Host string
}

Directories

Path Synopsis
hack

Jump to

Keyboard shortcuts

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