ut

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 22 Imported by: 0

README

utgo - Go utilities

pkg goreportcard workflow codecov

Documentation

Overview

Package ut provides functions that are commonly needed in multiple projects and packages.

Index

Constants

View Source
const (
	// EmptyString empty string
	EmptyString = ""

	// TestString test
	TestString = "test"
	// TestStringInitialCapitalized Test
	TestStringInitialCapitalized = "Test"
)
View Source
const (
	// Ten 10
	Ten = 10

	// SixtyFour 64
	SixtyFour = 64
)
View Source
const (
	// SecondsPerHour = 60 * 60
	SecondsPerHour = 60 * 60
	// SecondsPerDay = 60 * 60 * 24
	SecondsPerDay = 60 * 60 * 24
	// MinutesPerDay = 60 * 24
	MinutesPerDay = 60 * 24
)
View Source
const (
	// Ki = 1024
	Ki = 1024
	// Mi = Ki * 1024
	Mi = Ki * 1024
	// Gi = Mi * 1024
	Gi = Mi * 1024
	// Ti = Gi * 1024
	Ti = Gi * 1024
)
View Source
const (
	// CryptographicKeyDigit2048 2048
	CryptographicKeyDigit2048 = 2048
	// CryptographicKeyDigit4096 4096
	CryptographicKeyDigit4096 = 4096
	// CryptographicKeyDigit8192 8192
	CryptographicKeyDigit8192 = 8192
)

Variables

View Source
var (
	// UnixTimeZero is zero value of Unix Time. 1970-01-01T00:00:00Z https://play.golang.org/p/WGA16N7Oejn
	UnixTimeZero = time.Unix(0, 0)

	// TestBytes test
	TestBytes = []byte(TestString)

	// TestBytesInitialCapitalized Test
	TestBytesInitialCapitalized = []byte(TestStringInitialCapitalized)
)
View Source
var (
	// ErrShouldNotBeNil should not be nil
	ErrShouldNotBeNil = errors.New("should not be nil")

	// ErrStringIsEmpty string is empty
	ErrStringIsEmpty = errors.New("string is empty")

	// ErrSliceIsNil slice is nil
	ErrSliceIsNil = errors.New("slice is nil")

	// ErrEnvironmentVariableIsNotSetOrEmpty environment variable is not set or empty
	ErrEnvironmentVariableIsNotSetOrEmpty = errors.New("environment variable is not set or empty")

	// ErrCSVStringContainsEmptyString csv string contains empty string
	ErrCSVStringContainsEmptyString = errors.New("csv string contains empty string")

	// ErrCSVContainsEmptyValue csv contains empty value
	ErrCSVContainsEmptyValue = errors.New("csv contains empty value")

	// ErrParameterIsNil parameter is nil
	ErrParameterIsNil = errors.New("parameter is nil")

	// ErrTestError test error
	ErrTestError = errors.New("test error")
)
View Source
var (
	// ErrX509InvalidPEMFormat invalid PEM format
	ErrX509InvalidPEMFormat = errors.New("invalid PEM format")

	// ErrX509CertificateHasExpired certificate has expired
	ErrX509CertificateHasExpired = errors.New("certificate has expired")

	// ErrX509CertificateIsNotYetValid certificate is not yet valid
	ErrX509CertificateIsNotYetValid = errors.New("certificate is not yet valid")
)
View Source
var ErrCryptoNoSuchCryptographicAlgorithm = errors.New("no such cryptographic algorithm")

ErrCryptoNoSuchCryptographicAlgorithm no such encryption algorithm

Functions

This section is empty.

Types

type CryptoUtility added in v1.1.6

type CryptoUtility struct{}

CryptoUtility is an empty structure that is prepared only for creating methods.

var Crypto *CryptoUtility

Crypto is an entity that allows the methods of CryptoUtility to be executed from outside the package without initializing CryptoUtility.

func (*CryptoUtility) CryptographicAlgorithm added in v1.3.1

func (*CryptoUtility) CryptographicAlgorithm(algorithm string) CryptographicAlgorithm

CryptographicAlgorithm returns CryptoEncryptionAlgorithm corresponding to the passed string.

func (*CryptoUtility) GenerateKey added in v1.2.3

func (*CryptoUtility) GenerateKey(algorithm CryptographicAlgorithm) (crypto.PrivateKey, error)

GenerateKey generates a private key according to the algorithm passed. nolint: wrapcheck

func (*CryptoUtility) MustGenerateKey added in v1.1.6

func (*CryptoUtility) MustGenerateKey(privateKey crypto.PrivateKey, err error) crypto.PrivateKey

MustGenerateKey expects to be passed the result of executing Generate() function that returns crypto.PrivateKey. If the result is error, it will cause panic(error); otherwise, it will return a crypto.PrivateKey.

type CryptographicAlgorithm added in v1.3.1

type CryptographicAlgorithm int

CryptographicAlgorithm is a type for enumerating encryption algorithms.

const (
	// CryptographicAlgorithmNone no such encryption algorithm
	CryptographicAlgorithmNone CryptographicAlgorithm = iota
	// CryptoRSA2048 RSA 2048 bits
	CryptoRSA2048
	// CryptoRSA4096 RSA 4096 bits
	CryptoRSA4096
	// CryptoRSA8192 RSA 8192 bits
	CryptoRSA8192
	// CryptoECDSA256 ECDSA with p-256 curve
	CryptoECDSA256
	// CryptoECDSA384 ECDSA with p-384 curve
	CryptoECDSA384
)

func (CryptographicAlgorithm) String added in v1.3.1

func (algorithm CryptographicAlgorithm) String() string

type EnvUtility

type EnvUtility struct{}

EnvUtility is an empty structure that is prepared only for creating methods.

var Env *EnvUtility

Env is an entity that allows the methods of EnvUtility to be executed from outside the package without initializing EnvUtility.

func (*EnvUtility) GetBool

func (*EnvUtility) GetBool(env string) (value bool, err error)

GetBool returns the value of the environment variable `env` if it is set, or the error if it is not set or invalid.

func (*EnvUtility) GetCSV

func (*EnvUtility) GetCSV(env string) (values []string, err error)

GetCSV returns the value of the environment variable `env` if it is set, or the error if it is not set or invalid.

func (*EnvUtility) GetCSVExcludeEmptyString added in v1.1.8

func (*EnvUtility) GetCSVExcludeEmptyString(env string) (values []string, err error)

GetCSVExcludeEmptyString returns the value of the environment variable `env` if it is set, or the error if it is not set or invalid.

func (*EnvUtility) GetInt64 added in v1.2.1

func (*EnvUtility) GetInt64(env string) (value int64, err error)

GetInt64 returns the value of the environment variable `env` if it is set, or the error if it is not set or invalid.

func (*EnvUtility) GetOrDefaultBool

func (*EnvUtility) GetOrDefaultBool(env string, defaultValue bool) (value bool)

GetOrDefaultBool returns the value of the environment variable `env` if it is set, or `defaultValue` if it is not set.

func (*EnvUtility) GetOrDefaultInt64 added in v1.2.1

func (*EnvUtility) GetOrDefaultInt64(env string, defaultValue int64) (value int64)

GetOrDefaultInt64 returns the value of the environment variable `env` if it is set, or `defaultValue` if it is not set.

func (*EnvUtility) GetOrDefaultSecond

func (*EnvUtility) GetOrDefaultSecond(env string, defaultValue time.Duration) (value time.Duration)

GetOrDefaultSecond returns the value of the environment variable `env` if it is set, or `defaultValue` if it is not set.

func (*EnvUtility) GetOrDefaultString

func (*EnvUtility) GetOrDefaultString(env, defaultValue string) (value string)

GetOrDefaultString returns the value of the environment variable `env` if it is set, or `defaultValue` if it is not set.

func (*EnvUtility) GetSecond

func (*EnvUtility) GetSecond(env string) (value time.Duration, err error)

GetSecond returns the value of the environment variable `env` if it is set, or the error if it is not set or invalid.

func (*EnvUtility) GetString

func (*EnvUtility) GetString(env string) (value string, err error)

GetString returns the value of the environment variable `env` if it is set, or the error if it is not set.

type HTTPUtility added in v1.1.2

type HTTPUtility struct{}

HTTPUtility is an empty structure that is prepared only for creating methods.

var HTTP *HTTPUtility

HTTP is an entity that allows the methods of HTTPUtility to be executed from outside the package without initializing HTTPUtility.

func (*HTTPUtility) DumpResponse added in v1.1.2

func (*HTTPUtility) DumpResponse(response *http.Response, dump, body *bytes.Buffer) error

DumpResponse dumps http.(*Response) to "dump" and copies http.(*Response).Body to *bytes.Buffer as "body". If you need a http.(*Response) that http.(*Response).Body.Close() is not called, you can use the following for the return value "body":

response.Body = io.NopCloser(body)

type JSONUtility added in v1.1.8

type JSONUtility struct{}

JSONUtility is an empty structure that is prepared only for creating methods.

var JSON *JSONUtility

JSON is an entity that allows the methods of JSONUtility to be executed from outside the package without initializing JSONUtility.

func (*JSONUtility) MustMarshal added in v1.1.8

func (*JSONUtility) MustMarshal(v interface{}) []byte

MustMarshal executes json.Marshal() and panic() if an error occurs.

func (*JSONUtility) MustUnmarshal added in v1.1.8

func (*JSONUtility) MustUnmarshal(data []byte, v interface{})

MustUnmarshal executes json.Unmarshal() and panic() if an error occurs.

type MIMEUtility

type MIMEUtility struct{}

MIMEUtility is an empty structure that is prepared only for creating methods.

var MIME *MIMEUtility

MIME is an entity that allows the methods of MIMEUtility to be executed from outside the package without initializing MIMEUtility.

func (*MIMEUtility) DetectContentType

func (*MIMEUtility) DetectContentType(reader io.Reader) (contentType string, err error)

DetectContentType is equivalent to http.DetectContentType and uses io.Reader, so it saves memory.

type PtrUtility added in v1.4.0

type PtrUtility struct{}

PtrUtility is an empty structure that is prepared only for creating methods.

var Ptr *PtrUtility

Ptr is an entity that allows the methods of PtrUtility to be executed from outside the package without initializing PtrUtility.

func (*PtrUtility) Bool added in v1.4.0

func (*PtrUtility) Bool(value bool) *bool

Bool returns a pointer to the argument.

func (*PtrUtility) Complex128 added in v1.4.0

func (*PtrUtility) Complex128(value complex128) *complex128

Complex128 returns a pointer to the argument.

func (*PtrUtility) Complex64 added in v1.4.0

func (*PtrUtility) Complex64(value complex64) *complex64

Complex64 returns a pointer to the argument.

func (*PtrUtility) Duration added in v1.4.0

func (*PtrUtility) Duration(value time.Duration) *time.Duration

Duration returns a pointer to the argument.

func (*PtrUtility) Float32 added in v1.4.0

func (*PtrUtility) Float32(value float32) *float32

Float32 returns a pointer to the argument.

func (*PtrUtility) Float64 added in v1.4.0

func (*PtrUtility) Float64(value float64) *float64

Float64 returns a pointer to the argument.

func (*PtrUtility) Int added in v1.4.0

func (*PtrUtility) Int(value int) *int

Int returns a pointer to the argument.

func (*PtrUtility) Int16 added in v1.4.0

func (*PtrUtility) Int16(value int16) *int16

Int16 returns a pointer to the argument.

func (*PtrUtility) Int32 added in v1.4.0

func (*PtrUtility) Int32(value int32) *int32

Int32 returns a pointer to the argument.

func (*PtrUtility) Int64 added in v1.4.0

func (*PtrUtility) Int64(value int64) *int64

Int64 returns a pointer to the argument.

func (*PtrUtility) Int8 added in v1.4.0

func (*PtrUtility) Int8(value int8) *int8

Int8 returns a pointer to the argument.

func (*PtrUtility) String added in v1.4.0

func (*PtrUtility) String(value string) *string

String returns a pointer to the argument.

func (*PtrUtility) Time added in v1.4.0

func (*PtrUtility) Time(value time.Time) *time.Time

Time returns a pointer to the argument.

func (*PtrUtility) Uint added in v1.4.0

func (*PtrUtility) Uint(value uint) *uint

Uint returns a pointer to the argument.

func (*PtrUtility) Uint16 added in v1.4.0

func (*PtrUtility) Uint16(value uint16) *uint16

Uint16 returns a pointer to the argument.

func (*PtrUtility) Uint32 added in v1.4.0

func (*PtrUtility) Uint32(value uint32) *uint32

Uint32 returns a pointer to the argument.

func (*PtrUtility) Uint64 added in v1.4.0

func (*PtrUtility) Uint64(value uint64) *uint64

Uint64 returns a pointer to the argument.

func (*PtrUtility) Uint8 added in v1.4.0

func (*PtrUtility) Uint8(value uint8) *uint8

Uint8 returns a pointer to the argument.

type SliceUtility

type SliceUtility struct{}

SliceUtility is an empty structure that is prepared only for creating methods.

var Slice *SliceUtility

Slice is an entity that allows the methods of SliceUtility to be executed from outside the package without initializing SliceUtility.

func (*SliceUtility) ContainsInt

func (*SliceUtility) ContainsInt(slice []int, value int) bool

ContainsInt returns whether or not the passed slice contains the passed value.

func (*SliceUtility) ContainsString

func (*SliceUtility) ContainsString(slice []string, value string) bool

ContainsString returns whether or not the passed slice contains the passed value.

func (*SliceUtility) EqualInt

func (*SliceUtility) EqualInt(a, b []int) bool

EqualInt will return true if the elements of the two slices are identical.

func (*SliceUtility) EqualString

func (*SliceUtility) EqualString(a, b []string) bool

EqualString will return true if the elements of the two slices are identical.

func (*SliceUtility) ExcludeString added in v1.1.8

func (*SliceUtility) ExcludeString(slice []string, exclude string) (excluded []string)

ExcludeString returns an array of `slice` minus `exclude`.

type StrconvUtility added in v1.2.1

type StrconvUtility struct{}

StrconvUtility is an empty structure that is prepared only for creating methods.

var Strconv *StrconvUtility

Strconv is an entity that allows the methods of StrconvUtility to be executed from outside the package without initializing StrconvUtility.

func (*StrconvUtility) Atoi64 added in v1.2.1

func (*StrconvUtility) Atoi64(s string) (int64, error)

Atoi64 is equivalent to ParseInt(s, 10, 64).

func (*StrconvUtility) I64toa added in v1.2.1

func (*StrconvUtility) I64toa(i int64) string

I64toa is equivalent to FormatInt(i, 10).

type StringsUtility added in v1.1.2

type StringsUtility struct{}

StringsUtility is an empty structure that is prepared only for creating methods.

var Strings *StringsUtility

Strings is an entity that allows the methods of StringsUtility to be executed from outside the package without initializing StringsUtility.

func (*StringsUtility) CapitalizeInitial added in v1.1.2

func (*StringsUtility) CapitalizeInitial(s string) (capitalized string)

CapitalizeInitial returns the first character of the passed string converted to uppercase.

type X509Utility added in v1.2.0

type X509Utility struct{}

X509Utility is an empty structure that is prepared only for creating methods.

var X509 *X509Utility

X509 is an entity that allows the methods of X509Utility to be executed from outside the package without initializing X509Utility.

func (*X509Utility) CheckCertificate added in v1.2.0

func (*X509Utility) CheckCertificate(cert *x509.Certificate) (notyet bool, daysToStart int64, expired bool, daysToExpire int64)

CheckCertificate returns "not yet valid", "validity starts after how many days", "expired", and "validity expires after how many days" for the certificate passed as argument.

func (*X509Utility) ParseCertificate added in v1.2.0

func (*X509Utility) ParseCertificate(pemData []byte) (*x509.Certificate, error)

ParseCertificate returns *x509.Certificate from the passed PEM data.

type ZapUtility

type ZapUtility struct{}

ZapUtility is an empty structure that is prepared only for creating methods.

var Zap *ZapUtility

Zap is an entity that allows the methods of ZapUtility to be executed from outside the package without initializing ZapUtility.

func (*ZapUtility) DefaultConfig

func (*ZapUtility) DefaultConfig() *zap.Config

DefaultConfig returns a generic configuration *zap.Config.

func (*ZapUtility) MustBuild added in v1.4.0

func (*ZapUtility) MustBuild(config *zap.Config) *zap.Logger

MustBuild returns *zap.Logger if *zap.Config is built successfully, otherwise it executes os.Exit(1) and terminates the process abnormally.

Directories

Path Synopsis
Package log is a thin logging package.
Package log is a thin logging package.

Jump to

Keyboard shortcuts

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