github.com/brycereitano/goa@v0.0.0-20170315073847-8ffa6c85e265/uuid/uuid.go (about)

     1  // +build !js
     2  
     3  //This is just a declaration of the uuid.UUID which doesn't work with gopherjs
     4  //See uuid_js.go for the JS implementation
     5  
     6  package uuid
     7  
     8  import "github.com/satori/go.uuid"
     9  
    10  // FromString Wrapper around the real FromString
    11  func FromString(input string) (UUID, error) {
    12  	u, err := uuid.FromString(input)
    13  	return UUID(u), err
    14  }
    15  
    16  // NewV4 Wrapper over the real NewV4 method
    17  func NewV4() UUID {
    18  	return UUID(uuid.NewV4())
    19  }
    20  
    21  // String Wrapper over the real String method
    22  func (u UUID) String() string {
    23  	return uuid.UUID(u).String()
    24  }
    25  
    26  // MarshalText Wrapper over the real MarshalText method
    27  func (u UUID) MarshalText() (text []byte, err error) {
    28  	return uuid.UUID(u).MarshalText()
    29  }
    30  
    31  // MarshalBinary Wrapper over the real MarshalBinary method
    32  func (u UUID) MarshalBinary() ([]byte, error) {
    33  	return uuid.UUID(u).MarshalBinary()
    34  }
    35  
    36  // UnmarshalBinary Wrapper over the real UnmarshalBinary method
    37  func (u *UUID) UnmarshalBinary(data []byte) error {
    38  	t := uuid.UUID{}
    39  	err := t.UnmarshalBinary(data)
    40  	for i, b := range t.Bytes() {
    41  		u[i] = b
    42  	}
    43  	return err
    44  }
    45  
    46  // UnmarshalText Wrapper over the real UnmarshalText method
    47  func (u *UUID) UnmarshalText(text []byte) error {
    48  	t := uuid.UUID{}
    49  	err := t.UnmarshalText(text)
    50  	for i, b := range t.Bytes() {
    51  		u[i] = b
    52  	}
    53  	return err
    54  }