utilities

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 13 Imported by: 5

README

utilities

Go Quality Report GoDoc

utilities is a Go Library to share useful code, just that

Getting started

  • API documentation is available via godoc.

Installation

To install utilities package, you need to install Go and set your Go workspace first.

1 - The first need Go installed (version 1.13+ is required). Then you can use the below Go command to install Requist

$ go get -u github.com/dotWicho/utilities

And then Import it in your code:

package main

import "github.com/dotWicho/utilities"

Or

2 - Use as module in you project (go.mod file):

module myproject

go 1.13

require (
	github.com/dotWicho/utilities v1.0.6
)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Info    = Teal
	Warn    = Yellow
	Fatal   = Red
	Success = Green
)
View Source
var (
	White   = Color("\033[0;30m%s\033[0m")
	Red     = Color("\033[0;31m%s\033[0m")
	Green   = Color("\033[0;32m%s\033[0m")
	Yellow  = Color("\033[0;33m%s\033[0m")
	Purple  = Color("\033[0;34m%s\033[0m")
	Magenta = Color("\033[0;35m%s\033[0m")
	Teal    = Color("\033[0;36m%s\033[0m")

	LightWhite   = Color("\033[1;30m%s\033[0m")
	LightRed     = Color("\033[1;31m%s\033[0m")
	LightGreen   = Color("\033[1;32m%s\033[0m")
	LightYellow  = Color("\033[1;33m%s\033[0m")
	LightBlue    = Color("\033[1;34m%s\033[0m")
	LightMagenta = Color("\033[1;35m%s\033[0m")
	LightTeal    = Color("\033[1;36m%s\033[0m")
	Normal       = Color("\033[1;37m%s\033[0m")
)

Functions

func BaseName

func BaseName(str string) string

BaseName makes a string safe to use in a file name, producing a sanitized basename replacing . or / with -. No attempt is made to normalise a path or normalise case.

func CleanString

func CleanString(str string, r *regexp.Regexp) string

CleanString replaces separators with - and removes characters listed in the regexp provided from string. Accents, spaces, and all characters not in A-Za-z0-9 are replaced.

func Color added in v1.0.5

func Color(colorString string) func(...interface{}) string

func DecodeBase64 added in v1.0.3

func DecodeBase64(encode string) string

DecodeBase64 returns plain text from base64 entry

func DelInitialSlash

func DelInitialSlash(path string) string

DelInitialSlash just delete (if exists) a initial /

func EncodeBase64 added in v1.0.3

func EncodeBase64(value string) string

EncodeBase64 returns base64 encoded text

func EndsWithSlash

func EndsWithSlash(path string) string

EndsWithSlash just check if a path ends with /, if not add

func FileExists added in v1.0.7

func FileExists(fileName string) bool

func FileNameISO8601

func FileNameISO8601(fileName string) string

FileNameISO8601 returns a valid fileName with ISO8606 timestamp on it

func FilenameWithoutExtension added in v1.0.2

func FilenameWithoutExtension(fileName string) string

FilenameWithoutExtension returns a valid fileName without extension

func GetEnvVariable added in v1.0.3

func GetEnvVariable(name, defVal string) string

GetEnvVariable try to get an environment variable, returns default value otherwise

func IsValidUUID added in v1.0.6

func IsValidUUID(id string) bool

IsValidUUID just validate if an uuid is valid (Version 1 or Version 4)

func LoadDataFromJSON added in v1.0.1

func LoadDataFromJSON(body interface{}, fileName string) error

LoadDataFromJSON reads a JSON format file and returns its contents on body

func LoadDataFromYAML added in v1.0.1

func LoadDataFromYAML(body interface{}, fileName string) error

LoadDataFromYAML reads a YAML format file and returns its contents on body

func Name

func Name(str string) string

Name makes a string safe to use in a file name by first finding the path basename, then replacing non-ascii characters.

func ReadFile

func ReadFile(fileName string) []byte

ReadFile reads a file and returns its content if exists, on the other hand nil

func SetEnvVariable added in v1.0.3

func SetEnvVariable(name, value string) string

SetEnvVariable try to set an environment variable, returns current value if exist, empty string otherwise

func ValidFileName

func ValidFileName(folderName, fileName string) string

ValidFileName returns a valid fileName without not-ascii characters

func WriteDataToJSON added in v1.0.1

func WriteDataToJSON(body interface{}, fileName string) error

WriteDataToJSON saves the content of body in a JSON format file

func WriteDataToYAML added in v1.0.1

func WriteDataToYAML(body interface{}, fileName string) error

WriteDataToYAML saves the content of body in a YAML format file

func WriteFile added in v1.0.4

func WriteFile(body io.Reader, fileName string) error

WriteFile writes io.ReadCloser to a file and returns an error if exists

Types

This section is empty.

Jump to

Keyboard shortcuts

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