Categorygithub.com/elitecodegroovy/goutil
modulepackage
0.0.2
Repository: https://github.com/elitecodegroovy/goutil.git
Documentation: pkg.go.dev

# README

Go Utilities

Common Encoding and Decoding

ecoding.go

  • GetBasicAuthHeader(user string, password string) string : RFC 4648 encoding string and return string serial. DecodeBasicAuthHeader(header string) (string, string, error): RFC 4648 decoding string, vice verse as above function.
  • encodeMd5(str string) string: quickly gets the md5 code.
  • encodeSha1(str string) string: quickly gets the sha1 code.
  • encodeSha256(str string) string: quickly gets the sha256 code.
  • encodeSha512(str string) string: quickly gets the sha512 code.
  • EncodePassword(password string, salt string) string: encodes a password using PBKDF2.
  • Encrypt(payload []byte, secret string) ([]byte, error): encrypts a payload with a given secret. Decrypt(payload []byte, secret string) ([]byte, error): decrypts a payload with a given secret.

String Opts

  • IsValidShortUID(uid string) bool: checks if short unique identifier contains valid characters.
  • GenerateShortUID() string: generates a short unique identifier.

time Opts

  • GetCurrentDateISOStrDate() string: gets the current time with the format "2006-01-02". GetISOStrDate(t time.Time) string : does the same functionality.
  • GetCurrentTimeISOStrTime() string: gets the current time with the format "2006-01-02 15:04:05". GetISOStrTime(t time.Time) string: does the same functionality.
  • GetCurrentTimeNumberISOStrTime() string : gets the current time with the format "20060102150405". GetISOStrTimeNumber(t time.Time) string : does the same functionality.
  • GetStrTime(t time.Time, format string) string : gets the current time with the provided format parameter.
  • ParseLocal(datestr string) (time.Time, error): Parses local given an unknown date format, detect the layout, using time.Local. ParseIn(datestr string, loc *time.Location) (time.Time, error) : Parses given an unknown date format , detect the layout, using loc parameter.

url Opts

File Opts

filepath.go

  • copyFiles(sourcePath string, targetPath string) error: copy file from source directory to target directory.

IP Opts

ip_address.go

  • ParseIPAddress(input string) string : copy file from source directory to target directory.
  • SplitHostPortDefault(input, defaultHost, defaultPort string) (host string, port string):splits ip address/hostname string by host and port. Defaults used if no match found.

JSON Opts

XML Opts

Others

  • IsEmail(str string) bool: checks if a string is a valid email address..

Log framework

Do import the package and then declare the log structure instance.

import (l "github.com/elitecodegroovy/goutil"
        "go.uber.org/zap"
)

var ( 
    log = l.GetLogger()
)

//...

func DoXxx(){
    log.Info("", zap.String("field name :", "value")
    //...
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

RFC 4648 decoding string serial.
Decrypt decrypts a payload with a given secret.
EncodeMd5 encodes a string to md5 hex value.
EncodePassword encodes a password using PBKDF2.
No description provided by the author
No description provided by the author
No description provided by the author
Encrypt encrypts a payload with a given secret.
No description provided by the author
Run a func and get its result as a futur immediately Note this is unmanaged, it is as good as your own go func(){}() Just that it is wrapped with a nice Future object, and you can retrieve it as many times as you want, and you can retrieve with timeout.
GenerateShortUID generates a short unique identifier.
GetAgeString returns a string representing certain time from years to minutes.
RFC 4648 encoding string serial.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetRandomString generate random string by specify chars.
No description provided by the author
IsEmail checks if a string is a valid email address.
IsValidShortUID checks if short unique identifier contains valid characters.
JoinURLFragments joins two URL fragments into only one URL string.
Md5Sum calculates the md5sum of a stream.
Md5SumString calculates the md5sum of a string.
MustParse parse a date, and panic if it can't be parsed.
Create a new ThreadPool.
NewURLQueryReader parses a raw query and returns it as a URLQueryReader type.
No description provided by the author
Do a list of jobs in parallel, and return the List of futures immediately This will create as many threads as possible.
Do a list of jobs in parallel, and return the List of futures immediately.
ParseAny parse an unknown date format, detect the layout.
ParseFormat parse's an unknown date-time string and returns a layout string that can parse this (and exact same format) other date-time strings.
ParseIn with Location, equivalent to time.ParseInLocation() timezone/offset rules.
ParseIPAddress parses an IP address and removes port and/or IPV6 format.
ParseLocal Given an unknown date format, detect the layout, using time.Local, parse.
ParseStrict parse an unknown date format.
PBKDF2 implements Password-Based Key Derivation Function 2), aimed to reduce the vulnerability of encrypted keys to brute force attacks.
RandomHex returns a random string from a n seed.
No description provided by the author
No description provided by the author
SplitHostPort splits ip address/hostname string by host and port.
SplitHostPortDefault splits ip address/hostname string by host and port.
SplitString splits a string by commas or empty spaces.
No description provided by the author
Defer is not the same as deferred (or futures/promises) in other languages.
StringsFallback2 returns the first of two not empty strings.
StringsFallback3 returns the first of three not empty strings.
No description provided by the author
No description provided by the author
Walk walks a path, optionally following symbolic links, and for each path,it calls the walkFn passed.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Variables

ErrAmbiguousMMDD for date formats such as 04/02/2014 the mm/dd vs dd/mm are ambiguous, so it is an error for strict parse rules.
ErrWalkSkipDir is the Error returned when we want to skip descending into a directory.

# Structs

Represents a Future result object.
No description provided by the author
Internal concept of a Job and its produced result.
Represent a Thread Pool Object.
URLQueryReader is a URL query type.
No description provided by the author

# Type aliases

DynMap defines a dynamic map interface.
Represent a job that returns something for future retrieval.
A function that is no args, no returns.
WalkFunc is a callback function called for each path as a directory is walkedIf resolvedPath != "", then we are following symbolic links.