Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Latest commit

 

History

History
42 lines (34 loc) · 724 Bytes

README.md

File metadata and controls

42 lines (34 loc) · 724 Bytes

Go Marshaller

A simple library for marshalling / unmarshalling objects to/from byte arrays in go

Example

import (
  ...
  reqmarshaller "github.com/c3systems/c3-utils-go-marshaller/http/req"
  ...
)

func foo(r *http.Request) error {
  tr, err := reqmarshal.TransformRequest(r)
  if err != nil {
    return err
  }

  b, err := tr.Marshal()
  if err != nil {
    return err
   }

   // do something with the bytes array, b
   // ...

}

func bar(b []byte) error {
  tr := new(reqmarshal.TransformedRequest)
  if err := tr.Unmarshal(b); err != nil {
    return err
   }

   r, err := reqmarshal.UntransformRequest(tr)
   if err != nil {
    return err
   }

   // do something with the request, r
   // ...
}