gohelper

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 6 Imported by: 1

README

GOHELPER

Maintainer: jiharal

Go CI

Go Report Card

Overview

The GOHELPER package provides utility functions for working with pointers and safely retrieving values from maps in Go. These helper functions can make your code cleaner and more concise.

Functions

Pointer Functions

These functions return pointers to values of their respective types. They are useful for creating pointer references for various data types.

Available Functions
  • PointerUUID: Returns a pointer to a uuid.UUID.
  • PointerString: Returns a pointer to a string.
  • PointerBool: Returns a pointer to a bool.
  • PointerInt: Returns a pointer to an int.
  • PointerInt8: Returns a pointer to an int8.
  • PointerInt16: Returns a pointer to an int16.
  • PointerInt32: Returns a pointer to an int32.
  • PointerInt64: Returns a pointer to an int64.
  • PointerUint: Returns a pointer to a uint.
  • PointerUint8: Returns a pointer to a uint8.
  • PointerUint16: Returns a pointer to a uint16.
  • PointerUint32: Returns a pointer to a uint32.
  • PointerUint64: Returns a pointer to a uint64.
  • PointerFloat32: Returns a pointer to a float32.
  • PointerFloat64: Returns a pointer to a float64.
  • PointerComplex64: Returns a pointer to a complex64.
  • PointerComplex128: Returns a pointer to a complex128.
  • PointerByte: Returns a pointer to a byte.
  • PointerRune: Returns a pointer to a rune.
Usage Example
go get github.com/tlabdotcom/gohelper
package main

import (
    "fmt"
    "github.com/google/uuid"
    "github.com/tlabdotcom/gohelper"
)

func main() {
    str := "Hello, World!"
    strPtr := gohelper.PointerString(str)
    fmt.Println(*strPtr) // Output: Hello, World!

    id := uuid.New()
    idPtr := gohelper.PointerUUID(id)
    fmt.Println(*idPtr) // Output: (some UUID value)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolToString added in v1.0.2

func BoolToString(b bool) string

BoolToString converts a bool to a string

func Float64ToInt added in v1.0.2

func Float64ToInt(f float64) int

Float64ToInt converts a float64 to an int

func Float64ToString added in v1.0.2

func Float64ToString(f float64) string

Float64ToString converts a float64 to a string

func GetBoolValue added in v1.0.1

func GetBoolValue(ptr *bool) bool

GetBoolValue returns the value of a bool pointer.

func GetByteValue added in v1.0.1

func GetByteValue(ptr *byte) byte

GetByteValue returns the value of a byte pointer.

func GetComplex64Value added in v1.0.1

func GetComplex64Value(ptr *complex64) complex64

GetComplex64Value returns the value of a complex64 pointer.

func GetComplex128Value added in v1.0.1

func GetComplex128Value(ptr *complex128) complex128

GetComplex128Value returns the value of a complex128 pointer.

func GetEndOfDay added in v1.0.3

func GetEndOfDay(t time.Time) time.Time

GetEndOfDay returns the end of the day for a given time

func GetFloat32Value added in v1.0.1

func GetFloat32Value(ptr *float32) float32

GetFloat32Value returns the value of a float32 pointer.

func GetFloat64Value added in v1.0.1

func GetFloat64Value(ptr *float64) float64

GetFloat64Value returns the value of a float64 pointer.

func GetInt8Value added in v1.0.1

func GetInt8Value(ptr *int8) int8

GetInt8Value returns the value of an int8 pointer.

func GetInt16Value added in v1.0.1

func GetInt16Value(ptr *int16) int16

GetInt16Value returns the value of an int16 pointer.

func GetInt32Value added in v1.0.1

func GetInt32Value(ptr *int32) int32

GetInt32Value returns the value of an int32 pointer.

func GetInt64Value added in v1.0.1

func GetInt64Value(ptr *int64) int64

GetInt64Value returns the value of an int64 pointer.

func GetIntValue added in v1.0.1

func GetIntValue(ptr *int) int

GetIntValue returns the value of an int pointer.

func GetRuneValue added in v1.0.1

func GetRuneValue(ptr *rune) rune

GetRuneValue returns the value of a rune pointer.

func GetStartOfDay added in v1.0.3

func GetStartOfDay(t time.Time) time.Time

func GetStringValue added in v1.0.1

func GetStringValue(ptr *string) string

GetStringValue returns the value of a string pointer.

func GetTimeValue added in v1.0.2

func GetTimeValue(ptr *time.Time) time.Time

GetRuneValue returns the value of a rune pointer.

func GetUUIDValue added in v1.0.1

func GetUUIDValue(ptr *uuid.UUID) uuid.UUID

GetUUIDValue returns the value of a uuid.UUID pointer.

func GetUint8Value added in v1.0.1

func GetUint8Value(ptr *uint8) uint8

GetUint8Value returns the value of a uint8 pointer.

func GetUint16Value added in v1.0.1

func GetUint16Value(ptr *uint16) uint16

GetUint16Value returns the value of a uint16 pointer.

func GetUint32Value added in v1.0.1

func GetUint32Value(ptr *uint32) uint32

GetUint32Value returns the value of a uint32 pointer.

func GetUint64Value added in v1.0.1

func GetUint64Value(ptr *uint64) uint64

GetUint64Value returns the value of a uint64 pointer.

func GetUintValue added in v1.0.1

func GetUintValue(ptr *uint) uint

GetUintValue returns the value of a uint pointer.

func Int64ToInt added in v1.0.2

func Int64ToInt(i int64) int

Int64ToInt converts an int64 to an int

func Int64ToString added in v1.0.2

func Int64ToString(i int64) string

Int64ToString converts an int64 to a string

func IntToFloat64 added in v1.0.2

func IntToFloat64(i int) float64

IntToFloat64 converts an int to a float64

func IntToInt64 added in v1.0.2

func IntToInt64(i int) int64

IntToInt64 converts an int to an int64

func IntToString added in v1.0.2

func IntToString(i int) string

IntToString converts an int to a string

func NewUUID added in v1.0.2

func NewUUID() uuid.UUID

NewUUID generates a new UUID

func ParseDate added in v1.0.3

func ParseDate(dateStr string) (*time.Time, error)

func PointerBool

func PointerBool(prm bool) *bool

PointerBool returns a pointer to the given bool. It is useful for creating pointers to bool values.

func PointerByte

func PointerByte(prm byte) *byte

PointerByte returns a pointer to the given byte. It is useful for creating pointers to byte values.

func PointerComplex64

func PointerComplex64(prm complex64) *complex64

PointerComplex64 returns a pointer to the given complex64. It is useful for creating pointers to complex64 values.

func PointerComplex128

func PointerComplex128(prm complex128) *complex128

PointerComplex128 returns a pointer to the given complex128. It is useful for creating pointers to complex128 values.

func PointerFloat32

func PointerFloat32(prm float32) *float32

PointerFloat32 returns a pointer to the given float32. It is useful for creating pointers to float32 values.

func PointerFloat64

func PointerFloat64(prm float64) *float64

PointerFloat64 returns a pointer to the given float64. It is useful for creating pointers to float64 values.

func PointerInt

func PointerInt(prm int) *int

PointerInt returns a pointer to the given int. It is useful for creating pointers to int values.

func PointerInt8

func PointerInt8(prm int8) *int8

PointerInt8 returns a pointer to the given int8. It is useful for creating pointers to int8 values.

func PointerInt16

func PointerInt16(prm int16) *int16

PointerInt16 returns a pointer to the given int16. It is useful for creating pointers to int16 values.

func PointerInt32

func PointerInt32(prm int32) *int32

PointerInt32 returns a pointer to the given int32. It is useful for creating pointers to int32 values.

func PointerInt64

func PointerInt64(prm int64) *int64

PointerInt64 returns a pointer to the given int64. It is useful for creating pointers to int64 values.

func PointerRune

func PointerRune(prm rune) *rune

PointerRune returns a pointer to the given rune. It is useful for creating pointers to rune values.

func PointerString

func PointerString(prm string) *string

PointerString returns a pointer to the given string. It is useful for creating pointers to string values.

func PointerTime added in v1.0.2

func PointerTime(prm time.Time) *time.Time

PointerTime returns a pointer to the given time. It is useful for creating pointers to time values.

func PointerUUID

func PointerUUID(id uuid.UUID) *uuid.UUID

PointerUUID returns a pointer to the given UUID. It is useful for creating pointers to UUID values.

func PointerUint

func PointerUint(prm uint) *uint

PointerUint returns a pointer to the given uint. It is useful for creating pointers to uint values.

func PointerUint8

func PointerUint8(prm uint8) *uint8

PointerUint8 returns a pointer to the given uint8. It is useful for creating pointers to uint8 values.

func PointerUint16

func PointerUint16(prm uint16) *uint16

PointerUint16 returns a pointer to the given uint16. It is useful for creating pointers to uint16 values.

func PointerUint32

func PointerUint32(prm uint32) *uint32

PointerUint32 returns a pointer to the given uint32. It is useful for creating pointers to uint32 values.

func PointerUint64

func PointerUint64(prm uint64) *uint64

PointerUint64 returns a pointer to the given uint64. It is useful for creating pointers to uint64 values.

func SafeGetBoolValue

func SafeGetBoolValue(m map[string]interface{}, key string, defaultValue bool) bool

SafeGetBoolValue safely retrieves a bool value from a map by key. If the key is not found or the value is not a bool, it returns the default value.

func SafeGetFloat64Value

func SafeGetFloat64Value(m map[string]interface{}, key string, defaultValue float64) float64

SafeGetFloat64Value safely retrieves a float64 value from a map by key. If the key is not found or the value is not a float64, it returns the default value.

func SafeGetInt64Value

func SafeGetInt64Value(m map[string]interface{}, key string, defaultValue int64) int64

SafeGetInt64Value safely retrieves an int64 value from a map by key. If the key is not found or the value is not an int64, it returns the default value.

func SafeGetIntValue

func SafeGetIntValue(m map[string]interface{}, key string, defaultValue int) int

SafeGetIntValue safely retrieves an int value from a map by key. If the key is not found or the value is not an int, it returns the default value.

func SafeGetStringValue

func SafeGetStringValue(m map[string]interface{}, key string, defaultValue string) string

SafeGetStringValue safely retrieves a string value from a map by key. If the key is not found or the value is not a string, it returns the default value.

func SafeGetValue

func SafeGetValue(m map[string]interface{}, key string, defaultValue interface{}) interface{}

SafeGetValue safely retrieves a value of any type from a map by key. If the key is not found or the value cannot be cast to the desired type, it returns the default value.

func StringToBool added in v1.0.2

func StringToBool(s string) (bool, error)

StringToBool converts a string to a bool

func StringToFloat64 added in v1.0.2

func StringToFloat64(s string) (float64, error)

StringToFloat64 converts a string to a float64

func StringToInt added in v1.0.2

func StringToInt(s string) (int, error)

StringToInt converts a string to an int

func StringToInt64 added in v1.0.2

func StringToInt64(s string) (int64, error)

StringToInt64 converts a string to an int64

func StringToTime added in v1.0.2

func StringToTime(s, layout string) (time.Time, error)

StringToTime converts a string to a time.Time The layout parameter specifies the format of the input string

func StringToUUID added in v1.0.2

func StringToUUID(s string) (uuid.UUID, error)

StringToUUID converts a string to a UUID

func TimeToString added in v1.0.2

func TimeToString(t time.Time, layout string) string

TimeToString converts a time.Time to a string The layout parameter specifies the desired output format

func ToBool added in v1.0.2

func ToBool(v interface{}) (bool, error)

func ToFloat64 added in v1.0.2

func ToFloat64(v interface{}) (float64, error)

func ToInt added in v1.0.2

func ToInt(v interface{}) (int, error)

func ToInt64 added in v1.0.2

func ToInt64(v interface{}) (int64, error)

func ToString added in v1.0.2

func ToString(v interface{}) string

Interface conversions

func ToUUID added in v1.0.2

func ToUUID(v interface{}) (uuid.UUID, error)

func UUIDToString added in v1.0.2

func UUIDToString(u uuid.UUID) string

UUIDToString converts a UUID to a string

Types

This section is empty.

Jump to

Keyboard shortcuts

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