Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

Implement json.Marshaller interface for Inet, Macaddr (et al.) #79

@atz

Description

@atz

Application JSON data coming in (or going out) should not know (or reveal) anything about our underlying implementation model. For a given struct like:

type My struct {
  IP pgtype.Inet
  MAC pgtype.Macaddr
}

Populated accordingly, it would be reasonable for json.Marshall to deliver bytes equivalent to (for example):

{"IP":"192.0.2.1/32","MAC":"00:0a:95:9d:68:16"}

Symmetrically, json.Unmarshal should be able reconstitute the struct from the serialized JSON. Can probably submit a PR for some of this if you concur. Currently that would give an error like:

json: cannot unmarshal string into Go struct field My.IP of type pgtype.Inet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions