github.com/xtls/xray-core@v1.8.12-0.20240518155711-3168d27b0bdb/main/commands/all/uuid.go (about)

     1  package all
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/xtls/xray-core/common/uuid"
     7  	"github.com/xtls/xray-core/main/commands/base"
     8  )
     9  
    10  var cmdUUID = &base.Command{
    11  	UsageLine: `{{.Exec}} uuid [-i "example"]`,
    12  	Short:     `Generate UUIDv4 or UUIDv5`,
    13  	Long: `
    14  Generate UUIDv4 or UUIDv5.
    15  
    16  UUIDv4 (random): {{.Exec}} uuid
    17  
    18  UUIDv5 (from input): {{.Exec}} uuid -i "example"
    19  `,
    20  }
    21  
    22  func init() {
    23  	cmdUUID.Run = executeUUID // break init loop
    24  }
    25  
    26  var input = cmdUUID.Flag.String("i", "", "")
    27  
    28  func executeUUID(cmd *base.Command, args []string) {
    29  	var output string
    30  	if l := len(*input); l == 0 {
    31  		u := uuid.New()
    32  		output = u.String()
    33  	} else if l <= 30 {
    34  		u, _ := uuid.ParseString(*input)
    35  		output = u.String()
    36  	} else {
    37  		output = "Input must be within 30 bytes."
    38  	}
    39  	fmt.Println(output)
    40  }