jsontypes

package
v0.2024.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

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

type Duration struct {
	time.Duration
}

Duration wraps a time.Duration. It marshals / unmarshals to a string with the time.ParseDuration format.

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) Or

func (d *Duration) Or(ifAbsent time.Duration) time.Duration

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

func (d *Duration) UnmarshalJSON(raw []byte) error

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.

func (PEM) Read

func (p PEM) Read(base string) ([]byte, error)

Read reads the contents of p, the file or string. If p is a path, it is resolved relative to base.

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.

func (Password) Read

func (c Password) Read() (string, error)

Read returns the password, either from Password or PasswordFile.

type Schedule

type Schedule struct {
	cron.Schedule
	Raw string
}

Schedule represent a cron formatted schedule suitable for including in json types.

func MustParseSchedule

func MustParseSchedule(raw string) *Schedule

MustParseSchedule parses a cron formatted schedule and panics if it fails.

func (*Schedule) MarshalJSON

func (s *Schedule) MarshalJSON() ([]byte, error)

func (*Schedule) String

func (s *Schedule) String() string

func (*Schedule) UnmarshalJSON

func (s *Schedule) UnmarshalJSON(bytes []byte) error

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

func (s String) IsPath() bool

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.

func (String) OpenBase

func (s String) OpenBase(base string) (io.ReadCloser, error)

OpenBase returns a reader for the contents of s, the file or string. Paths are resolved relative to base.

func (String) Read

func (s String) Read() (string, error)

Read reads 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.

func (*TLSConfig) Read

func (c *TLSConfig) Read(base string, hubCfg *tls.Config) (*tls.Config, error)

Read converts c to a tls.Config. Files read are resolved relative to base. If hubCfg is not nil - and IgnoreHub is false - then hubCfg is used as a base for the returned tls.Config.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL