types

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package types provides a set of common data types that implement the relevant interfaces for use within gondulapi.

In general, that means implementing JSON marshaling/unmarshaling and database/sql's Scanner and driver.Value interface for SQL operations.

Any data type that implement JSON marshaling and can be handled by SQL can be used without any further scaffolding. So these data types are just a bit outside of the norm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Box added in v0.0.7

type Box struct {
	X1 int
	X2 int
	Y1 int
	Y2 int
}

Box contains the two opposing corners of a geometric box, matching Postgres' box type.

Please note that Postgresql will always place the upper right corner first - so X1/Y1 might be X2/Y2 when you read it back out - but the semantics are correct.

func (*Box) Scan added in v0.0.7

func (b *Box) Scan(src interface{}) error

Scan implements sql.Scan to enable gondulapi/db to read the SQL directly into the box.

func (Box) Value added in v0.0.7

func (b Box) Value() (driver.Value, error)

Value implements sql/driver's Value interface to provide implicit support for writing the value.

In other words: Scan() enables SELECT and Value() allows INSERT/UPDATE.

type IP

type IP struct {
	IP   net.IP
	Mask int
}

IP represent an IP and an optional netmask/size. It is provided because while net/IP provides much of what is needed for marshalling to/from text and json, it doesn't provide a convenient netmask. And it doesn't implement database/sql's Scanner either. This type implements both MarshalText/UnmarshalText and Scan(), and to top it off: String(). this should ensure maximum usability.

func NewIP added in v0.0.8

func NewIP(src string) (IP, error)

NewIP parses the text string and returns it as an IP data structure

func (IP) MarshalText

func (i IP) MarshalText() ([]byte, error)

MarshalText returns a text version of an ip using String, it is used by various encoders, including the JSON encoder.

func (*IP) Scan

func (i *IP) Scan(src interface{}) error

Scan is used by database/sql's Scan to parse bytes to an IP structure.

func (*IP) String

func (i *IP) String() string

String returns a ip address in string format, with an optional /mask if the IP has a non-zero mask.

func (*IP) UnmarshalText

func (i *IP) UnmarshalText(b []byte) error

UnmarshalText parses a byte string onto an IP structure. It is used by various encoders, including the JSON encoder.

func (IP) Value added in v0.0.2

func (i IP) Value() (driver.Value, error)

Value implements sql/driver's Value interface to provide implicit support for writing the value.

type Jsonb added in v0.0.8

type Jsonb struct {
	Data interface{}
}

Jsonb is a wrapper around an empty interface to enable adding methods to it. The wrapping is hidden both from SQL and JSON through a ton of dummy-methods.

func (*Jsonb) MarshalJSON added in v0.0.8

func (j *Jsonb) MarshalJSON() ([]byte, error)

MarshalJSON qwrasfaksfjasklfjasf

func (Jsonb) MarshalText added in v0.0.8

func (j Jsonb) MarshalText() ([]byte, error)

MarshalText returns a byte-string of the string representation of the object and this documentation, I'm sure, is very helpful.

func (*Jsonb) Scan added in v0.0.8

func (j *Jsonb) Scan(src interface{}) error

Scan is used by database/sql's Scan to parse bytes

func (Jsonb) String added in v0.0.8

func (j Jsonb) String() string

String JSON marshals the data and returns it. AS A STRING.

func (*Jsonb) UnmarshalJSON added in v0.0.8

func (j *Jsonb) UnmarshalJSON(b []byte) error

UnmarshalJSON is here just to make lint-software think this is a sensible way of writing documentation.

func (*Jsonb) UnmarshalText added in v0.0.8

func (j *Jsonb) UnmarshalText(b []byte) error

UnmarshalText un marshals the text. Weird.

func (Jsonb) Value added in v0.0.8

func (j Jsonb) Value() (driver.Value, error)

Value wraps String() for the sake of sql.

Jump to

Keyboard shortcuts

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