Library to integrate github.com/google/uuid with gopkg.in/vmihailenco/msgpack
go get github.com/citilinkru/uuid-msgpack
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")
}
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
- write code
- run
go fmt ./...
- run all linters and tests (see above)
- create a PR describing the changes
MIT
Nikita Sapogov [email protected]