Skip to content

pilagod/pointer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pointer Build Status Coverage Status

Pointer utils for Golang

Installation

go get -u github.com/pilagod/pointer

Usage

import (
    "time"

    "github.com/pilagod/pointer"
)

type Person struct {
    Name    *string
    Age     *int
    BornAt  *time.Time
}

func CreatePerson() Person {
    return Person{
        // use New to convert arbitrary value to pointer, and manually assert result to expected type
        Name: pointer.New("Andy").(*string),
        // use type helper to convert value to pointer without type assertion
        Age: pointer.Int(30),
        BornAt: pointer.Time(time.Now())
    }
}

About

Pointer utils for Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages