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: 2 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
⌂ 换网址