...

Source file src/github.com/pborman/uuid/node.go

Documentation: github.com/pborman/uuid

     1  // Copyright 2011 Google Inc.  All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package uuid
     6  
     7  import (
     8  	guuid "github.com/google/uuid"
     9  )
    10  
    11  // NodeInterface returns the name of the interface from which the NodeID was
    12  // derived.  The interface "user" is returned if the NodeID was set by
    13  // SetNodeID.
    14  func NodeInterface() string {
    15  	return guuid.NodeInterface()
    16  }
    17  
    18  // SetNodeInterface selects the hardware address to be used for Version 1 UUIDs.
    19  // If name is "" then the first usable interface found will be used or a random
    20  // Node ID will be generated.  If a named interface cannot be found then false
    21  // is returned.
    22  //
    23  // SetNodeInterface never fails when name is "".
    24  func SetNodeInterface(name string) bool {
    25  	return guuid.SetNodeInterface(name)
    26  }
    27  
    28  // NodeID returns a slice of a copy of the current Node ID, setting the Node ID
    29  // if not already set.
    30  func NodeID() []byte {
    31  	return guuid.NodeID()
    32  }
    33  
    34  // SetNodeID sets the Node ID to be used for Version 1 UUIDs.  The first 6 bytes
    35  // of id are used.  If id is less than 6 bytes then false is returned and the
    36  // Node ID is not set.
    37  func SetNodeID(id []byte) bool {
    38  	return guuid.SetNodeID(id)
    39  }
    40  
    41  // NodeID returns the 6 byte node id encoded in uuid.  It returns nil if uuid is
    42  // not valid.  The NodeID is only well defined for version 1 and 2 UUIDs.
    43  func (uuid UUID) NodeID() []byte {
    44  	if len(uuid) != 16 {
    45  		return nil
    46  	}
    47  	node := make([]byte, 6)
    48  	copy(node, uuid[10:])
    49  	return node
    50  }
    51  

View as plain text