Browse Source

Removed the unused err reporting from NewUUID()

deiu 7 years ago
parent
commit
d43c97b766
3 changed files with 6 additions and 23 deletions
  1. 4 6
      ldp.go
  2. 1 16
      ldp_test.go
  3. 1 1
      server.go

+ 4 - 6
ldp.go

@@ -137,15 +137,13 @@ func (l *Linkheaders) MatchURI(uri string) bool {
 	return false
 }
 
-func newUUID() (string, error) {
+// NewUUID generates a new UUID string
+func NewUUID() string {
 	uuid := make([]byte, 16)
-	n, err := io.ReadFull(rand.Reader, uuid)
-	if n != len(uuid) || err != nil {
-		return "", err
-	}
+	io.ReadFull(rand.Reader, uuid)
 	uuid[8] = uuid[8]&^0xc0 | 0x80
 	uuid[6] = uuid[6]&^0xf0 | 0x40
-	return hex.EncodeToString(uuid), nil
+	return hex.EncodeToString(uuid)
 }
 
 // NewETag generates ETag

+ 1 - 16
ldp_test.go

@@ -1,7 +1,6 @@
 package gold
 
 import (
-	"fmt"
 	"testing"
 
 	"github.com/stretchr/testify/assert"
@@ -48,20 +47,6 @@ func TestPreferHeaderParser(t *testing.T) {
 }
 
 func TestNewUUID(t *testing.T) {
-	uuid, err := newUUID()
-	assert.Nil(t, err)
+	uuid := NewUUID()
 	assert.Equal(t, 32, len(uuid))
 }
-
-func BenchmarkNewUUID(b *testing.B) {
-	e := 0
-	for i := 0; i < b.N; i++ {
-		if _, err := newUUID(); err != nil {
-			e++
-		}
-	}
-	if e > 0 {
-		b.Log(fmt.Sprintf("%d/%d failed", e, b.N))
-		b.Fail()
-	}
-}

+ 1 - 1
server.go

@@ -790,7 +790,7 @@ func (s *Server) handle(w http.ResponseWriter, req *httpRequest) (r *response) {
 			link := ParseLinkHeader(req.Header.Get("Link")).MatchRel("type")
 			slug := req.Header.Get("Slug")
 
-			uuid, err := newUUID()
+			uuid := NewUUID()
 			if err != nil {
 				s.debug.Println("POST LDP UUID err: " + err.Error())
 				return r.respond(500, err)