Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 884 Bytes

README.md

File metadata and controls

35 lines (27 loc) · 884 Bytes

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())
    }
}