panic

package module
v0.0.0-...-4c03242 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 28, 2024 License: LGPL-3.0 Imports: 3 Imported by: 0

README

Panic

A library that allows different panic behaviours to be configured at runtime.

The intent is to allow stricter assertions in development, that may be relaxed when running in production, although the reverse may also be configured.

Usage

package main

import "github.com/crystalix007/panic"

func main() {
	panic.Panic("test")
}

Then, this can be run / built with -tags dev:

$ go run -tags dev ./main.go
panic: test

goroutine 1 [running]:
github.com/crystalix007/panic.Panic(...)
        /Users/michaelkuc6/Documents/coding/panic/panic.dev.go:7
main.main()
        /private/tmp/testing/main.go:10 +0x30
exit status 2

or -tags prod:

$ go run -tags prod ./main.go

Build flags

Flag Description
default or GITHUB_COM_CRYSTALIX007_PANIC_PANIC Panics and breaks execution on panic.
prod or GITHUB_COM_CRYSTALIX007_PANIC_LOG Makes panics print a slog warning.
GITHUB_COM_CRYSTALIX007_PANIC_SILENT Silently drops panics.
GITHUB_COM_CRYSTALIX007_PANIC_CUSTOM Allows setting a custom panic implementation.

Using environment tags, like:

  • dev
  • prod

will also be sufficient, as dev will invoke the default behaviour, and prod will enable slog logging.

Documentation

Overview

Package panic provides logic to use the configured panic behaviour.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogger

func GetLogger() *slog.Logger

GetLogger returns the logger for the backend.

func Panic

func Panic(v interface{})

Panic will panic with the behaviour configured by the build tags.

func Panicf

func Panicf(format string, v ...interface{})

Panicf will panic with the given format and values, as configured by the build tags.

func SetLogger

func SetLogger(l *slog.Logger)

SetLogger sets the logger for the backend.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL