idthing

package
v0.0.0-...-2935971 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2022 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = &module.Module{
	Name: "idthing",

	Commands: []*drc.Command{
		getnewid,
		idtime,
	},

	InitFunc: func(m *module.Module) error {
		var epoch time.Time

		dat, err := ioutil.ReadFile(filename)
		if err != nil {
			if !os.IsNotExist(err) {
				return err
			}
			epoch = time.Now().UTC()

			ndt, err := json.Marshal(epoch)
			if err != nil {
				return err
			}
			if err := ioutil.WriteFile(filename, ndt, 0600); err != nil {
				return err
			}
		} else {
			err = json.Unmarshal(dat, &epoch)
			if err != nil {
				return err
			}
		}

		gen = &sid.Generator{
			Epoch:  epoch,
			Worker: 0,
		}
		return nil
	},
}

Functions

func Get

func Get() sid.ID

func GetIDTime

func GetIDTime(id sid.ID) time.Time

func GetIDTimeString

func GetIDTimeString(id string) (time.Time, error)

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