Documentation ¶
Overview ¶
Package jsontypes contains utility / wrapper types that are suitable for JSON marshalling / unmarshalling using the standard library json package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Duration ¶
Duration wraps a time.Duration. It marshals / unmarshals to a string with the time.ParseDuration format.
func (Duration) MarshalJSON ¶
func (*Duration) Or ¶
Or returns d.Duration if d is not nil, or ifAbsent if d is nil. Or only really works if Duration is used as a pointer
type Config struct { TTL *Duration // pointer type } ttl := config.TTL.Or(15*time.Minute)
func (*Duration) UnmarshalJSON ¶
type PEM ¶
type PEM string
PEM represents one or more PEM encoded blocks. When encoded in json it is either a string of PEM encoded blocks, or a path to file containing PEM encoded blocks. See String.IsPath for how we tell the difference.
type Password ¶
type Password struct { Password string `json:"password,omitempty"` PasswordFile string `json:"passwordFile,omitempty"` }
Password allows specifying a password either directly or via a password file.
type Schedule ¶
type Schedule struct { cron.Schedule Raw string }
Schedule represent a cron formatted schedule suitable for including in json types.
func MustParseSchedule ¶
MustParseSchedule parses a cron formatted schedule and panics if it fails.
func (*Schedule) MarshalJSON ¶
func (*Schedule) UnmarshalJSON ¶
type String ¶
type String string
String is either a literal string or a string loaded from a file. If the contents of String are an absolute path or start with a dot, the contents are loaded from a file. Otherwise, the contents are used as-is.
func (String) IsPath ¶
IsPath returns whether s looks like a filesystem path or not. Filesystem paths are either absolute paths or paths starting with a dot. Absolute paths are defined by filepath.IsAbs.
func (String) Open ¶
func (s String) Open() (io.ReadCloser, error)
Open returns a reader for the contents of s, the file or string.
type TLSCertificate ¶
type TLSCertificate struct { Certificate PEM `json:"certificate,omitempty"` PrivateKey PEM `json:"privateKey,omitempty"` }
TLSCertificate models a tls.Certificate as json.
func (*TLSCertificate) Read ¶
func (c *TLSCertificate) Read(base string) (tls.Certificate, error)
Read returns a tls.Certificate from the config in c. The certificate and private key will be validated as a matching pair, like tls.X509KeyPair.
type TLSConfig ¶
type TLSConfig struct { // IgnoreHub controls whether hub configured TLS settings are ignored. // If IgnoreHub is true then even if the client is enrolled with a hub, the hub provided TLS settings will be ignored. IgnoreHub bool `json:"ignoreHub,omitempty"` // These settings match their equivalents in [tls.Config]. InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"` Certificates []TLSCertificate `json:"certificates,omitempty"` RootCAs PEM `json:"rootCAs,omitempty"` }
TLSConfig models a tls.Config as json. Call [Read] to convert it to a *tls.Config.