Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

disgoorg/omit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

5 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:

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 or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Languages

AltStyle によって変換されたページ (->オリジナル) /