New Upstream Release - golang-github-aleksi-pointer

Ready changes

Summary

Merged new upstream version: 1.2.0 (was: 1.1.0).

Resulting package

Built on 2022-03-14T19:34 (took 2m2s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases golang-github-aleksi-pointer-dev

Lintian Result

Diff

diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml
new file mode 100644
index 0000000..c9facaa
--- /dev/null
+++ b/.github/workflows/go.yml
@@ -0,0 +1,31 @@
+---
+name: Go
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+  schedule:
+    - cron: '42 3 * * 4'
+
+jobs:
+  test:
+    name: Test
+    runs-on: ubuntu-20.04
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Install Go tip
+        run: |
+          sudo rm -fr /opt/hostedtoolcache/go /usr/local/go /usr/bin/go /bin/go
+          curl -o go.tar.gz -L \
+            https://github.com/AlekSi/golang-tip/releases/download/tip/master.linux-amd64.tar.gz
+          sudo tar -C /usr/local -xzf go.tar.gz
+          sudo ln -s /usr/local/go/bin/* /usr/local/bin/
+          go version
+          rm go.tar.gz
+
+      - name: Run tests
+        run: go test -v
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 7c92871..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,8 +0,0 @@
-language: go
-sudo: false
-
-go:
-  - 1.x
-  - master
-
-script: go test -v
diff --git a/README.md b/README.md
index 25f2948..64c72d7 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,15 @@
 # pointer
-[![GoDoc](https://godoc.org/github.com/AlekSi/pointer?status.svg)](https://godoc.org/github.com/AlekSi/pointer)
-[![Build Status](https://travis-ci.org/AlekSi/pointer.svg)](https://travis-ci.org/AlekSi/pointer)
 
-Go package pointer provides helpers to get pointers to values of built-in types.
+[![Go Reference](https://pkg.go.dev/badge/github.com/AlekSi/pointer.svg)](https://pkg.go.dev/github.com/AlekSi/pointer)
+
+Go package `pointer` provides helpers to convert between pointers and values of built-in
+(and, with Go 1.18+ generics, of any) types.
 
 ```
 go get github.com/AlekSi/pointer
 ```
 
-API is stable. [Documentation](http://godoc.org/github.com/AlekSi/pointer).
+API is stable. [Documentation](https://pkg.go.dev/github.com/AlekSi/pointer).
 
 ```go
 package motivationalexample
diff --git a/debian/changelog b/debian/changelog
index 2c17071..bf6953f 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-aleksi-pointer (1.2.0-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 14 Mar 2022 19:32:42 -0000
+
 golang-github-aleksi-pointer (1.1.0-2) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/generic.go b/generic.go
new file mode 100644
index 0000000..1ef976b
--- /dev/null
+++ b/generic.go
@@ -0,0 +1,36 @@
+//go:build go1.18
+// +build go1.18
+
+package pointer
+
+// To returns a pointer to the passed value.
+func To[T any](t T) *T {
+	return &t
+}
+
+// ToOrNil returns a pointer to the passed value, or nil, if the passed value is a zero value.
+// If the passed value has `IsZero() bool` method (for example, time.Time instance),
+// it is used to determine if the value is zero.
+func ToOrNil[T comparable](t T) *T {
+	if z, ok := any(t).(interface{ IsZero() bool }); ok {
+		if z.IsZero() {
+			return nil
+		}
+		return &t
+	}
+
+	var zero T
+	if t == zero {
+		return nil
+	}
+	return &t
+}
+
+// Get returns the value from the passed pointer or the zero value if the pointer is nil.
+func Get[T any](t *T) T {
+	if t == nil {
+		var zero T
+		return zero
+	}
+	return *t
+}
diff --git a/generic_test.go b/generic_test.go
new file mode 100644
index 0000000..154a59b
--- /dev/null
+++ b/generic_test.go
@@ -0,0 +1,33 @@
+//go:build go1.18
+// +build go1.18
+
+package pointer
+
+import (
+	"testing"
+	"time"
+)
+
+func TestGeneric(t *testing.T) {
+	var x time.Time
+	if *To(x) != x {
+		t.Errorf("*To(%v)", x)
+	}
+	if ToOrNil(x) != nil {
+		t.Errorf("ToOrNil(%v)", x)
+	}
+	if Get((*time.Time)(nil)) != x {
+		t.Errorf("Time(%v)", nil)
+	}
+
+	x = time.Date(2014, 6, 25, 12, 24, 40, 0, time.UTC)
+	if *To(x) != x {
+		t.Errorf("*To(%v)", x)
+	}
+	if *ToOrNil(x) != x {
+		t.Errorf("*ToOrNil(%v)", x)
+	}
+	if Get(&x) != x {
+		t.Errorf("Get(%v)", &x)
+	}
+}
diff --git a/go.mod b/go.mod
index 1d40808..07e2025 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,3 @@
 module github.com/AlekSi/pointer
 
-go 1.11
+go 1.18
diff --git a/pointer.go b/pointer.go
index 15ce5c4..8203feb 100644
--- a/pointer.go
+++ b/pointer.go
@@ -1,4 +1,4 @@
-// Package pointer provides helpers to get pointers to values of built-in types.
+// Package pointer provides helpers to convert between pointers and values of built-in (and, with generics, of any) types.
 package pointer // import "github.com/AlekSi/pointer"
 
 import (

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/gocode/src/github.com/AlekSi/pointer/generic.go
-rw-r--r--  root/root   /usr/share/gocode/src/github.com/AlekSi/pointer/generic_test.go

No differences were encountered in the control files

More details

Full run details