summaryrefslogtreecommitdiffstats
path: root/internal
diff options
context:
space:
mode:
authorSimen A. W. Olsen <hello@simenandre.no>2026-10-17 14:19:09 +0200
committerSimen A. W. Olsen <hello@simenandre.no>2026-10-17 14:19:09 +0200
commitc0a01ac65bb492640b169274614e0d8022f5076d (patch)
treef7d3f0e81d1a9dc05288ba24f1ecc57387f3e0d5 /internal
downloadfiken-c0a01ac65bb492640b169274614e0d8022f5076d.tar.gz
fiken-c0a01ac65bb492640b169274614e0d8022f5076d.zip
Fiken API client and OAuth2 for Gov0.1.0
Extracted from gcbill, where it was internal/fiken and internal/fikenauth, so adaa and sokkel-billing can use the same client instead of each carrying its own. The login command named when a grant cannot be renewed is now injected (Source.LoginCommand): it was hardcoded to gcbill's, which would have sent every other caller's operator to a command that does not exist.
Diffstat (limited to 'internal')
-rw-r--r--internal/assert/assert.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/assert/assert.go b/internal/assert/assert.go
new file mode 100644
index 0000000..cb0063c
--- /dev/null
+++ b/internal/assert/assert.go
@@ -0,0 +1,36 @@
+// Package assert provides programmer-error checks that abort the process.
+//
+// An assertion failure is never a user error: it means the program reached a
+// state its author believed impossible. User errors are returned as values.
+package assert
+
+import "fmt"
+
+// True aborts unless cond holds.
+func True(cond bool, format string, args ...any) {
+ if !cond {
+ panic("assertion failed: " + fmt.Sprintf(format, args...))
+ }
+}
+
+// Equal aborts unless got == want.
+func Equal[T comparable](got, want T, format string, args ...any) {
+ if got != want {
+ panic(fmt.Sprintf("assertion failed: %s: got %v, want %v",
+ fmt.Sprintf(format, args...), got, want))
+ }
+}
+
+// NoError aborts if err is non-nil. Use only where an error is structurally
+// impossible, never to discard an error a caller could handle.
+func NoError(err error, format string, args ...any) {
+ if err != nil {
+ panic(fmt.Sprintf("assertion failed: %s: %v",
+ fmt.Sprintf(format, args...), err))
+ }
+}
+
+// Unreachable aborts unconditionally.
+func Unreachable(format string, args ...any) {
+ panic("unreachable: " + fmt.Sprintf(format, args...))
+}