gohelper

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 4 Imported by: 1

README

GOHELPER

Maintainer: jiharal

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 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 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 GetStringValue added in v1.0.1

func GetStringValue(ptr *string) string

GetStringValue returns the value of a string 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 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 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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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