utils

package
v0.0.0-...-08f68e1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RANDOM_SUBDOMAIN_LENGTH = 6
	CONNECTION_ID_LENGTH    = 10
	SECRET_KEY_LENGTH       = 32
	SESSION_ID_LENGTH       = 16

	NANOID_ALPHABETS = "abcdefghijklmnopqrstuvwxyz0123456789"
)

Variables

View Source
var (
	ErrPasswordNotLongEnough = errors.New("password must be atleast 6 chars long")
	ErrInvalidSubdomain      = errors.New("subdomain must contain only a-z, 0-9 and `-`(not leading or trailing)")
)

Functions

func GenerateConnectionId

func GenerateConnectionId() string

func GenerateRandomSubdomain

func GenerateRandomSubdomain() string

func GenerateSecretKey

func GenerateSecretKey() string

func GenerateSessionToken

func GenerateSessionToken() string

func HttpBadRequest

func HttpBadRequest(c echo.Context, format string, args ...interface{}) error

func HttpUnauthorized

func HttpUnauthorized(c echo.Context, format string, args ...interface{}) error

func ProxyError

func ProxyError(c echo.Context, err error) error

ProxyError log error and return a HTTP 526 error with the message

func ProxyErrorf

func ProxyErrorf(c echo.Context, format string, args ...interface{}) error

ProxyErrorf log error and return a HTTP 526 error with the message

func SanitizeString

func SanitizeString(value string) string

Remove any leading or trailing whitespace

func UnserializeHTTPRequest

func UnserializeHTTPRequest(req *HTTPRequest) (r *http.Request, err error)

UnserializeHTTPRequest create a new http.Request from a HTTPRequest

func ValidateEmail

func ValidateEmail(input string) error

func ValidatePassword

func ValidatePassword(input string) error

func ValidateSubdomain

func ValidateSubdomain(subdomain string) error

Types

type HTTPRequest

type HTTPRequest struct {
	Method        string
	URL           string
	Header        map[string][]string
	ContentLength int64
}

HTTPRequest is a serializable version of http.Request ( with only usefull fields )

func SerializeHTTPRequest

func SerializeHTTPRequest(req *http.Request) (r *HTTPRequest)

SerializeHTTPRequest create a new HTTPRequest from a http.Request

type HTTPResponse

type HTTPResponse struct {
	StatusCode    int
	Header        http.Header
	ContentLength int64
}

HTTPResponse is a serializable version of http.Response ( with only useful fields )

func NewHTTPResponse

func NewHTTPResponse() (r *HTTPResponse)

NewHTTPResponse creates a new HTTPResponse

func SerializeHTTPResponse

func SerializeHTTPResponse(resp *http.Response) *HTTPResponse

SerializeHTTPResponse create a new HTTPResponse from a http.Response

Jump to

Keyboard shortcuts

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