Skip to content
poohvpnPublic

About

Golang pointer helper

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

Pointer Helper for Go

This library can help to handle null value with golang primitive types, which is implemented by pointer.

Installing

go get -u github.com/poohvpn/ptr

Usage

package main

import (
    "github.com/poohvpn/ptr"
)

func main() {
	model := struct {
		Name *ptr.String `json:"name,omitempty"`
		Age  *ptr.Int    `json:"age,omitempty"`
	}{
		Name: ptr.NewString("anna"),
	}

	j, err := json.Marshal(model)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(j), model.Age.Value())
	// {"name":"anna"} 0
}

About

Golang pointer helper

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages