Xray-core/main/commands/all/uuid.go

41 lines
772 B
Go
Raw Normal View History

2020-11-25 14:01:53 +03:00
package all
import (
"fmt"
2020-12-04 04:36:16 +03:00
"github.com/xtls/xray-core/common/uuid"
"github.com/xtls/xray-core/main/commands/base"
2020-11-25 14:01:53 +03:00
)
var cmdUUID = &base.Command{
UsageLine: `{{.Exec}} uuid [-i "example"]`,
Short: `Generate UUIDv4 or UUIDv5`,
2020-11-25 14:01:53 +03:00
Long: `
Generate UUIDv4 or UUIDv5.
UUIDv4 (random): {{.Exec}} uuid
UUIDv5 (from input): {{.Exec}} uuid -i "example"
`,
2020-11-25 14:01:53 +03:00
}
func init() {
cmdUUID.Run = executeUUID // break init loop
}
var input = cmdUUID.Flag.String("i", "", "")
2020-11-25 14:01:53 +03:00
func executeUUID(cmd *base.Command, args []string) {
var output string
if l := len(*input); l == 0 {
u := uuid.New()
output = u.String()
} else if l <= 30 {
u, _ := uuid.ParseString(*input)
output = u.String()
} else {
output = "Input must be within 30 bytes."
}
fmt.Println(output)
2020-11-25 14:01:53 +03:00
}