utils

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2022 License: MIT Imports: 12 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:")
)

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 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 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 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 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