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 ¶
- type RawJSON
- func (j RawJSON) IsNil() bool
- func (j RawJSON) IsZero() bool
- func (j RawJSON) MarshalJSON() ([]byte, error)
- func (j RawJSON) MarshalMapValue() (interface{}, error)
- func (j *RawJSON) Scan(src interface{}) error
- func (j *RawJSON) Set(v []byte)
- func (j *RawJSON) SetStr(v string)
- func (j *RawJSON) UnmarshalJSON(data []byte) error
- func (j RawJSON) Value() (driver.Value, error)
- func (j RawJSON) ValueIsZero() (bool, error)
- type SFPoint
- func (p SFPoint) Alt() float64
- func (p SFPoint) IsNil() bool
- func (p SFPoint) IsZero() bool
- func (p SFPoint) Lat() float64
- func (p SFPoint) Lng() float64
- func (p SFPoint) MarshalJSON() ([]byte, error)
- func (p SFPoint) MarshalMapValue() (interface{}, error)
- func (p *SFPoint) Scan(src interface{}) error
- func (p *SFPoint) UnmarshalJSON(data []byte) error
- func (p SFPoint) Value() (driver.Value, error)
- type SFPolygon
- func (p SFPolygon) IsNil() bool
- func (p SFPolygon) IsZero() bool
- func (p SFPolygon) MarshalJSON() ([]byte, error)
- func (p SFPolygon) MarshalMapValue() (interface{}, error)
- func (p *SFPolygon) Scan(src interface{}) error
- func (p *SFPolygon) UnmarshalJSON(data []byte) error
- func (p SFPolygon) Value() (driver.Value, error)
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 ¶
NewJSON will return a new RawJSON object that has been initialized with a copy of the contents of b.
func NewJSONStr ¶
NewJSONStr will return a new RawJSON object that has been initialized with the given string.
func (RawJSON) IsNil ¶
IsNil implements the pyrrho/encoding IsNiler interface. It will return true if j has a length of zero.
func (RawJSON) IsZero ¶
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 ¶
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 ¶
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 ¶
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) UnmarshalJSON ¶
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 ¶
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 ¶
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 ¶
NewSFPointXY constructs and returns a new SFPoint with longitude and latitude components.
func NewSFPointXYZ ¶
NewSFPointXYZ constructs and returns a new SFPoint with longitude, latitude, and altitude components.
func (SFPoint) Alt ¶
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 ¶
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 ¶
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) MarshalJSON ¶
MarshalJSON implements the encoding/json Marshaler interface. It will return the GeoJSON encoded representation of p.
func (SFPoint) MarshalMapValue ¶
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 ¶
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 ¶
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.
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 ¶
NewSFPolygonXY constructs and returns a new SFPolygon object with longitude and latitude components initialized with the given external and (optionally) internal shapes.
func NewSFPolygonXYZ ¶
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 ¶
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 ¶
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 ¶
MarshalJSON implements the encoding/json Marshaler interface. It will return the GeoJSON encoded representation of p.
func (SFPolygon) MarshalMapValue ¶
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 ¶
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 ¶
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.