Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 784 Bytes

README.md

File metadata and controls

47 lines (34 loc) · 784 Bytes

nullable

Go Reference Report card

A way to represent nullable types in Go with JSON serialization.

Usage

go get github.com/syntaqx/nullable

Example

package main

import (
	"database/sql"
	"encoding/json"
	"fmt"

	"github.com/syntaqx/nullable"
)

type User struct {
	ID   nullable.Int64
	Name nullable.String
}

func main() {
	u := User{
		Name: nullable.String{
			sql.NullString{String: "John Doe", Valid: true},
		},
	}

	b, err := json.Marshal(u)
	if err != nil {
		panic(err)
	}

	fmt.Println(string(b))
}