Golang must, avoid err checks

2 months ago

A code snippet that helps to avoid "if err != nil" checks, in case we need to panic in that case Can be replaced with simple loging Can be extended for 1 or nore arguments

package must

import (
	"log"
	"runtime/debug"
)

func Panic[T any](val T, err error) T {
	if err != nil {
		debug.PrintStack()
		log.Panicln(err)
	}

	return val
}