webtype

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 6 Imported by: 0

README

webtype for Golang

webtypeはweb開発において、よく使用する型を提供します。 DBやJSONによる入出力を定義した型です。

NBool, NFloat64, NInt64, NStringはsql.NullBool, sql.NullFloat64, sql.NullInt64, sql.NullString相当と同じメンバー構成である、Null許容型です。MarshalJSONとUnmarshalJSONを実装しており、JSONの入出力にも使えます。 NTimeは上記のtime.Timeバージョンです。

Identはint64の別名ですが、JSONに変換する際、文字列に変換する型です。 JavaScriptの整数は53bitまでの制約により、Goによるint64がJavaScriptのエンジンにおいて、正確に値を読み取れないことがあります。 これを解決するために、DBやGoでは64bit整数として扱い、JSONに変換するときは文字列にして渡すことがあります。 主に計算に利用しないIDなどで利用することを想定した型です。 NIdentはIdentのNull許容型です。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NullBool = NBool{
	Valid: false,
}

NullBool is Null value for NBool.

View Source
var NullFloat64 = NFloat64{
	Valid: false,
}

NullFloat64 is Null value for NFloat64.

View Source
var NullID = NIdent{
	Valid: false,
}

NullID is Null value for NIdent.

View Source
var NullInt64 = NInt64{
	Valid: false,
}

NullInt64 is Null value for NInt64.

View Source
var NullString = NString{
	Valid: false,
}

NullString is Null value for NString.

View Source
var NullTime = NTime{
	Valid: false,
}

NullTime is Null value for NTime.

Functions

This section is empty.

Types

type Ident

type Ident int64

Ident represents a int64 as identifier.

func MakeID

func MakeID(id int64) Ident

MakeID make Ident from int64.

func (Ident) MarshalJSON

func (id Ident) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*Ident) UnmarshalJSON

func (id *Ident) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

type NBool

type NBool struct {
	Bool  bool
	Valid bool
}

NBool represents a bool that may be null.

func MakeNBool

func MakeNBool(b bool) NBool

MakeNBool make NBool from bool.

func (NBool) MarshalJSON

func (nb NBool) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*NBool) Scan

func (nb *NBool) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NBool) UnmarshalJSON

func (nb *NBool) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

func (NBool) Value

func (nb NBool) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NFloat64

type NFloat64 struct {
	Float64 float64
	Valid   bool
}

NFloat64 represents a float64 that may be null.

func MakeNFloat64

func MakeNFloat64(f float64) NFloat64

MakeNFloat64 make NFloat64 from float64.

func (NFloat64) MarshalJSON

func (nf NFloat64) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*NFloat64) Scan

func (nf *NFloat64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NFloat64) UnmarshalJSON

func (nf *NFloat64) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

func (NFloat64) Value

func (nf NFloat64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NIdent

type NIdent struct {
	Ident Ident
	Valid bool
}

NIdent represents a Ident that may be null.

func MakeNID

func MakeNID(id int64) NIdent

MakeNID make NIdent from int64.

func (NIdent) MarshalJSON

func (nid NIdent) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*NIdent) Scan

func (nid *NIdent) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NIdent) UnmarshalJSON

func (nid *NIdent) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

func (NIdent) Value

func (nid NIdent) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NInt64

type NInt64 struct {
	Int64 int64
	Valid bool
}

NInt64 represents a int64 that may be null.

func MakeNInt64

func MakeNInt64(i int64) NInt64

MakeNInt64 make NInt64 from int64.

func (NInt64) MarshalJSON

func (ni NInt64) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*NInt64) Scan

func (ni *NInt64) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NInt64) UnmarshalJSON

func (ni *NInt64) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

func (NInt64) Value

func (ni NInt64) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NString

type NString struct {
	String string
	Valid  bool
}

NString represents a string that may be null.

func MakeNString

func MakeNString(s string) NString

MakeNString make NString from string.

func (NString) MarshalJSON

func (ns NString) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*NString) Scan

func (ns *NString) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NString) UnmarshalJSON

func (ns *NString) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

func (NString) Value

func (ns NString) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type NTime

type NTime struct {
	Time  time.Time
	Valid bool
}

NTime represents a time that may be null.

func MakeNTime

func MakeNTime(t time.Time) NTime

MakeNTime make NTime from time.Time.

func (NTime) MarshalJSON

func (nt NTime) MarshalJSON() ([]byte, error)

MarshalJSON encode json value.

func (*NTime) Scan

func (nt *NTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (*NTime) UnmarshalJSON

func (nt *NTime) UnmarshalJSON(data []byte) error

UnmarshalJSON decode json value.

func (NTime) Value

func (nt NTime) Value() (driver.Value, error)

Value implements the driver Valuer interface.

Jump to

Keyboard shortcuts

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