once

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 3 Imported by: 6

README

Safe

Safe function execution without panic

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/once

Getting Started

import (
  "testing"
  "github.com/go-zoox/once"
)

func main(t *testing.T) {
	loadConfig := func() {
		panic("load config panic")
	}

	if err := safe.Do(loadConfig); err != nil {
		log.Error(err)
	}
}

Inspired By

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "0.0.4"

Version is the current version of the package.

Functions

func Do

func Do(name string, fn func())

Do ...

func Func

func Func(name string, fn func()) func()

Func ...

func Get

func Get[T any](name string, fn func() T) T

Get ...

Types

type Once

type Once interface {
	Do(name string, fn func())
	Func(name string, fn func()) func()
	Get(name string, fn func() any) any
}

Once ...

func New

func New() Once

New creates once.

Jump to

Keyboard shortcuts

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