gohelper

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 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
package main

import (
    "fmt"
    "github.com/google/uuid"
    "path/to/your/helper"
)

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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