Skip to main content
The Auth0 Go SDK provides a set of pointer helper functions to simplify working with pointer types. Since the SDK uses pointer fields extensively for optional values, these helpers make it easy to create pointers and safely dereference them.

Overview

All helper functions follow a consistent pattern:
  • Constructor functions (e.g., Bool, String) create pointers from values
  • Value functions (e.g., BoolValue, StringValue) safely dereference pointers with default values

Boolean Helpers

Bool

func Bool(b bool) *bool
Returns a pointer to the bool value passed in. Example:
import "github.com/auth0/go-auth0/v2"

client := &management.Client{
    IsFirstParty: auth0.Bool(true),
}

BoolValue

func BoolValue(b *bool) bool
Returns the value of the bool pointer passed in or false if the pointer is nil. Example:
import "github.com/auth0/go-auth0/v2"

isFirstParty := auth0.BoolValue(client.IsFirstParty)
// Returns false if client.IsFirstParty is nil

String Helpers

String

func String(s string) *string
Returns a pointer to the string value passed in. Example:
import "github.com/auth0/go-auth0/v2"

client := &management.Client{
    Name: auth0.String("My Application"),
}

Stringf

func Stringf(s string, v ...interface{}) *string
Returns a pointer to a formatted string using fmt.Sprintf. Example:
import "github.com/auth0/go-auth0/v2"

client := &management.Client{
    Description: auth0.Stringf("Application for %s environment", env),
}

StringValue

func StringValue(v *string) string
Returns the value of the string pointer passed in or "" (empty string) if the pointer is nil. Example:
import "github.com/auth0/go-auth0/v2"

name := auth0.StringValue(client.Name)
// Returns "" if client.Name is nil

Integer Helpers

Int

func Int(i int) *int
Returns a pointer to the int value passed in. Example:
import "github.com/auth0/go-auth0/v2"

connection := &management.Connection{
    Options: &management.ConnectionOptions{
        PasswordHistoryCount: auth0.Int(5),
    },
}

IntValue

func IntValue(i *int) int
Returns the value of the int pointer passed in or 0 if the pointer is nil. Example:
import "github.com/auth0/go-auth0/v2"

count := auth0.IntValue(connection.Options.PasswordHistoryCount)
// Returns 0 if PasswordHistoryCount is nil

Float Helpers

Float64

func Float64(f float64) *float64
Returns a pointer to the float64 value passed in. Example:
import "github.com/auth0/go-auth0/v2"

rule := &management.Rule{
    Order: auth0.Float64(1.5),
}

Float64Value

func Float64Value(f *float64) float64
Returns the value of the float64 pointer passed in or 0.00 if the pointer is nil. Example:
import "github.com/auth0/go-auth0/v2"

order := auth0.Float64Value(rule.Order)
// Returns 0.00 if rule.Order is nil

Time Helpers

Time

func Time(t time.Time) *time.Time
Returns a pointer to the time value passed in. Example:
import (
    "time"
    "github.com/auth0/go-auth0/v2"
)

user := &management.User{
    EmailVerified: auth0.Bool(true),
    LastLogin: auth0.Time(time.Now()),
}

TimeValue

func TimeValue(t *time.Time) time.Time
Returns the value of the time pointer passed in or the zero value of time (time.Time{}) if the pointer is nil. Example:
import (
    "time"
    "github.com/auth0/go-auth0/v2"
)

lastLogin := auth0.TimeValue(user.LastLogin)
// Returns time.Time{} if user.LastLogin is nil

Common Use Cases

Creating Resources

When creating resources, use the constructor functions to set optional fields:
import "github.com/auth0/go-auth0/v2"

client := &management.Client{
    Name:             auth0.String("My App"),
    Description:      auth0.String("Application description"),
    AppType:          auth0.String("regular_web"),
    IsFirstParty:     auth0.Bool(true),
    OIDCConformant:   auth0.Bool(true),
    JWTConfiguration: &management.ClientJWTConfiguration{
        LifetimeInSeconds: auth0.Int(36000),
        SecretEncoded:     auth0.Bool(false),
    },
}

Reading Resources

When reading resources, use the value functions or the safe getter methods:
import "github.com/auth0/go-auth0/v2"

// Using value functions
name := auth0.StringValue(client.Name)
isFirstParty := auth0.BoolValue(client.IsFirstParty)

// Using safe getter methods (preferred)
name := client.GetName()
isFirstParty := client.GetIsFirstParty()

Conditional Logic

Check for nil pointers before using value functions:
import "github.com/auth0/go-auth0/v2"

if client.IsFirstParty != nil {
    if auth0.BoolValue(client.IsFirstParty) {
        // Handle first-party client
    }
}

// Or use the safe getter method
if client.GetIsFirstParty() {
    // Handle first-party client
}

Best Practices

  1. Use constructor functions for optional fields: Always use auth0.String(), auth0.Bool(), etc., when setting optional fields
  2. Prefer safe getters over value functions: The SDK provides auto-generated safe getter methods (e.g., GetName()) that are preferred over manual value functions
  3. Check for nil when needed: For conditional logic, check if the pointer is nil before dereferencing
  4. Use Stringf for formatted strings: When you need to format strings, use auth0.Stringf() instead of manually formatting and wrapping

See Also

Build docs developers (and LLMs) love