From e833f8eb1c5ba94f1613c0c427d170af3616719c Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sun, 11 Sep 2022 20:11:38 +0100 Subject: [PATCH] Monomorphise can be generic now --- go.mod | 2 +- phttpc/http.go | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index a1bde73..08cc740 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module git.sr.ht/~ogham/doom -go 1.16 +go 1.18 require ( github.com/getsentry/sentry-go v0.13.0 diff --git a/phttpc/http.go b/phttpc/http.go index 94de44b..3dc9aa9 100644 --- a/phttpc/http.go +++ b/phttpc/http.go @@ -126,12 +126,11 @@ func getJson(req *http.Request, endpoint *url.URL, target interface{}) { } } -// Monomorphise checks the given length. Many responses should only include -// arrays with a length of 0 (entity not found) or 1 (entity found); this -// function checks for that not being the case. -func Monomorphise(length int) { - if length > 1 { - panic(fmt.Sprintf("Too many elements (%d) in response", length)) +// Monomorphise checks the given list of results to have a length of 1. Many +// responses should only include arrays with a length of 0 (entity not found) or +// 1 (entity found); this function checks for that not being the case. +func Monomorphise[T any](elements []T) { + if len(elements) > 1 { + panic(fmt.Sprintf("Too many elements (%d) in response: %+v", len(elements), elements)) } } - -- 2.45.2