Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/noamt/goptr

Pointer utilities for go
https://github.com/noamt/goptr

go golang pointer pointers ptr util utility

Last synced: 16 days ago
JSON representation

Pointer utilities for go

Awesome Lists containing this project

README

        

= goptr

image:https://circleci.com/gh/noamt/goptr.svg?style=svg["CircleCI", link="https://circleci.com/gh/noamt/goptr"]

A utility package for Go pointers

== Pointer Resolution

In this package there are helper methods for resolving pointers of primitive types, with a fallback to a default value.

For example, resolving a pointer to a string:
[source,go]
----
import "github.com/noamt/goptr"

goptr.String(nil) // Returns an empty string
goptr.String("foo") // Returns "foo"

goptr.StringOrDefault(nil, "foo") // Returns "foo"

s := "bar"
goptr.StringOrDefault(&s, "foo") // Returns "bar"
----