1
0
mirror of https://github.com/google/uuid.git synced 2025-02-18 12:24:00 +02:00

go-uuid: Update to Go 1.

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

Committer: Paul Borman <borman@google.com>
This commit is contained in:
David Symonds 2012-05-29 18:05:31 -05:00
parent 1da9265622
commit 7fc15a0835
6 changed files with 13 additions and 43 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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
}
}

View File

@ -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)
}