types

package module
v0.0.0-...-38e990d Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2019 License: Apache-2.0 Imports: 15 Imported by: 8

README

Types Package

Build Status GoDoc GoWalker License

warp basic type for golang and offer some extra type transform functions

Documentation

Index

Constants

View Source
const (
	// B byte 8bit
	B = 1
	// KB Kibibyte 2^10B
	KB = 1024 * B
	// MB Mebibyte 2^20B
	MB = 1024 * KB
	// GB Gigabyte 2^30B
	GB = 1024 * MB
	// TB Terabyte 2^40B
	TB = 1024 * GB
	// PB Petabyte 2^50B
	PB = 1024 * TB
	// EB Exabyte  2^60B
	EB = 1024 * PB
)
View Source
const (
	Second = int64(time.Second)
	Minute = int64(time.Minute)
	Hour   = int64(time.Hour)
	Day    = Hour * 24
	Month  = Day * 30
	Year   = Month * 12
)

time duration int64

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b Bytes) string

BytesToString byte => string 直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变。 效率是string(Bytes{})的百倍以上,且转换量越大效率优势越明显。

func DurationHuman

func DurationHuman(d time.Duration) string

DurationHuman duration human

func Format

func Format(in, out interface{}) error

Format implement Formatter interface map[string]interface{} => struct{} eg: Format(map[string]interface{...}, &Struct{})

func FormatINI

func FormatINI(in, out interface{}) error

FormatINI format ini

func FormatJSON

func FormatJSON(in, out interface{}) error

FormatJSON format json

func FormatXML

func FormatXML(in, out interface{}) error

FormatXML format xml

func FormatYAML

func FormatYAML(in, out interface{}) error

FormatYAML format yaml

func ParseConfigFile

func ParseConfigFile(v interface{}, file string) error

ParseConfigFile parse config file

func ParseConfigFiles

func ParseConfigFiles(v interface{}, files ...string) error

ParseConfigFiles parse config files

func Round

func Round(f float64, n int) float64

Round float64四舍五入,并取前几位

func StringToBool

func StringToBool(s string) (bool, error)

StringToBool string => bool, if fail return false

func StringToFloat64

func StringToFloat64(s string) (float64, error)

StringToFloat64 string => float64, if fail return 0

func StringToInt

func StringToInt(s string) (int, error)

StringToInt string => int, if fail return 0

func StringToInt64

func StringToInt64(s string) (int64, error)

StringToInt64 string => int64, if fail return 0

func TimeFormat

func TimeFormat(str string) string

TimeFormat time string

func ToBool

func ToBool(v interface{}) (bool, error)

ToBool interface => bool

func ToFloat64

func ToFloat64(v interface{}) (float64, error)

ToFloat64 interface => float64

func ToInt

func ToInt(v interface{}) (int, error)

ToInt interface => int

func ToInt64

func ToInt64(v interface{}) (int64, error)

ToInt64 interface => int64

func ToJSON

func ToJSON(in interface{}) ([]byte, error)

ToJSON to json

func ToString

func ToString(v interface{}) (string, error)

ToString interface => string

func ToXML

func ToXML(in interface{}) ([]byte, error)

ToXML to json

func ToYAML

func ToYAML(in interface{}) ([]byte, error)

ToYAML 将结构体in转换成yml格式的字符串, 适用于配置文件落地

Types

type Bytes

type Bytes = []byte

Bytes equal []byte

func Clean

func Clean(b Bytes) Bytes

Clean 清理#注释

func FileToBytes

func FileToBytes(s string) (Bytes, error)

FileToBytes file => []byte

func MapToBytes

func MapToBytes(m Map) (Bytes, error)

MapToBytes map[string]interface{} => []byte

func StringToBytes

func StringToBytes(s string) Bytes

StringToBytes string => Bytes 直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变。 效率是string(Bytes{})的百倍以上,且转换量越大效率优势越明显。 转换之后若没做其他操作直接改变里面的字符,则程序会崩溃。 如 b:=String2bytes("xxx"); b[1]='d'; 程序将panic。

func ToBytes

func ToBytes(v interface{}) (Bytes, error)

ToBytes interface => []byte

type CallFuncType

type CallFuncType = func(interface{}, ...interface{}) (List, error)

CallFuncType call func type

type Configer

type Configer interface {
	Parse(v interface{}) error
}

Configer config interface.

type Float64

type Float64 float64

Float64 float64

func (Float64) Float64

func (f Float64) Float64() float64

Float64 to float64

func (Float64) Int

func (f Float64) Int() int

Int to int

func (Float64) Int64

func (f Float64) Int64() int64

Int64 to int64

func (Float64) String

func (f Float64) String() string

String to string

type Formatter

type Formatter interface {
	Format(in, out interface{}) error
}

Formatter interface

type HashMap

type HashMap Map

HashMap map

func (HashMap) Parse

func (m HashMap) Parse(v interface{}) error

Parse Implement Configer interface.

type Int

type Int int

Int int field

func (Int) Bool

func (i Int) Bool() bool

Bool convert to bool

func (Int) Float64

func (i Int) Float64() float64

Float64 to float64

func (Int) Int

func (i Int) Int() int

Int to int

func (Int) Int64

func (i Int) Int64() int64

Int64 to int64

func (Int) String

func (i Int) String() string

String to string

type Int64

type Int64 int64

Int64 int64 field

func (Int64) Bool

func (i Int64) Bool() bool

Bool convert to bool

func (Int64) Float64

func (i Int64) Float64() float64

Float64 to float64

func (Int64) Int

func (i Int64) Int() int

Int to int

func (Int64) Int64

func (i Int64) Int64() int64

Int64 to int64

func (Int64) String

func (i Int64) String() string

String to string

type IntList

type IntList []int

IntList intList

func (IntList) Append

func (i IntList) Append(v ...int)

Append append to the end L.append(object) -- append object to end

func (IntList) Contains

func (i IntList) Contains(v int) bool

Contains contains

func (IntList) Count

func (i IntList) Count(v int) int

Count L.count(value) -> integer -- return number of occurrences of value

func (IntList) Index

func (i IntList) Index(v int) int

Index index

func (IntList) Insert

func (i IntList) Insert(idx, v int)

Insert insert

func (IntList) Len

func (i IntList) Len() int

Len len

func (IntList) List

func (i IntList) List() []int

List to []int

func (IntList) Pop

func (i IntList) Pop(id ...int) int

Pop 指定下标,删除指定的元素,如果删除一个不存在的元素会报错,默认Pop()删除最后一个元素

type Interface

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

Interface interface field

func (*Interface) Float64

func (v *Interface) Float64() float64

Float64 to float64

func (*Interface) Int

func (v *Interface) Int() int

Int to int

func (*Interface) List

func (v *Interface) List() []interface{}

List to list

func (*Interface) Map

func (v *Interface) Map() map[string]interface{}

Map to map

func (*Interface) String

func (v *Interface) String() string

String to string

type List

type List []interface{}

List list

func CallFuncName

func CallFuncName(fun interface{}, args ...interface{}) (List, error)

CallFuncName call func name

func CallMethodName

func CallMethodName(class interface{}, fun string, args ...interface{}) (List, error)

CallMethodName Call method by name

Example:
  type Test struct {
      i   int
      j   int
  }
  func (t *Test) Add(i int) (int,error) {
      return t.i+t.j+i, nil
  }
  var T = &Test{1,2}
  CallMethodName(T,"Add",1) // [4 <nil>] <nil>

func FuncWithTimeout

func FuncWithTimeout(timeout int, fun interface{}, args ...interface{}) (List, error)

FuncWithTimeout func timeout

func ToList

func ToList(v interface{}) (l List, err error)

ToList interface => []interface

func (List) Append

func (i List) Append(v ...interface{})

Append L.append(object) -- append object to end

func (List) Contains

func (i List) Contains(v interface{}) bool

Contains contains

func (List) Count

func (i List) Count(v interface{}) int

Count L.count(value) -> integer -- return number of occurrences of value

func (List) Index

func (i List) Index(v interface{}) int

Index index

func (List) Insert

func (i List) Insert(id int, v interface{})

Insert insert

func (List) Len

func (i List) Len() int

Len len

func (List) List

func (i List) List() []interface{}

List to []interface{}

func (List) Pop

func (i List) Pop(id ...int) interface{}

Pop 指定下标,删除指定的元素,如果删除一个不存在的元素会报错,默认Pop()删除最后一个元素

type Map

type Map = map[string]interface{}

Map map

func BytesToMap

func BytesToMap(b Bytes) (m Map, err error)

BytesToMap []byte => map[string]interface{}

func FileToMap

func FileToMap(s string) (Map, error)

FileToMap file => map[string]interface{}

func StringToMap

func StringToMap(s string) (m Map, err error)

StringToMap string => map[string]interface{}

func ToMap

func ToMap(v interface{}) (m Map, err error)

ToMap interface => map[string]interface{}

type Result

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

Result result

type SortMap

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

SortMap sort Map

func NewSortMap

func NewSortMap() *SortMap

NewSortMap sortmap

func (*SortMap) Index

func (sm *SortMap) Index(index int) (string, interface{})

Index index

func (*SortMap) String

func (sm *SortMap) String() string

type String

type String string

String string

func (String) Float64

func (s String) Float64() float64

Float64 to float64

func (String) Int

func (s String) Int() int

Int to int

func (String) Int64

func (s String) Int64() int64

Int64 to int64

func (String) String

func (s String) String() string

type StringList

type StringList []string

StringList StringList

func (StringList) Append

func (s StringList) Append(v ...string)

Append append to the end L.append(object) -- append object to end

func (StringList) Contains

func (s StringList) Contains(v string) bool

Contains contains

func (StringList) Count

func (s StringList) Count(v string) int

Count L.count(value) -> integer -- return number of occurrences of value

func (StringList) Index

func (s StringList) Index(v string) int

Index index

func (StringList) Insert

func (s StringList) Insert(idx int, v string)

Insert insert

func (StringList) Len

func (s StringList) Len() int

Len len

func (StringList) List

func (s StringList) List() []string

List to []string

func (StringList) Pop

func (s StringList) Pop(idx ...int) string

Pop 指定下标,删除指定的元素,如果删除一个不存在的元素会报错,默认Pop()删除最后一个元素

type Time

type Time time.Time

Time time

func Now

func Now() Time

Now now

func (Time) Float64

func (t Time) Float64() float64

Float64 flot64

func (Time) Int

func (t Time) Int() int

Int int

func (Time) Int64

func (t Time) Int64() int64

Int64 int64

func (Time) MarshalJSON

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON xxx

func (Time) String

func (t Time) String() string

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON xxx

type Typer

type Typer interface {
	Int() int
	Int64() int64
	Float64() float64
	String() string
}

Typer type interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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