command

package
v0.0.0-...-88f1992 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewSIDCommand = cli.Command{
	Name:  "new",
	Usage: "New snow id",
	Flags: []cli.Flag{
		cli.Uint64Flag{
			Name:  "n",
			Usage: "node number",
		},
	},
	Action: func(context *cli.Context) error {
		nodeNumber := context.Int64("n")
		node, err := snowflake.NewNode(nodeNumber)
		if err != nil {
			return err
		}
		fmt.Printf("SID is : %+v\r\n", node.Generate().Int64())
		return nil
	},
}
View Source
var ParseTimeCommand = cli.Command{
	Name:  "parse",
	Usage: "Parse snow id to time",
	Flags: []cli.Flag{
		cli.Uint64Flag{
			Name:  "i",
			Usage: "snow id",
		},
	},
	Action: func(context *cli.Context) error {
		sid := context.Int64("i")
		ec := int64(1288834974657)
		step2 := sid - 4096
		step1 := step2 >> 22
		unixMill := step1 + ec
		utcTime := unixMill2Time(unixMill).UTC()
		locTime := utcTime.Local()
		fmt.Printf("SID is : %+v\r\nUnixMill is : %+v\r\nUTC time is : %+v\r\nLocal time is : %+v\r\n", sid, unixMill, utcTime, locTime)
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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