Skip to content

onrik/pointer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pointer

Build Status Coverage Status Go Report Card GoDoc

Helpers for working with pointers.

Examples

package main

import (
    "time"

    "github.com/onrik/pointer"
)

type User struct {
    ID        int
    Name      string
    Age       *int
    UpdatedAt *time.Time
}

func main() {
  // Set helpers
  user := User{
      ID:        1,
      Name:      "John",
      Age:       pointer.Int(27),
      UpdatedAt: pointer.Time(time.Now()),
  }
  
  // Get helpers
  // instead of
  age := -1
  if user.Age != nil {
      age := *user.Age
  }
  
  // Use
  age := pointer.GetInt(user.Age, -1)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages