diff --git a/uuid/Makefile b/uuid/Makefile deleted file mode 100644 index 2000732..0000000 --- a/uuid/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -# 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 diff --git a/uuid/hash.go b/uuid/hash.go index 89cda5b..cdd4192 100644 --- a/uuid/hash.go +++ b/uuid/hash.go @@ -28,7 +28,7 @@ func NewHash(h hash.Hash, space UUID, data []byte, version int) UUID { 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) diff --git a/uuid/node.go b/uuid/node.go index fd607b4..dd0a8ac 100755 --- a/uuid/node.go +++ b/uuid/node.go @@ -4,10 +4,7 @@ package uuid -import ( - "net" - "os" -) +import "net" var ( interfaces []net.Interface // cached list of interfaces @@ -30,7 +27,7 @@ func NodeInterface() string { // 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 diff --git a/uuid/time.go b/uuid/time.go index 27625e6..3105c52 100755 --- a/uuid/time.go +++ b/uuid/time.go @@ -6,7 +6,7 @@ package uuid import ( "encoding/binary" - "os" + "time" ) // A Time represents a time as the number of 100's of nanoseconds since 15 Oct @@ -38,17 +38,14 @@ func (t Time) UnixTime() (sec, nsec int64) { // 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 diff --git a/uuid/util.go b/uuid/util.go index 748ca2a..de40b10 100644 --- a/uuid/util.go +++ b/uuid/util.go @@ -11,7 +11,7 @@ import ( // 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 } } diff --git a/uuid/uuid_test.go b/uuid/uuid_test.go index e38c332..7f2997b 100755 --- a/uuid/uuid_test.go +++ b/uuid/uuid_test.go @@ -270,16 +270,10 @@ func TestNodeAndTime(t *testing.T) { 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) @@ -365,7 +359,7 @@ func TestDCE(t *testing.T) { 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) }