All Projects → emvi → null

emvi / null

Licence: MIT license
Nullable Go types that can be marshalled/unmarshalled to/from JSON.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to null

fritz
Astronomical data platform for the Zwicky Transient Facility.
Stars: ✭ 20 (-28.57%)
Mutual labels:  marshal
Outlaw
JSON mapper for macOS, iOS, tvOS, and watchOS
Stars: ✭ 24 (-14.29%)
Mutual labels:  marshal
jrecordbind
Tiny and super fast fixed-length files reader/parser
Stars: ✭ 29 (+3.57%)
Mutual labels:  marshal
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+335.71%)
Mutual labels:  unmarshal
rmarsh
Ruby Marshal 4.8 encoder/decoder in Golang. Why? Who knows.
Stars: ✭ 15 (-46.43%)
Mutual labels:  marshal
cffi
Safe* C foreign function interface for Rust, using proc macros and marshaling types.
Stars: ✭ 15 (-46.43%)
Mutual labels:  marshal
ex marshal
Ruby Marshal format implemented in Elixir
Stars: ✭ 37 (+32.14%)
Mutual labels:  marshal
eclipse-null-eea-augments
Eclipse External null Annotations (EEA) repository
Stars: ✭ 34 (+21.43%)
Mutual labels:  nullable
nanoption
Tiny (220 bytes), zero dependency wrapper for nullable values
Stars: ✭ 23 (-17.86%)
Mutual labels:  nullable

Nullable Go types

Go Reference CircleCI Go Report Card Chat on Discord

Description

This package provides nullable Go types for bool, float64, int64, int32, string and time.Time replacing sql.NullString, sql.NullInt64, ... that can be marshalled/unmarshalled to/from JSON.

Installation

To install "null", run go get within your project:

go get github.com/emvi/null

Note that from 1.3 on "null" requires Go version 1.13 or newer.

Usage

Here is a short example demonstrating the string type. The other types (int64, float64 and bool) work in the same manner.

package main

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

    "github.com/emvi/null"
)

type NullableString struct {
    Value null.String `json:"value"`
}

func main() {
    str := NullableString{null.NewString("nullable string", true)}
    // or long version: str := NullableString{null.String{sql.NullString{String: "nullable string", Valid: true}}}
    
    data, _ := json.Marshal(str)
    fmt.Println(string(data)) // -> {"value": "nullable"}

    str.SetNil() // use str.SetValid("value") to set a value again
    data, _ = json.Marshal(str)
    fmt.Println(string(data)) // -> {"value": null}
}

Contribute

See CONTRIBUTING.md

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].