Skip to content

Marshals different GO standar types

License

Notifications You must be signed in to change notification settings

xescugc/marshaler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marshaler

Adds JSON (for now) Marshal and Unmarshal to different standard GO types

Installation

$> go get github.com/xescugc/marshaler

Usage

It supports 2 types:

Example

import (
	"encoding/json"
	"fmt"
	"net/url"

	"github.com/xescugc/marshaler"
)

type User struct {
  Name  string        `json:"name"`
  URL   marshaler.URL `json:"url"`
}

func main() {
  u, _ := url.Parse("http://example.com")
  usr := User{
    Name: "Pepito",
    URL:  marshaler.URL{
      URL: u,
    },
  }

  b, _ := json.Marshal(usr)

  fmt.Println(string(b))
  // { "name": "Pepito", "url": "http://example.com" }
}