types

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAuthorized defines a not authorized error
	ErrNotAuthorized = NewError().Status(http.StatusUnauthorized).Format("not authorized")

	// ErrInvalidParameter defines an invalid parameter error
	ErrInvalidParameter = NewError().Status(http.StatusBadRequest).Format("invalid parameter")

	// ErrNotImplemented defines a not implemented error
	ErrNotImplemented = NewError().Status(http.StatusNotImplemented).FormatFunc("method '%s' not implemented")

	// ErrResourceConflict is returned when an object conflicts with one that already exists
	ErrResourceConflict = NewError().Status(http.StatusConflict).FormatFunc("'%s' conflicts with one that already exists")

	// ErrNotFound is is returned when an object was not found
	ErrNotFound = NewError().Status(http.StatusNotFound).FormatFunc("'%s' not found")

	// ErrServerError is reserved for server errors
	ErrServerError = NewError().Status(http.StatusInternalServerError).FormatFunc("server error: %s")
)
View Source
var (
	// NoContentResponse is a no content HTTP success response
	NoContentResponse = NewResponse().SetStatus(http.StatusNoContent)

	// SeeOtherResponse returns a redirect response
	SeeOtherResponse = func(loc string) *Response {
		return NewResponse().SetStatus(http.StatusSeeOther).SetHeader("Location", loc)
	}
)
View Source
var ModelGenerateUUID = false

ModelGenerateUUID is a flag to tell sparks to generate a new uuid for the models

Functions

This section is empty.

Types

type Caster added in v1.1.3

type Caster interface {
	String() string
	StringPtr() *string
	StringSlice() []string
	Bool() bool
	Int64() int64
	Float64() float64
	Slice() []interface{}
	StringMap() StringMap
}

Caster defines a simple casting interface

type Error

type Error struct {
	Code    *string           `json:"code,omitempty"`
	Message *string           `json:"message,omitempty"`
	Detail  map[string]string `json:"detail,omitempty"`
	// contains filtered or unexported fields
}

Error is the common error struct compatible with swagger response types

func NewError

func NewError(err ...error) *Error

NewError returns a new models.Error from a go error

func (*Error) BodyLength

func (e *Error) BodyLength() int

BodyLength returns the http body length in bytes

func (*Error) Err

func (e *Error) Err() error

Err returns the underlining error

func (*Error) Error

func (e *Error) Error() string

Err returns the go error

func (*Error) ErrorCode

func (e *Error) ErrorCode(code string) *Error

ErrorCode sets the error code

func (*Error) Format

func (e *Error) Format(msg string, args ...interface{}) *Error

Format formats the error message

func (*Error) FormatFunc

func (e *Error) FormatFunc(msg string) func(args ...interface{}) *Error

FormatFunc func formats a error message functor

func (*Error) Header

func (e *Error) Header() http.Header

Header returns the http header

func (*Error) Reason

func (e *Error) Reason(args ...interface{}) *Error

Reason sets the detail for the error

func (*Error) Scan

func (e *Error) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (*Error) Status

func (e *Error) Status(status int) *Error

Status sets the http status

func (*Error) StatusCode

func (e *Error) StatusCode() int

StatusCode returns the http statuscode

func (*Error) String

func (e *Error) String() string

func (*Error) Validate

func (*Error) Validate(formats strfmt.Registry) error

Validate handles the strfmt validation for the StringArray object

func (Error) Value

func (e Error) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

func (*Error) WriteResponse

func (e *Error) WriteResponse(rw http.ResponseWriter, pr runtime.Producer)

WriteResponse implements the middleware.Responder interface

type Link struct {

	// expires at
	ExpiresAt int64 `json:"expires_at,omitempty"`

	// the target url/uri
	// Format: uri
	Href strfmt.URI `json:"href,omitempty"`

	// optional link name
	Name *string `json:"name,omitempty"`
}

Link an href link object swagger:model Link

func (*Link) MarshalBinary

func (m *Link) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (*Link) UnmarshalBinary

func (m *Link) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*Link) Validate

func (m *Link) Validate(formats strfmt.Registry) error

Validate validates this link

type MapFilter added in v1.1.0

type MapFilter func(index int, val interface{}) (string, interface{}, bool)

MapFilter returns true and the key and value, or false if the value should be skipped

type Mapper added in v1.1.0

type Mapper interface {
	IsSet(key interface{}) bool
	Set(key, value interface{})
	Get(key interface{}) interface{}
	Cast(key interface{}) Caster
	Sub(key interface{}) Mapper
	Delete(key interface{})
	Copy() Mapper
	Without(keys ...interface{}) Mapper
}

Mapper provides a map wrapper interface for working easily with unknown map types

func Map added in v1.1.0

func Map(m interface{}) Mapper

Map returns a Mapper from the passed map

type Model

type Model struct {
	// Table unique identifier
	// Read Only: true
	ID int64 `json:"id"`

	// Universally unique identifier
	// Read Only: true
	UUID *strfmt.UUID `json:"uuid,omitempty"`

	// Date and time of object creation
	// Read Only: true
	CreatedAt strfmt.DateTime `json:"_created_at,omitempty" sql:"column:_created_at"`

	// User uuid that created the object
	// Read Only: true
	CreatedBy string `json:"_created_by,omitempty" sql:"column:_created_by"`

	// Last date of object modification
	// Read Only: true
	UpdatedAt strfmt.DateTime `json:"_updated_at,omitempty" sql:"column:_updated_at"`

	// User that updated the object
	// Read Only: true
	UpdatedBy string `json:"_updated_by,omitempty" sql:"column:_updated_by"`

	// meta
	Meta StringMap `json:"meta,omitempty"`

	// tags
	Tags StringArray `json:"tags,omitempty"`
}

Model is the base datebase model type used by Model Rocket

func (*Model) BeforeCreate added in v1.3.0

func (m *Model) BeforeCreate() (err error)

BeforeCreate hooks the gorm on create

func (*Model) MarshalBinary

func (m *Model) MarshalBinary() ([]byte, error)

MarshalBinary interface implementation

func (*Model) UnmarshalBinary

func (m *Model) UnmarshalBinary(b []byte) error

UnmarshalBinary interface implementation

func (*Model) Validate

func (m *Model) Validate(formats strfmt.Registry) error

Validate validates this base model

type Params

type Params = StringMap

Params is a simple type alias for a Map

func ParseStringParams

func ParseStringParams(s string) Params

ParseStringParams parses a parameter string and returns a params object Example string: foo=bar aparam="value"

type Response

type Response struct {
	// contains filtered or unexported fields
}

Response defines a simple middleware.Responder struct

func NewResponse

func NewResponse(options ...*ResponseOptions) *Response

NewResponse returns a new response object

func (*Response) Body

func (r *Response) Body() []byte

Body returns the body

func (*Response) Copy

func (r *Response) Copy() *Response

Copy copies a response

func (*Response) Header

func (r *Response) Header() http.Header

Header implements the http.ResponseWriter

func (*Response) Length

func (r *Response) Length() int

Length returns the response length

func (*Response) SetAcceleration

func (r *Response) SetAcceleration(acc bool) *Response

SetAcceleration enables json acceleration

func (*Response) SetHeader

func (r *Response) SetHeader(name, value string) *Response

SetHeader sets additional response headers

func (*Response) SetHeaderMap

func (r *Response) SetHeaderMap(vals map[string]string) *Response

SetHeaderMap sets additional response headers

func (*Response) SetHeaders

func (r *Response) SetHeaders(h http.Header) *Response

SetHeaders sets all of the headers

func (*Response) SetOptions

func (r *Response) SetOptions(options ...*ResponseOptions) *Response

SetOptions sets the options for a response

func (*Response) SetPayload

func (r *Response) SetPayload(payload interface{}) *Response

SetPayload sets the payload

func (*Response) SetStatus

func (r *Response) SetStatus(s int) *Response

SetStatus sets the response http status

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode returns the response http status code

func (*Response) Write

func (r *Response) Write(body []byte) (int, error)

Write implements the http.ResponseWriter.Write() method

func (*Response) WriteHeader

func (r *Response) WriteHeader(statusCode int)

WriteHeader implements the http.ResponseWriter.WriteHeader() method

func (*Response) WriteResponse

func (r *Response) WriteResponse(rw http.ResponseWriter, pr runtime.Producer)

WriteResponse implements the middleware.Responder.WriteResponse() method

type ResponseOptions

type ResponseOptions struct {
	Request      *http.Request
	Encoding     string
	ContentType  string
	Binary       bool
	Acceleration bool
}

ResponseOptions defines responder options

type Slicer added in v1.1.0

type Slicer interface {
	Append(vals ...interface{})
	Insert(index int, val interface{})
	IndexOf(val interface{}) int
	Remove(index int)
	Map(out interface{}, filters ...MapFilter)
	Contains(values ...interface{}) bool
	ContainsAny(values ...interface{}) bool
}

Slicer is a generic slice manipulation interface helper

func Slice added in v1.1.0

func Slice(s interface{}) Slicer

Slice returns a slicer object from a pointer to a slice

v := make([]string, 0)
util.Slice(&v).Append("foo")

type StringArray

type StringArray pq.StringArray

StringArray is a proper string array type

func (*StringArray) Scan

func (a *StringArray) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (*StringArray) Validate

func (*StringArray) Validate(formats strfmt.Registry) error

Validate handles the strfmt validation for the StringArray object

func (StringArray) Value

func (a StringArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type StringMap

type StringMap map[string]interface{}

StringMap is a wrapper on a map[string]interface{} that implements the Mapper interface

func (StringMap) Bool added in v1.1.0

func (p StringMap) Bool(key string, def ...bool) bool

Bool parses and returns the boolean value of the parameter

func (StringMap) Cast added in v1.1.3

func (p StringMap) Cast(key interface{}) Caster

Cast returns Caster to convert the value to another type

func (StringMap) Copy added in v1.1.0

func (p StringMap) Copy() Mapper

Copy does a shallow copy

func (StringMap) Delete added in v1.1.0

func (p StringMap) Delete(key interface{})

Delete removes a key

func (StringMap) Float64 added in v1.1.0

func (p StringMap) Float64(key string, def ...float64) float64

Float64 returns the float value or 0 if not set

func (StringMap) Get added in v1.1.0

func (p StringMap) Get(key interface{}) interface{}

Get returns the value and if the key is set

func (StringMap) GetValue added in v1.1.0

func (p StringMap) GetValue(key string) (Value, bool)

GetValue returns a Value and if the key is set

func (StringMap) Int64 added in v1.1.0

func (p StringMap) Int64(key string, def ...int64) int64

Int64 returns the int value or 0 if not set

func (StringMap) IsSet added in v1.1.0

func (p StringMap) IsSet(key interface{}) bool

IsSet returns true if the parameter is set

func (*StringMap) Scan added in v1.1.0

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

Scan implements the sql.Scanner interface

func (StringMap) Set added in v1.1.0

func (p StringMap) Set(key, value interface{})

Set sets a value in the map

func (StringMap) String added in v1.1.0

func (p StringMap) String(key string, def ...string) string

String returns a string value for the param, or the optional default

func (StringMap) StringPtr added in v1.1.0

func (p StringMap) StringPtr(key string, def ...string) *string

StringPtr returns a string ptr or nil

func (StringMap) StringSlice added in v1.1.0

func (p StringMap) StringSlice(key string) []string

StringSlice returns a string value for the param, or the optional default

func (StringMap) Sub added in v1.1.0

func (p StringMap) Sub(key interface{}) Mapper

Sub returns a sub StringMap for the key

func (*StringMap) Validate

func (*StringMap) Validate(formats strfmt.Registry) error

Validate handles the strfmt validation for the StringArray object

func (StringMap) Value added in v1.1.0

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

Value implements the driver.Valuer interface.

func (StringMap) Without added in v1.1.0

func (p StringMap) Without(keys ...interface{}) Mapper

Without removes the keys, returns a shallow copy

type Ticker added in v1.1.1

type Ticker struct {
	// contains filtered or unexported fields
}

Ticker is a ticker wrapper with some extra functionality

func NewTicker added in v1.1.1

func NewTicker(period time.Duration) *Ticker

NewTicker create a new resetable ticker

func (*Ticker) C added in v1.1.1

func (t *Ticker) C() <-chan time.Time

C returns the ticker channel

func (*Ticker) Reset added in v1.1.1

func (t *Ticker) Reset()

Reset resets the tickers

type UUIDArray

type UUIDArray []strfmt.UUID

UUIDArray is a proper string array type

func (*UUIDArray) Scan

func (a *UUIDArray) Scan(src interface{}) error

Scan implements the sql.Scanner interface

func (UUIDArray) Strings

func (a UUIDArray) Strings() []string

Strings returns a string slice from the uuid array

func (*UUIDArray) Validate

func (*UUIDArray) Validate(formats strfmt.Registry) error

Validate handles the strfmt validation for the StringArray object

func (UUIDArray) Value

func (a UUIDArray) Value() (driver.Value, error)

Value implements the driver.Valuer interface.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value defines a value wrapper

func NewValue

func NewValue(v interface{}) Value

NewValue returns a new value with cast helpers

func (Value) Bool

func (v Value) Bool() bool

Bool casts the value to a bool

func (Value) Float64

func (v Value) Float64() float64

Float64 casts the value to a float64

func (Value) Int64

func (v Value) Int64() int64

Int64 casts the value to an int64

func (Value) Interface added in v1.1.0

func (v Value) Interface() interface{}

Interface returns the underlying interface for the value

func (Value) IsNil added in v1.1.3

func (v Value) IsNil() bool

IsNil returns if the enclosed value is nil

func (Value) Slice added in v1.3.0

func (v Value) Slice() []interface{}

Slice returns the value cast as []interface{}

func (Value) String

func (v Value) String() string

String casts the value to a string

func (Value) StringMap added in v1.3.0

func (v Value) StringMap() StringMap

StringMap converts the object to a StringMap

func (Value) StringPtr

func (v Value) StringPtr() *string

StringPtr casts the value to a string pointer

func (Value) StringSlice

func (v Value) StringSlice() []string

StringSlice casts the value to a string slice

Directories

Path Synopsis
geo
encoding/postgis
Package postgis implements Well Known Binary encoding and decoding.
Package postgis implements Well Known Binary encoding and decoding.
Package ptr provides some helpers for converting types to pointers
Package ptr provides some helpers for converting types to pointers

Jump to

Keyboard shortcuts

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