Skip to content

BacoFoods/ptr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ptr

ptr is a Go library that provides a set of helper functions for easily handling literal pointers.

Installation

go get github.com/BacoFoods/ptr

Features

  • Simplifies the creation of pointers for literal values.
  • Allows to handle conditional transformation pointers.
  • Generic support for any type.

Example

package main

import (
	"fmt"
	"github.com/BacoFoods/ptr"
)

type example struct {
  Name *string
  Price *float64
}

func main() {
  e := example{
    Name: ptr.Ptr("Example"),
    Price: ptr.Ptr(42.0)
  }

  log.Println(ptr.Val(e.Name, "Default Name"))

  if ptr.EqualVals(e.Price, ptr.Ptr(82)) {
    log.Println("Not the same")
  }

  var str *string
  t := ptr.Transform(str, strings.TrimSpaces)
}

License

This library is open-source and available under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages