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

xescugc/url-marshaler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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" }
}

Releases

No releases published

Packages

No packages published

Languages