util

package
v0.0.0-...-83625b3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2018 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildLink(r *http.Request, path string, query map[string]string) *url.URL

BuildLink buils a link from the current request.

func CreateCipher

func CreateCipher(key []byte) (cipher.AEAD, error)

func Decrypt

func Decrypt(aeadCipher cipher.AEAD, msg []byte) ([]byte, error)

func DecryptString

func DecryptString(aeadCipher cipher.AEAD, msg string) (string, error)

func Encrypt

func Encrypt(aeadCipher cipher.AEAD, msg []byte) []byte

func EncryptString

func EncryptString(aeadCipher cipher.AEAD, msg string) string

func GenerateCertificate

func GenerateCertificate(host, organization string) (string, string)

GenerateCertificate generates a cerificate for a host.

The first return value is the ceritificate, the second is the key. Both are PEM encoded.

func GenerateKey

func GenerateKey() string

GenerateKey generates an RSA key (2048 bit) and encodes it using PEM.

func GeneratePlaceholders

func GeneratePlaceholders(start, end uint) string

GeneratePlaceholders generates placeholders from start to end for an SQL query.

func GetPublicKey

func GetPublicKey(key *rsa.PrivateKey) string

GetPublicKey gets the public part of a private key in OpenSSL format.

func MarshalPrivateKey

func MarshalPrivateKey(key *rsa.PrivateKey) []byte

MarshalPrivateKey converts a private key to a PEM encoded string.

func RandomSecret

func RandomSecret(length int) string

RandomSecret generates a random secret of length bytes long.

The returned data will be hex encoded, so it will be length*2 characters.

func RandomString

func RandomString(length int) string

RandomString generates a random string of a given length.

func RedirectDestination

func RedirectDestination(r *http.Request) string

RedirectDestination constucts an URL to the redirect destination.

The redirect destination is read from the destination URL parameter.

func ResponseBodyToString

func ResponseBodyToString(r *http.Response) string

ResponseBodyToString reads the whole response body and converts it to a string.

func SetContext

func SetContext(r *http.Request, key, value interface{}) *http.Request

SetContext sets a value in the context of *http.Request, and returns a new one with the updated context.

func StringSliceToInterfaceSlice

func StringSliceToInterfaceSlice(s []string) []interface{}

StringSliceToInterfaceSlice converts a string slice into an interface{} slice.

func StripTerminalColorCodes

func StripTerminalColorCodes(s string) string

func TestServerAddress

func TestServerAddress() string

func UUIDSliceToInterface

func UUIDSliceToInterface(s []uuid.UUID) []interface{}

func UnmarshalPrivateKey

func UnmarshalPrivateKey(key []byte) *rsa.PrivateKey

UnmarshalPrivateKey converts a PEM encoded string into a private key.

Returns nil on failure.

Types

type ResponseWriterWrapper

type ResponseWriterWrapper struct {
	http.ResponseWriter
}

func (ResponseWriterWrapper) Flush

func (w ResponseWriterWrapper) Flush()

func (ResponseWriterWrapper) Hijack

func (ResponseWriterWrapper) Push

func (w ResponseWriterWrapper) Push(target string, opts *http.PushOptions) error

Jump to

Keyboard shortcuts

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