package
3.0.0+incompatible
Repository: https://github.com/donutloop/toolkit.git
Documentation: pkg.go.dev

# README

Usage

the singleton pattern is a software design pattern that restricts the instantiation of a type to one object

Example

package main 

import (
	"github.com/donutloop/toolkit/singleton"
)

type config struct {
	Addr string
	Port int
}

var configSingleton singleton.NewSingleton = singleton.NewSingleton(func() (interface{}, error) {
	return &config{Addr:"localhost", Port:80}, nil
})

func Config() (*config, error) {
	s, err := configSingleton.Get()
	if err != nil {
		return nil, err
	}
	return s.(*config), nil
}

func main() {
	config, err := Config()
	// do things 
}