Exemplo n.º 1
1
func Example() {
	saver := new(savers.FileSystemSaver)
	saver.Report = true
	saver.Duration = time.Second * 3

	// Run before any v1 or v2 UUIDs to ensure the saver takes
	uuid.RegisterSaver(saver)

	u1 := uuid.NewV1()
	fmt.Printf("version %d variant %x: %s\n", u1.Version(), u1.Variant(), u1)

	uP, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	u3 := uuid.NewV3(uP, uuid.Name("test"))

	u4 := uuid.NewV4()
	fmt.Printf("version %d variant %x: %s\n", u4.Version(), u4.Variant(), u4)

	u5 := uuid.NewV5(uuid.NamespaceURL, uuid.Name("test"))

	if uuid.Equal(u1, u3) {
		fmt.Printf("Will never happen")
	}

	fmt.Print(uuid.Sprintf(uuid.CurlyHyphen, u5))

	uuid.SwitchFormat(uuid.BracketHyphen)
}
Exemplo n.º 2
0
func ExampleParse() {
	u, err := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	if err != nil {
		fmt.Println("error:", err)
	}
	fmt.Println(u)
}
Exemplo n.º 3
0
func BenchmarkParse(b *testing.B) {
	s := "f3593cff-ee92-40df-4086-87825b523f13"
	for i := 0; i < b.N; i++ {
		uuid.Parse(s)
	}
	b.StopTimer()
	b.ReportAllocs()
}
Exemplo n.º 4
0
func Test_Parse(t *testing.T) {
	u, err := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	if err != nil {
		fmt.Println("error:", err)
		return
	}
	fmt.Println(u)
}
Exemplo n.º 5
0
// Overriding the UnmarshalJSON method of the UUID type so we can parse the UUID
func (self *UUID) UnmarshalJSON(b []byte) error {

	s := strings.Trim(string(b), "\"")
	uuid, uuidErr := uuid.Parse(s)
	self.UUID = uuid
	if self.UUID == nil || uuidErr != nil {
		return errors.New("Could not parse UUID")
	}
	return nil
}
Exemplo n.º 6
0
func IsID(str string) error {
	if str == "" {
		return errors.New("valik: id is empty")
	}

	u, err := uuid.Parse(str)
	if err != nil || u.String() != str {
		return errors.New("valik: id is not a valid uuid")
	}

	return nil
}
Exemplo n.º 7
0
func Example() {
	var config = uuid.StateSaverConfig{SaveReport: true, SaveSchedule: 30 * time.Minute}
	uuid.SetupFileSystemStateSaver(config)
	u1 := uuid.NewV1()
	fmt.Printf("version %d variant %x: %s\n", u1.Version(), u1.Variant(), u1)

	uP, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	u3 := uuid.NewV3(uP, uuid.Name("test"))

	u4 := uuid.NewV4()
	fmt.Printf("version %d variant %x: %s\n", u4.Version(), u4.Variant(), u4)

	u5 := uuid.NewV5(uuid.NamespaceURL, uuid.Name("test"))

	if uuid.Equal(u1, u3) {
		fmt.Printf("Will never happen")
	}

	fmt.Printf(uuid.Formatter(u5, uuid.CurlyHyphen))

	uuid.SwitchFormat(uuid.BracketHyphen)
}
func Example() {
	saver := new(savers.FileSystemSaver)
	saver.Report = true
	saver.Duration = time.Second * 3

	// Run before any v1 or v2 UUIDs to ensure the savers takes
	uuid.RegisterSaver(saver)

	up, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	fmt.Printf("version %d variant %x: %s\n", up.Version(), up.Variant(), up)

	uuid.New(up.Bytes())

	u1 := uuid.NewV1()
	fmt.Printf("version %d variant %x: %s\n", u1.Version(), u1.Variant(), u1)

	u4 := uuid.NewV4()
	fmt.Printf("version %d variant %x: %s\n", u4.Version(), u4.Variant(), u4)

	u3 := uuid.NewV3(u1, u4)

	url, _ := url.Parse("www.example.com")

	u5 := uuid.NewV5(uuid.NameSpaceURL, url)

	if uuid.Equal(u1, u3) {
		fmt.Println("Will never happen")
	}

	if uuid.Compare(uuid.NameSpaceDNS, uuid.NameSpaceDNS) == 0 {
		fmt.Println("They are equal")
	}

	// Default Format is Canonical
	fmt.Println(uuid.Formatter(u5, uuid.FormatCanonicalCurly))

	uuid.SwitchFormat(uuid.FormatCanonicalBracket)
}
Exemplo n.º 9
0
// Constructor method for BaseInstance structs
func NewBaseInstance(args ...interface{}) *BaseInstance {
	newInstance := &BaseInstance{ID: new(UUID)}

	for argNum, arg := range args {

		switch argNum {
		case 0:
			uuid, _ := uuid.Parse(arg.(string))
			newInstance.ID.UUID = uuid
		case 1:
			newInstance.Label = arg.(string)
		case 2:
			newInstance.Type = arg.(InstanceType)
		case 3:
			newInstance.OSVersion = arg.(float32)
		case 4:
			newInstance.IsRunning = arg.(bool)
		case 5:
			newInstance.Path = arg.(string)
		case 6:
			newInstance.RootDiskImageSize = arg.(string)
		case 7:
			newInstance.Address = arg.(net.IP)
		case 8:
			newInstance.AdminLogin = arg.(string)
		case 9:
			newInstance.SSHPort = arg.(int)
		case 10:
			newInstance.SSHKeyPassphraseEnabled = arg.(bool)
		case 11:
			newInstance.Containers = arg.([]BaseApplicationContainerInstance)
		}
	}

	return newInstance

}
Exemplo n.º 10
0
func ExampleNewV3() {
	u, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	u3 := uuid.NewV3(u, uuid.Name("test"))
	fmt.Printf("version %d variant %x: %s\n", u3.Version(), u3.Variant(), u3)
}
Exemplo n.º 11
0
func Test_NewV3(t *testing.T) {
	u, _ := uuid.Parse("6ba7b810-9dad-11d1-80b4-00c04fd430c8")
	u3 := uuid.NewV3(u, uuid.Name("test"))
	fmt.Printf(print, u3.Version(), u3.Variant(), u3)
}
Exemplo n.º 12
0
//FormatUUID format uuidv4
func FormatUUID(uuid string) (string, error) {
	u, err := uuidlib.Parse(uuid)
	return u.String(), err
}
Exemplo n.º 13
0
func (f uuidFormatChecker) IsFormat(input string) bool {
	_, err := uuid.Parse(input)
	return err == nil
}