Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Latest commit

 

History

History
45 lines (33 loc) · 1001 Bytes

README.md

File metadata and controls

45 lines (33 loc) · 1001 Bytes

URL Marshaler

⚠️ THIS LIB HAS BEEN INTEGRATED INTO https://github.com/xescugc/marshaler USE IT INSTEAD ⚠️

GoDoc

It's a simple type that implements the Marshaler and Unmarshaler interfaces for a URL transforming it to an string.

Installation

$> go get github.com/xescugc/url-marshaler

Usage

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

	marshaler "github.com/xescugc/url-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" }
}