Documentation ¶
Overview ¶
Package types provides common types.
Index ¶
- Variables
- func BytesSize(n uint64) string
- func ConflictKeys[T any](a, b Map[T]) (conflicts []string)
- func DiffKeys[T any](a, b Map[T]) (added, removed []string)
- func Equal(a, b any) bool
- func Less(a, b any) bool
- func MarshalFile(name string, in any) error
- func More(a, b any) bool
- func NotEqual(a, b any) bool
- func UnmarshalFile(name string, out any) error
- type ContentType
- func (ct ContentType) Bytes() []byte
- func (ct ContentType) Marshal(in any) (io.Reader, error)
- func (ct ContentType) MarshalJSON() ([]byte, error)
- func (ct ContentType) String() string
- func (ct ContentType) Unmarshal(r io.Reader, out any) error
- func (ct *ContentType) UnmarshalJSON(data []byte) error
- func (ct ContentType) Validate() bool
- type DateTime
- type Map
- func (m Map[T]) AsString(key string) string
- func (m Map[T]) Clear()
- func (m Map[T]) Clone() Map[T]
- func (m Map[T]) Delete(key string)
- func (m Map[T]) Get(key string) T
- func (m Map[T]) Has(key string) bool
- func (m Map[T]) IsEmpty() bool
- func (m Map[T]) Keys() (keys []string)
- func (m Map[T]) Len() int
- func (m Map[T]) Merge(maps ...Map[T]) Map[T]
- func (m Map[T]) Range(fn func(key string, value T) bool)
- func (m Map[T]) Set(key string, value T)
- func (m Map[T]) String(sep, join string) string
- func (m Map[T]) Value() (driver.Value, error)
- func (m Map[T]) Values() (values []T)
- type Option
- func NewBooleanOption(name string, description string, required bool, def bool) *Option
- func NewDateTimeOption(name string, description string, required bool, def string, min string, ...) *Option
- func NewFloatOption(name string, description string, required bool, def float64, min float64, ...) *Option
- func NewIDOption(name string, description string, required bool, def string) *Option
- func NewIntegerOption(name string, description string, required bool, def int, min int, max int) *Option
- func NewOption(name string, description string, required bool, t Type, def any, min any, ...) *Option
- func NewStringOption(name string, description string, required bool, def string, choices []string) *Option
- type Options
- type Type
- type URI
Constants ¶
This section is empty.
Variables ¶
var ( ContentTypeNames = map[ContentType]string{ ContentTypeJson: "application/json", ContentTypeMsgPack: "application/msgpack", ContentTypeYaml: "application/yaml", ContentTypeHtml: "text/html", ContentTypeFormUrlEncoded: "application/x-www-form-urlencoded", ContentTypePlain: "text/plain", } )
var ( TypeNames = map[Type]string{ TypeBoolean: "Boolean", TypeDateTime: "DateTime", TypeFloat: "Float", TypeID: "ID", TypeInteger: "Integer", TypeString: "String", } )
Functions ¶
func ConflictKeys ¶
ConflictKeys returns a map of conflicting keys between the two maps.
func MarshalFile ¶ added in v0.0.12
MarshalFile marshals a file.
func UnmarshalFile ¶ added in v0.0.12
UnmarshalFile unmarshals a file.
Types ¶
type ContentType ¶
type ContentType uint8
ContentType represents the content type.
const ( ContentTypeInvalid ContentType = iota // ContentTypeJson ContentTypeMsgPack ContentTypeYaml ContentTypeHtml ContentTypeFormUrlEncoded ContentTypePlain )
func ParseContentType ¶
func ParseContentType(value string) ContentType
ParseContentType parses ContentType from string.
func (ContentType) Bytes ¶
func (ct ContentType) Bytes() []byte
Bytes returns the ContentType as a []byte.
func (ContentType) MarshalJSON ¶
MarshalJSON outputs the ContentType as a json.
func (ContentType) String ¶
func (ct ContentType) String() string
String outputs the ContentType as a string.
func (*ContentType) UnmarshalJSON ¶
UnmarshalJSON parses ContentType from json.
type DateTime ¶
DateTime represents the date and time using RFC3339 format.
func DateTimeNow ¶ added in v0.0.15
func DateTimeNow() DateTime
DateTimeNow returns the current date and time.
func ParseDateTime ¶ added in v0.0.15
ParseDateTime parses DateTime from string.
func (DateTime) MarshalJSON ¶
MarshalJSON outputs the DateTime as a json.
func (*DateTime) UnmarshalJSON ¶
UnmarshalJSON parses DateTime from json.
type Map ¶
Map defines a map of key:value. It implements Map.
type Option ¶ added in v0.0.10
type Option struct { Name string `json:"name"` Description string `json:"description"` Required bool `json:"required"` Type Type `json:"type"` Default any `json:"default"` Min any `json:"min,omitempty"` Max any `json:"max,omitempty"` Choices []string `json:"choices,omitempty"` }
Option represents the ui option.
func NewBooleanOption ¶ added in v0.0.10
NewBooleanOption creates a new Option instance with type boolean.
func NewDateTimeOption ¶ added in v0.0.15
func NewDateTimeOption(name string, description string, required bool, def string, min string, max string) *Option
NewDateTimeOption creates a new Option instance with type datetime.
func NewFloatOption ¶ added in v0.0.10
func NewFloatOption(name string, description string, required bool, def float64, min float64, max float64) *Option
NewFloatOption creates a new Option instance with type float.
func NewIDOption ¶ added in v0.0.15
NewIDOption creates a new Option instance with type id.
func NewIntegerOption ¶ added in v0.0.10
func NewIntegerOption(name string, description string, required bool, def int, min int, max int) *Option
NewIntegerOption creates a new Option instance with type integer.
type Options ¶ added in v0.0.10
type Options []*Option
Options represents the options.
func NewOptions ¶ added in v0.0.10
func NewOptions(options ...*Option) Options
NewOptions creates a new Options instance.
func (Options) DefaultValue ¶ added in v0.0.18
DefaultValue returns the default value of the option with the given name.
func (Options) Len ¶ added in v0.0.11
func (o Options) Len() int
Len returns the length of the options.
func (Options) SetDefaultValue ¶ added in v0.0.18
SetDefaultValue sets the default value of the option with the given name.
type Type ¶
type Type uint8
Type represents the data type.
const ( TypeInvalid Type = iota // TypeBoolean TypeDateTime TypeFloat TypeID TypeInteger TypeString )
func (Type) MarshalJSON ¶
MarshalJSON outputs the Type as a json.
func (*Type) UnmarshalJSON ¶
UnmarshalJSON parses Type from json.
type URI ¶
URI represents the URI.
func (URI) MarshalJSON ¶
MarshalJSON outputs the URI as a json.
func (*URI) UnmarshalJSON ¶
UnmarshalJSON parses URI from json.