Skip to content

Library for integrating github.com/google/uuid with gopkg.in/vmihailenco/msgpack.v2.

License

Notifications You must be signed in to change notification settings

citilinkru/uuid-msgpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UUID msgpack

Lint Tests codecov Go Report Card License GoDoc Release

Library to integrate github.com/google/uuid with gopkg.in/vmihailenco/msgpack

Installation

go get github.com/citilinkru/uuid-msgpack

Example

package main

import (
	_ "github.com/citilinkru/uuid-msgpack" // This blank import is required to register encoder/decoder!
	"github.com/google/uuid"
	"log"
	"bytes"
	"gopkg.in/vmihailenco/msgpack.v2" 
)

func main() {
	id := uuid.New()
	buf := bytes.NewBuffer(nil)
	encoder := msgpack.NewEncoder(buf)
	err := encoder.Encode(id)
	if err != nil {
		log.Fatalf("can't encode uuid: %s", err)
	}
	reader := bytes.NewReader(buf.Bytes())
	decoder := msgpack.NewDecoder(reader)
	var decodedId uuid.UUID
	err = decoder.Decode(&decodedId)
	if err != nil {
		log.Fatalf("can't decode uuid: %s", err)
	}

	if id.String() == decodedId.String() {
		log.Printf("original id is equal to decoded '%s'\n", id)
	} else {
		log.Printf("decoded id '%s' is not equal to origin '%s'\n", id, decodedId)
	}
	
	log.Println("done")
}

Testing

Unit-tests:

go test -v -race ./...

Run linter:

go mod vendor \
  && docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.40 golangci-lint run -v \
  && rm -R vendor

CONTRIBUTE

  • write code
  • run go fmt ./...
  • run all linters and tests (see above)
  • create a PR describing the changes

LICENSE

MIT

AUTHOR

Nikita Sapogov [email protected]

About

Library for integrating github.com/google/uuid with gopkg.in/vmihailenco/msgpack.v2.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages