goutils

package module
v1.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 9 Imported by: 9

README

goutils

Go Report Card Build Status go.dev reference

Bibliothèque Go avec des fonctions d'aide.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckError

func CheckError(err error, exitCode int)

CheckError manages errors.

func EndOfDay added in v1.0.7

func EndOfDay(t time.Time) time.Time

EndOfDay returns a the last time of a day.

func GetHTTPStatusMessage added in v1.0.8

func GetHTTPStatusMessage(code int) string

GetHTTPStatusMessage returns a message for a HTTP status code.

func HumanSize added in v1.0.9

func HumanSize(size float64) string

HumanSize returns a human-readable approximation of a size capped at 1 valid number (eg. "2.7MB", "796.0KB").

func HumanSizeWithPrecision added in v1.0.9

func HumanSizeWithPrecision(size float64, precision int) string

HumanSizeWithPrecision allows the size to be in any precision, instead of 1 digit precision used in HumanSize.

func InArray added in v1.0.4

func InArray(value interface{}, array interface{}) (found bool, index int)

InArray search an element in an array.

func RemoveDuplicatesFromStringArray added in v1.0.7

func RemoveDuplicatesFromStringArray(arr []string) []string

RemoveDuplicatesFromStringArray removes duplicates strings from slice.

func RemoveStringFromSlice added in v1.0.7

func RemoveStringFromSlice(a string, slice []string) []string

RemoveStringFromSlice removes string from slice.

func SQLDateToTime added in v1.0.4

func SQLDateToTime(d string) (time.Time, error)

SQLDateToTime converts SQL date to time.Time.

func SQLDatetimeToTime added in v1.0.4

func SQLDatetimeToTime(d string) (time.Time, error)

SQLDatetimeToTime converts SQL date to time.Time.

func SetInterval added in v1.0.10

func SetInterval(fct func(), milliseconds int, async bool) chan<- bool

SetInterval executes a function that is repeated at regular intervals and returns a channel to clear the interval. Usage: interval := setInterval(myFunction, 1000, false) To clear interval: interval <- true

func SetTimeout added in v1.0.10

func SetTimeout(fct func(), milliseconds int)

SetTimeout runs a function after a given period of time.

func StartOfDay added in v1.0.7

func StartOfDay(t time.Time) time.Time

StartOfDay returns a the first time of a day.

func StringArrayIntersection added in v1.0.7

func StringArrayIntersection(arr1, arr2 []string) []string

StringArrayIntersection returns the intersection of two slices.

func StringInSlice added in v1.0.7

func StringInSlice(a string, slice []string) bool

StringInSlice finds string in slice.

Example
ok := StringInSlice("Coucou", []string{"Coucou", "Hello"})
fmt.Println(ok)
Output:

true

func StringSliceDiff added in v1.0.7

func StringSliceDiff(a, b []string) []string

StringSliceDiff returns differences between two slices.

Example
a := []string{"one", "two", "three", "four", "five", "six"}
b := []string{"two", "seven", "four", "six"}
diff := StringSliceDiff(a, b)

fmt.Printf("diff: %v\n", diff)
Output:

diff: [one three five]

func SubPath added in v1.0.6

func SubPath(path, pattern string) string

SubPath returns subpath of file from path.

func TimeToSQLDate added in v1.0.5

func TimeToSQLDate(t time.Time) string

TimeToSQLDate returns a time to SQL date format (YYYY-MM-DD).

func TimeToSQLDatetime added in v1.0.5

func TimeToSQLDatetime(t time.Time) string

TimeToSQLDatetime returns a time to SQL datetime format (YYYY-MM-DD HH:MM:SS).

func Ucfirst added in v1.0.4

func Ucfirst(s string) string

Ucfirst makes a string's first character uppercase.

func Yesterday added in v1.0.7

func Yesterday() time.Time

Yesterday returns yesterday time.

Types

type HTTPResponse added in v1.0.4

type HTTPResponse struct {
	Code    int         `json:"code" xml:"code"`
	Message string      `json:"message" xml:"message"`
	Data    interface{} `json:"data,omitempty" xml:"data"`
}

HTTPResponse type

func GetHTTPInternalServerError added in v1.0.4

func GetHTTPInternalServerError(message string) HTTPResponse

GetHTTPInternalServerError returns 500 error.

func GetHTTPResponse added in v1.0.4

func GetHTTPResponse(code int, message string, data interface{}) HTTPResponse

GetHTTPResponse returns HTTPResponse type.

Directories

Path Synopsis
database
mgo

Jump to

Keyboard shortcuts

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