utils

package module
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: MIT Imports: 13 Imported by: 3

README

GoUtils

Documentation

Testing codecov Go Report Card

## This is a collection of useful packages including:
  • Config
  • Environment
  • Logging
  • Signals
  • Testing

Config

package main

import (
    "github.com/nano-interactive/go-utils/config
)

// Defaults

var DefaultConfig = Config {
    Env: "development",
    Name: "config",
    Type: "yaml",
}

func main() {
    config, err := config.New(config.Config)

    if err != nil {
        // Failed to load configuration
    }
}

Environment

Logging

Signals

Testing

Documentation

Index

Constants

View Source
const (
	// RequestIdLength
	RequestIdLength = 32

	// MaxEncodedLength
	MaxEncodedLength = (RequestIdLength*8 + 5) / 6
)
View Source
const (
	UnknownIp = "UNKNOWN IP"
)

Variables

View Source
var (
	GooglePlay  = []byte("play.google")
	ITunesApple = []byte("itunes.apple")

	HTTPS         = []byte("https://")
	HTTP          = []byte("http://")
	HTTPSProtocol = []byte("https:")
	HTTPProtocol  = []byte("http:")
)
View Source
var ErrEscape = errors.New("invalid URL escape")

Functions

func AnonymizeIp

func AnonymizeIp(ip []byte) []byte

Slices IP address byte slice and writes 0 to last octet Example: AnonymizeIp([]byte{'1','9','2','.','1','7','2','.','9','0','.','7','0'}) Returns []byte{'1','9','2','.','1','7','2','.','9','0','.','0'}

func CopyBytes

func CopyBytes(input []byte) []byte

Provides a way of copying bytes into new byte slice Returns byte slice

func CreateDirectory

func CreateDirectory(path string, perm fs.FileMode) (string, error)

Provides a way of creating directory with permissions for a given path Returns string path of created directory and error if fails

func CreateDirectoryFromFile

func CreateDirectoryFromFile(path string, perm fs.FileMode) (string, error)

Provides a way of creating a directory from a path Returns created directory path and error if fails

func CreateFile

func CreateFile(path string, flags int, dirMode, mode fs.FileMode) (file *os.File, err error)

Creates file for given directory with flags and permissions for directory and file Returns file instance and error if it fails

func CreateLogFile

func CreateLogFile(path string) (file *os.File, err error)

Creates write only appendable file with permission 0o744 for directory and file for given path

func DecodeQuery added in v0.9.1

func DecodeQuery(dst []byte, src []byte) (int, error)

func DecodeQueryUnsafe added in v0.9.1

func DecodeQueryUnsafe(src []byte) ([]byte, error)

func DecodeQueryUnsafeString added in v0.9.1

func DecodeQueryUnsafeString(src []byte) (string, error)

func FileExists

func FileExists(path string) bool

Provides a way of checking if file exists. Returns bool

func GetAbsolutePath

func GetAbsolutePath(path string) (string, error)

Returns absolute path string for a given directory and error if directory doesent exist

func GetBrokenImageBytes added in v0.9.1

func GetBrokenImageBytes() []byte

func GetLocalIP

func GetLocalIP() string

Returns IP address of local machine, empty string if fails

func GetLocalIPs

func GetLocalIPs() []string

Returns strinngs slice of IP found on local machine

func GetRequestId

func GetRequestId() (string, error)

Returns 32 character string of random bytes

func Getenv

func Getenv(env string, def ...string) string

Returns ENV string

func IsHex added in v0.9.1

func IsHex(c byte) bool

func IsInt

func IsInt(s string) bool

Provides a way of testing if type is integer Returns bool value depending if its integer or not

func IsSuccess

func IsSuccess(status int) bool

Returns bool value of HTTP status code if its failure or success

func RandomString

func RandomString(n int32) string

Returns random string of given length

func TruncateUrl

func TruncateUrl(value []byte) []byte

Truncates a given url

func UnHex added in v0.9.1

func UnHex(c byte) byte

func UnsafeBytes

func UnsafeBytes(s string) []byte

#nosec G103 Returns a byte pointer without allocation

func UnsafeString

func UnsafeString(b []byte) string

#nosec G103 Returns a string pointer without allocation

Types

This section is empty.

Directories

Path Synopsis
__mocks__
io

Jump to

Keyboard shortcuts

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