types

package
v0.0.0-...-15635d3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package types defines a number of helper types that bridge the packages database/sql, encoding, encoding/json, and encoding/maps. Many are simple wrappers around types from other libraries (json.RawMessage), but all implement all of the following interfaces,

  • IsNiler from pyrrho/encoding -- IsNil() bool
  • IsZeroer from pyrrho/encoding -- IsZero() bool
  • Valuer from database/sql/driver -- Value() (driver.Value, error)
  • Scanner from database/sql -- Scan(value interface{}) error
  • Marshaler from encoding/json -- MarshalJSON() ([]byte, error)
  • Unmarshaler from encoding/json -- UnmarshalJSON(data []byte) error
  • Marshaler from pyrrho/encoding/maps -- MarshalMap() (map[string]interface{}, error)
  • Unmarshaler from pyrrho/encoding/maps -- [Pending maps.Unmarshal features]

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RawJSON

type RawJSON []byte

RawJSON is an alternative to the json.RawMessage type. RawJSON implements all of the pyrrho/encoding/types interfaces detailed in the package comments.

This implementation should not be considered safe to use with NULL-able SQL columns; for that application please use the pyrrho/encoding/types/null package, specifically the null.RawJSON type.

func NewJSON

func NewJSON(b []byte) RawJSON

NewJSON will return a new RawJSON object that has been initialized with a copy of the contents of b.

func NewJSONStr

func NewJSONStr(s string) RawJSON

NewJSONStr will return a new RawJSON object that has been initialized with the given string.

func (RawJSON) IsNil

func (j RawJSON) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if j has a length of zero.

func (RawJSON) IsZero

func (j RawJSON) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if j has a length of zero, or if the contained JSON is a zero value. If the parsing the contined JSON results in an error, IsZero will return false.

func (RawJSON) MarshalJSON

func (j RawJSON) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface. Before returning the encoded value, this function will validate the contained JSON and return any parsing errors encountered.

func (RawJSON) MarshalMapValue

func (j RawJSON) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will encode j into its interface{} representation for use in a map[string]interface{} by passing it through json.Unmarshal.

func (*RawJSON) Scan

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

Scan implements the database/sql Scanner interface. It expects to receive a valid JSON string or []byte from an SQL database, and will assign that value to j. Scan will not validatet the incoming JSON.

func (*RawJSON) Set

func (j *RawJSON) Set(v []byte)

Set will copy the contents of v into this RawJSON.

func (*RawJSON) SetStr

func (j *RawJSON) SetStr(v string)

SetStr will copy the contents of v into j.

func (*RawJSON) UnmarshalJSON

func (j *RawJSON) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface. It expects to receive a valid JSON value, and will assign that value to j. UnmarshalJSON will not validate the incoming JSON.

func (RawJSON) Value

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

Value implements the database/sql/driver Valuer interface. It will return the value of j as a driver.Value; specifically a []byte. Before returning the value, this function will validate the contained JSON and return any parsing errors encountered.

func (RawJSON) ValueIsZero

func (j RawJSON) ValueIsZero() (bool, error)

ValueIsZero will return true if the contained JSON is a zero value. If the contained JSON is invalid, ValueIsZero will return false and the resulting JSON parsing error.

type SFPoint

type SFPoint struct {
	geom.Point
}

SFPoint is a Simple Feature Point, named for the OpenGIS specification that backs WKB, WKT, and GeoJSON representations of geospatial data. An SFPoint represents a single [longitude, latitude] or [longitude, latitude, altitude] point in a given coordinate system.

This type is built on top of the go-geom geom.Point type, implementing all of the pyrrho/encoding/types interfaces detailed in the package comments. Database interactions (Value and Scan) will convert to and from a WKB (Well Known Binary) representation. JSON interactions (MarshalJSON and UnmarshalJSON) will convert to and from a GeoJSON representation.

func NewSFPoint

func NewSFPoint(p geom.Point) SFPoint

NewSFPoint constructs and returns a new SFPoint object initialized with the given geom.Point p.

func NewSFPointXY

func NewSFPointXY(x float64, y float64) SFPoint

NewSFPointXY constructs and returns a new SFPoint with longitude and latitude components.

func NewSFPointXYZ

func NewSFPointXYZ(x float64, y float64, z float64) SFPoint

NewSFPointXYZ constructs and returns a new SFPoint with longitude, latitude, and altitude components.

func (SFPoint) Alt

func (p SFPoint) Alt() float64

Alt returns the altitude (third) component of this SFPoint, or 0 if the SFPoint has no altitude component (is an XY SFPoint).

func (SFPoint) IsNil

func (p SFPoint) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if p contains no meaningful data. More specifically, if this if this SFPoint has been zero-initialized, or if it has been explicitly initialized with no layout;

var p types.SFPoint
var p := types.SFPoint{}
var p := types.NewSFPoint(geom.Point{geom.NoLayout})

func (SFPoint) IsZero

func (p SFPoint) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if p.IsNil() returns true, or if the contained data is of the zero-value.

func (SFPoint) Lat

func (p SFPoint) Lat() float64

Lat returns the latitude (easting, second) component of this SFPoint.

func (SFPoint) Lng

func (p SFPoint) Lng() float64

Lng returns the longitude (northing, first) component of this SFPoint.

func (SFPoint) MarshalJSON

func (p SFPoint) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface. It will return the GeoJSON encoded representation of p.

func (SFPoint) MarshalMapValue

func (p SFPoint) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will return p wrapped in an interface{} for use in a map[string]interface{}.

func (*SFPoint) Scan

func (p *SFPoint) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It expects to receive a WKB encoded []byte describing a Point from an SQL database, and will assign that value to p. If the incoming []byte is not a well formed WKB, or if that WKB value does not describe a Point, an error will be returned.

func (*SFPoint) UnmarshalJSON

func (p *SFPoint) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface. It expects to receive a valid GeoJSON Geometry of the type Point, and will assign the value of that data to p.

func (SFPoint) Value

func (p SFPoint) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. It will return the value of p as a driver.Value; specifically a WKB encoded []byte.

type SFPolygon

type SFPolygon struct {
	geom.Polygon
}

SFPolygon is a Simple Feature Polygon, named for the OpenGIS specification that backs WKB, WKT, and GeoJSON representations of geospatial data. An SFPolygon represents a series of [longitude, latitude] or [longitude, latitude, altitude] points in a given coordinate system that make up one external polygon bounding the given shape, and zero or more internal polygons bounding holes within the shape. These polygons should follow the right-hand rule for wrapping order; polygons with a positive area (the external, positive-space shape) should wrap counter-clockwise, and polygons with a negative area (the internal, negative-space holes) should wrap clockwise.

This type is built on top of the go-geom geom.Polygon type, implementing all of the pyrrho/encoding/types interfaces detailed in the package comments. Database interactions (Value and Scan) will convert to and from a WKB (Well Known Binary) representation. JSON interactions (MarshalJSON and UnmarshalJSON) will convert to and from a GeoJSON representation.

func NewSFPolygon

func NewSFPolygon(p geom.Polygon) SFPolygon

NewSFPolygon constructs and returns a new SFPolygon object initialized with the given geom.Polygon p.

func NewSFPolygonXY

func NewSFPolygonXY(external [][2]float64, internals ...[][2]float64) SFPolygon

NewSFPolygonXY constructs and returns a new SFPolygon object with longitude and latitude components initialized with the given external and (optionally) internal shapes.

func NewSFPolygonXYZ

func NewSFPolygonXYZ(external [][3]float64, internals ...[][3]float64) SFPolygon

NewSFPolygonXYZ constructs and returns a new SFPolygon object with longitude, latitude, and altitude components initialized with the given external and (optionally) internal shapes.

func (SFPolygon) IsNil

func (p SFPolygon) IsNil() bool

IsNil implements the pyrrho/encoding IsNiler interface. It will return true if p contains no meaningful data. More specifically, if this if this SFPoint has been zero-initialized, or if it has been explicitly initialized with no layout;

var p types.SFPolygon
var p := types.SFPolygon{}
var p := types.NewSFPolygon(geom.Polygon{geom.NoLayout})
var p := types.NewSFPolygonXY(nil)
var p := types.NewSFPolygonXY([][2]float64{})

func (SFPolygon) IsZero

func (p SFPolygon) IsZero() bool

IsZero implements the pyrrho/encoding IsZeroer interface. It will return true if p.IsNil() returns true, or if the contained data is of the zero-value.

func (SFPolygon) MarshalJSON

func (p SFPolygon) MarshalJSON() ([]byte, error)

MarshalJSON implements the encoding/json Marshaler interface. It will return the GeoJSON encoded representation of p.

func (SFPolygon) MarshalMapValue

func (p SFPolygon) MarshalMapValue() (interface{}, error)

MarshalMapValue implements the pyrrho/encoding/maps Marshaler interface. It will return p wrapped in an interface{} for use in a map[string]interface{}.

func (*SFPolygon) Scan

func (p *SFPolygon) Scan(src interface{}) error

Scan implements the database/sql Scanner interface. It expects to receive a WKB encoded []byte describing a Polygon from an SQL database, and will assign that value to p. If the incoming []byte is not a well formed WKB, or if that WKB value does not describe a Polygon, an error will be returned.

func (*SFPolygon) UnmarshalJSON

func (p *SFPolygon) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the encoding/json Unmarshaler interface. It expects to receive a valid GeoJSON Geometry with of the type Polygon, and will assign the value of that data to p.

func (SFPolygon) Value

func (p SFPolygon) Value() (driver.Value, error)

Value implements the database/sql/driver Valuer interface. It will return the value of p as a driver.Value; specifically a WKB encoded []byte.

Directories

Path Synopsis
Package null defines a number of nullable types that bridge the packages database/sql, encoding, encoding/json, and encoding/maps.
Package null defines a number of nullable types that bridge the packages database/sql, encoding, encoding/json, and encoding/maps.

Jump to

Keyboard shortcuts

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