utils

package module
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 12 Imported by: 3

README

GoUtils

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

AnonymizeIp slices ip address byte array and writes 0 to last octet example 192.172.90.70 -> 192.172.90.0

func CopyBytes

func CopyBytes(input []byte) []byte

func CreateDirectory

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

func CreateDirectoryFromFile

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

func CreateFile

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

func CreateLogFile

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

func FileExists

func FileExists(path string) bool

func GetAbsolutePath

func GetAbsolutePath(path string) (string, error)

func GetLocalIP

func GetLocalIP() string

func GetLocalIPs

func GetLocalIPs() []string

func GetRequestId

func GetRequestId() (string, error)

GetRequestId returns random byte slice of length 32

func Getenv

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

func IsInt

func IsInt(s string) bool

func IsSuccess

func IsSuccess(status int) bool

func RandomString

func RandomString(n int32) string

func TruncateUrl

func TruncateUrl(value []byte) []byte

func UnsafeBytes

func UnsafeBytes(s string) []byte

#nosec G103 UnsafeBytes returns a byte pointer without allocation

func UnsafeString

func UnsafeString(b []byte) string

#nosec G103 UnsafeString 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