https://github.com/xescugc/marshaler
Marshals different GO standar types
https://github.com/xescugc/marshaler
currency go golang json marhsaller url
Last synced: about 2 months ago
JSON representation
Marshals different GO standar types
- Host: GitHub
- URL: https://github.com/xescugc/marshaler
- Owner: xescugc
- License: mit
- Created: 2021-01-23T11:57:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-24T10:54:37.000Z (over 5 years ago)
- Last Synced: 2025-07-14T12:41:38.926Z (about 1 year ago)
- Topics: currency, go, golang, json, marhsaller, url
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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:
* [`url.URL`](https://golang.org/pkg/net/url/#URL): With `marshaler.URL`
* [`currency.Unit`](https://pkg.go.dev/golang.org/x/text/currency#Unit): With `marshaler.CurrencyUnit`
## Example
```go
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" }
}
```