Skip to content

disgoorg/omit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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("test@example.com"),
	}

	// 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages