1. Patrick Mézard
  2. go-uuid

Commits

dsymonds  committed 4f1c1d3

go-uuid: Update to Go 1.

R=borman
CC=borman
http://codereview.appspot.com/6255058

Committer: Paul Borman <borman@google.com>

  • Participants
  • Parent commits 3b37edb
  • Branches default

Comments (0)

Files changed (6)

File uuid/Makefile

  • Ignore whitespace
-# Copyright 2011 Google Inc.  All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include ${GOROOT}/src/Make.inc
-
-TARG=go-uuid.googlecode.com/hg/uuid
-GOFILES=\
-	hash.go\
-	dce.go\
-	node.go\
-	uuid.go\
-	util.go\
-	time.go\
-	version1.go\
-	version4.go\
-
-include ${GOROOT}/src/Make.pkg

File uuid/hash.go

View file
  • Ignore whitespace
 	h.Reset()
 	h.Write(space)
 	h.Write([]byte(data))
-	s := h.Sum()
+	s := h.Sum(nil)
 	uuid := make([]byte, 16)
 	copy(uuid, s)
 	uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)

File uuid/node.go

View file
  • Ignore whitespace
 
 package uuid
 
-import (
-	"net"
-	"os"
-)
+import "net"
 
 var (
 	interfaces []net.Interface // cached list of interfaces
 // SetNodeInterface never fails when name is "".
 func SetNodeInterface(name string) bool {
 	if interfaces == nil {
-		var err os.Error
+		var err error
 		interfaces, err = net.Interfaces()
 		if err != nil && name != "" {
 			return false

File uuid/time.go

View file
  • Ignore whitespace
 
 import (
 	"encoding/binary"
-	"os"
+	"time"
 )
 
 // A Time represents a time as the number of 100's of nanoseconds since 15 Oct
 // GetTime returns the current Time (100s of nanoseconds since 15 Oct 1582) and
 // adjusts the clock sequence as needed.  An error is returned if the current
 // time cannot be determined.
-func GetTime() (Time, os.Error) {
-	sec, nsec, err := os.Time()
-	if err != nil {
-		return 0, err
-	}
+func GetTime() (Time, error) {
+	t := time.Now()
 
 	// If we don't have a clock sequence already, set one.
 	if clock_seq == 0 {
 		SetClockSequence(-1)
 	}
-	now := uint64(sec)*10000000 + uint64(nsec)/100 + g1582ns100
+	now := uint64(t.UnixNano()/100) + g1582ns100
 
 	// If time has gone backwards with this clock sequence then we
 	// increment the clock sequence

File uuid/util.go

View file
  • Ignore whitespace
 // randomBits completely fills slice b with random data.
 func randomBits(b []byte) {
 	if _, err := io.ReadFull(rander, b); err != nil {
-		panic(err.String()) // rand should never fail
+		panic(err.Error()) // rand should never fail
 	}
 }
 

File uuid/uuid_test.go

View file
  • Ignore whitespace
 
 	ts, ok := uuid.Time()
 	if ok {
-		s, n := ts.UnixTime()
-		c := time.SecondsToUTC(s)
-		if c.Year != 1998 || c.Month != 2 || c.Day != 5 {
-			t.Errorf("Bad date: %d/%d/%d\n", c.Day, c.Month, c.Year)
-		}
-		if c.Hour != 0 || c.Minute != 30 || c.Second != 23 {
-			t.Errorf("Bad time\n")
-		}
-		if n != 136364800 {
-			t.Errorf("Bad faction of a second\n")
+		c := time.Unix(ts.UnixTime())
+		want := time.Date(1998, 2, 5, 0, 30, 23, 136364800, time.UTC)
+		if !c.Equal(want) {
+			t.Errorf("Got time %v, want %v", c, want)
 		}
 	} else {
 		t.Errorf("%s: bad time\n", uuid)
 
 type badRand struct{}
 
-func (r badRand) Read(buf []byte) (int, os.Error) {
+func (r badRand) Read(buf []byte) (int, error) {
 	for i, _ := range buf {
 		buf[i] = byte(i)
 	}