Skip to content

Latest commit

 

History

History
69 lines (48 loc) · 2.01 KB

README.md

File metadata and controls

69 lines (48 loc) · 2.01 KB

Go Reference Go Report Go Version License omit Version Discord

omit

omit is a simple library to handle optional and nullable struct field values for json serialization and deserialization in golang.

Installation

go get github.com/disgoorg/omit

Usage

package main

import (
	"encoding/json"
	"fmt"

	"github.com/disgoorg/omit"
)

type User struct {
	ID    int                `json:"id"`
	Name  string             `json:"name"`
	Email omit.Omit[*string] `json:"email,omitzero"`
}

func main() {
	u := User{
		ID:    1,
		Name:  "John Doe",
		Email: omit.NewPtr("[email protected]"),
	}

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

	fmt.Println(string(data))
}

Documentation

Documentation is wip and can be found under:

  • Go Reference

Troubleshooting

For help feel free to open an issue or reach out on Discord

Contributing

Contributions are welcomed but for bigger changes we recommend first reaching out via Discord or create an issue to discuss your problems, intentions and ideas.

License

Distributed under the License. See LICENSE for more information.