uuidmsgpack

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2023 License: MIT Imports: 5 Imported by: 0

README

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 amstaffix@gmail.com

Documentation

Overview

Package uuidmsgpack register msgpack encoder/decoder for uuid lib

Just import that package in your main and you can encode/decode like any struct

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL