describe

package module
v0.0.0-...-16de10f Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2018 License: MIT Imports: 7 Imported by: 17

README

Describe-Go

Describe your scripts at golang

Intro

  • reusable object
  • set first, use later

go get github.com/NeoJRotary/describe-go

Current Version : 0.2.0

Some issuses : ISSUES

Progess

  • ready : ready for production usage
  • beta : ready for test, no breaking changes
  • alpha : incomplete, may have breaking changes
  • util_only : currently only have few util functions
  • planned : plan to do, designing
Type Progess Path GoDoc
String beta describe-go Doc
StringSlice beta describe-go Doc
Error beta describe-go Doc
HTTP / Server alpha describe-go/dhttp Doc
Net util_only describe-go Doc
File util_only describe-go Doc
JSON util_only describe-go Doc
Time util_only describe-go Doc
Byte planned
ByteSlice planned

Examples

Handle String Output : Example

Documentation

Index

Constants

View Source
const (
	// ErrOutOfRange out of range
	ErrOutOfRange = "out of range"
	// ErrSliceIsEmpty slice is empty
	ErrSliceIsEmpty = "slice is empty"
	// ErrRangeIndexInvalid range index error : i > j or index < 0
	ErrRangeIndexInvalid = "range index error : i > j or index < 0"
	// ErrInvalidIndex invalid index < 0
	ErrInvalidIndex = "invalid index < 0"
)

Variables

This section is empty.

Functions

func CheckErr

func CheckErr(e error)

CheckErr panic if it is error

func FileExist

func FileExist(path string) bool

FileExist is file exist ?

func Found

func Found(elm interface{}) bool

Found check Slice.Find() return valid element or not

func GetENV

func GetENV(name string, defaultVal string) string

GetENV get env or use default

func GetTimeFormat

func GetTimeFormat(layout string) string

GetTimeFormat convert YYYYMMDD format to golang's time format layout

func IsErr

func IsErr(e error) bool

IsErr is error or not

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

IsPrivateIP if addr string is in RFC1918 private network or not

func IsPublicIP

func IsPublicIP(ip net.IP) bool

IsPublicIP if addr string is in public network or not

func JSONBytes

func JSONBytes(v interface{}) []byte

JSONBytes get json bytes from interface{}, ignore marshal error as empty []byte

func JSONString

func JSONString(v interface{}) string

JSONString get json string from interface{}, ignore marshal error as empty string

func NewErr

func NewErr(msg ...interface{}) error

NewErr return new error

func NotFound

func NotFound(elm interface{}) bool

NotFound check Slice.Find() return valid element or not

func PanicErr

func PanicErr(s string)

PanicErr panic error by string

func RecoverErr

func RecoverErr(f func(error))

RecoverErr run function when recover an error, it will panic again if it is not error

func ValidIP

func ValidIP(ip string) bool

ValidIP check string is valid IP or not by net.ParseIP

Types

type TypeError

type TypeError struct {
	Obj error
}

TypeError error function collections struct

func Error

func Error(e error) *TypeError

Error get *TypeError

func ErrorMsg

func ErrorMsg(s string) *TypeError

ErrorMsg get *TypeError By message string

func (*TypeError) AddPrefix

func (e *TypeError) AddPrefix(prefix string) *TypeError

AddPrefix add prefix msg to object error

func (*TypeError) AddSuffix

func (e *TypeError) AddSuffix(suffix string) *TypeError

AddSuffix add suffix msg to object error

func (*TypeError) Check

func (e *TypeError) Check()

Check if object is error, panic it

func (*TypeError) Get

func (e *TypeError) Get() error

Get return object error

func (*TypeError) Is

func (e *TypeError) Is() bool

Is whether object is an error

func (*TypeError) IsNot

func (e *TypeError) IsNot() bool

IsNot whether object is not an error

func (*TypeError) Msg

func (e *TypeError) Msg() string

Msg return object error message in string

func (*TypeError) ToTypeString

func (e *TypeError) ToTypeString() *TypeString

ToTypeString return object error message in TypeString

type TypeString

type TypeString struct {
	Obj        string
	SliceIndex int
}

TypeString string function collections struct

func String

func String(obj ...string) *TypeString

String get *TypeString

func (*TypeString) Copy

func (s *TypeString) Copy() *TypeString

Copy get copy of type

func (*TypeString) Empty

func (s *TypeString) Empty() bool

Empty is empty string

func (*TypeString) Get

func (s *TypeString) Get() string

Get return object string

func (*TypeString) Has

func (s *TypeString) Has(elm string, more ...string) bool

Has obejct string contain all elements

func (*TypeString) HasOne

func (s *TypeString) HasOne(elm string, more ...string) bool

HasOne obejct string contain one of elements

func (*TypeString) HasPrefix

func (s *TypeString) HasPrefix(prefix string) bool

HasPrefix wrapper of strings.HasPrefix()

func (*TypeString) HasSuffix

func (s *TypeString) HasSuffix(suffix string) bool

HasSuffix wrapper of strings.HasSuffix()

func (*TypeString) Index

func (s *TypeString) Index(substr string) int

Index find fisrt substr position in object. Retrun -1 if not found.

func (*TypeString) LastIndex

func (s *TypeString) LastIndex(substr string) int

LastIndex find last substr position in object. Retrun -1 if not found.

func (*TypeString) Len

func (s *TypeString) Len() int

Len length of string

func (*TypeString) NotHave

func (s *TypeString) NotHave(elm string, more ...string) bool

NotHave object string doesn't contain all elements

func (*TypeString) Range

func (s *TypeString) Range(i int, j int) *TypeString

Range get part of object from index i to j (exclude j). Panic when invalid index or out of range.

func (*TypeString) RangeBetween

func (s *TypeString) RangeBetween(a, b string) *TypeString

RangeBetween get part of object by given first and last element. Panic if a or b not found.

func (*TypeString) RangeCut

func (s *TypeString) RangeCut(n, m int) *TypeString

RangeCut get part of obejct by cut (n) chars from start and (m) chars from end

func (*TypeString) RangeFirst

func (s *TypeString) RangeFirst(n int) *TypeString

RangeFirst get first n chars

func (*TypeString) RangeFrom

func (s *TypeString) RangeFrom(sub string) *TypeString

RangeFrom get part of string from index of sub (exclude sub)

func (*TypeString) RangeLast

func (s *TypeString) RangeLast(n int) *TypeString

RangeLast get last n chars

func (*TypeString) RangeUntil

func (s *TypeString) RangeUntil(sub string) *TypeString

RangeUntil get part of string until index of sub (exclude sub)

func (*TypeString) Replace

func (s *TypeString) Replace(old string, new string, n int) *TypeString

Replace wrapper of strings.Replace()

func (*TypeString) ReplaceAll

func (s *TypeString) ReplaceAll(old string, new string) *TypeString

ReplaceAll wrapper of strings.Replace(), set n = -1

func (*TypeString) SetInto

func (s *TypeString) SetInto(ss *TypeStringSlice) *TypeStringSlice

SetInto set element into target slice by index. Panic if element doesn't have index.

func (*TypeString) SetSliceIndex

func (s *TypeString) SetSliceIndex(i int) *TypeString

SetSliceIndex set index of slice on TypeString. Panic when invalid index

func (*TypeString) Split

func (s *TypeString) Split(sep string) *TypeStringSlice

Split wrapper of strings.Split()

func (*TypeString) ToFloat32

func (s *TypeString) ToFloat32() float32

ToFloat32 convert string to float32. Panic if strconv throw error.

func (*TypeString) ToFloat64

func (s *TypeString) ToFloat64() float64

ToFloat64 convert string to float64. Panic if strconv throw error.

func (*TypeString) ToInt

func (s *TypeString) ToInt() int

ToInt convert string to int. Panic if strconv throw error.

func (*TypeString) ToInt16

func (s *TypeString) ToInt16() int16

ToInt16 convert string to int16. Panic if strconv throw error.

func (*TypeString) ToInt32

func (s *TypeString) ToInt32() int32

ToInt32 convert string to int32. Panic if strconv throw error.

func (*TypeString) ToInt64

func (s *TypeString) ToInt64() int64

ToInt64 convert string to int64. Panic if strconv throw error.

func (*TypeString) ToInt8

func (s *TypeString) ToInt8() int8

ToInt8 convert string to int8. Panic if strconv throw error.

func (*TypeString) ToUint

func (s *TypeString) ToUint() uint

ToUint convert string to uint. Panic if strconv throw error.

func (*TypeString) ToUint16

func (s *TypeString) ToUint16() uint16

ToUint16 convert string to uint16. Panic if strconv throw error.

func (*TypeString) ToUint32

func (s *TypeString) ToUint32() uint32

ToUint32 convert string to uint32. Panic if strconv throw error.

func (*TypeString) ToUint64

func (s *TypeString) ToUint64() uint64

ToUint64 convert string to uint64. Panic if strconv throw error.

func (*TypeString) ToUint8

func (s *TypeString) ToUint8() uint8

ToUint8 convert string to uint8. Panic if strconv throw error.

func (*TypeString) Trim

func (s *TypeString) Trim(cutset string) *TypeString

Trim wrapper of strings.Trim()

func (*TypeString) TrimLeft

func (s *TypeString) TrimLeft(cutset string) *TypeString

TrimLeft wrapper of strings.TrimLeft()

func (*TypeString) TrimPrefix

func (s *TypeString) TrimPrefix(prefix string) *TypeString

TrimPrefix wrapper of strings.TrimPrefix()

func (*TypeString) TrimRight

func (s *TypeString) TrimRight(cutset string) *TypeString

TrimRight wrapper of strings.TrimRight()

func (*TypeString) TrimSpace

func (s *TypeString) TrimSpace() *TypeString

TrimSpace wrapper of strings.TrimSpace()

func (*TypeString) TrimSuffix

func (s *TypeString) TrimSuffix(suffix string) *TypeString

TrimSuffix wrapper of strings.TrimSuffix()

func (*TypeString) Update

func (s *TypeString) Update(str string) *TypeString

Update update object

func (*TypeString) WrapBy

func (s *TypeString) WrapBy(wrapper string) *TypeString

WrapBy wrap string by wrapper

type TypeStringSlice

type TypeStringSlice struct {
	Obj []string
}

TypeStringSlice []string function collections struct

func StringSlice

func StringSlice(obj ...[]string) *TypeStringSlice

StringSlice get *TypeStringSlice

func (*TypeStringSlice) Copy

func (ss *TypeStringSlice) Copy() *TypeStringSlice

Copy get copy of type

func (*TypeStringSlice) Delete

func (ss *TypeStringSlice) Delete(i int) *TypeStringSlice

Delete delete elm at i

func (*TypeStringSlice) DeleteSame

func (ss *TypeStringSlice) DeleteSame(s ...string) *TypeStringSlice

DeleteSame delete elm same with s

func (*TypeStringSlice) ElmAt

func (ss *TypeStringSlice) ElmAt(i int) *TypeString

ElmAt return element of slice at position in describe.Type. Panic if slice is empty or out of range.

func (*TypeStringSlice) ElmTrim

func (ss *TypeStringSlice) ElmTrim(cutset string) *TypeStringSlice

ElmTrim trim all elements in slice

func (*TypeStringSlice) ElmTrimLeft

func (ss *TypeStringSlice) ElmTrimLeft(cutset string) *TypeStringSlice

ElmTrimLeft trim all elements in slice

func (*TypeStringSlice) ElmTrimPrefix

func (ss *TypeStringSlice) ElmTrimPrefix(prefix string) *TypeStringSlice

ElmTrimPrefix trim all elements in slice

func (*TypeStringSlice) ElmTrimRight

func (ss *TypeStringSlice) ElmTrimRight(cutset string) *TypeStringSlice

ElmTrimRight trim all elements in slice

func (*TypeStringSlice) ElmTrimSpace

func (ss *TypeStringSlice) ElmTrimSpace() *TypeStringSlice

ElmTrimSpace trim space all elements in slice

func (*TypeStringSlice) ElmTrimSuffix

func (ss *TypeStringSlice) ElmTrimSuffix(suffix string) *TypeStringSlice

ElmTrimSuffix trim all elements in slice

func (*TypeStringSlice) ElmWrapBy

func (ss *TypeStringSlice) ElmWrapBy(wrapper string) *TypeStringSlice

ElmWrapBy wrap all elements in slice

func (*TypeStringSlice) Empty

func (ss *TypeStringSlice) Empty() bool

Empty is empty slice or not

func (*TypeStringSlice) FilterBy

func (ss *TypeStringSlice) FilterBy(filter func(*TypeString) bool) *TypeStringSlice

FilterBy get new slice of string which pass the func

func (*TypeStringSlice) FilterByPrefix

func (ss *TypeStringSlice) FilterByPrefix(prefix string) *TypeStringSlice

FilterByPrefix get new slice of string which has prefix

func (*TypeStringSlice) FilterBySuffix

func (ss *TypeStringSlice) FilterBySuffix(suffix string) *TypeStringSlice

FilterBySuffix get new slice of string which has prefix

func (*TypeStringSlice) Find

func (ss *TypeStringSlice) Find(f func(*TypeString) bool) *TypeString

Find find first element in describe.Type when func passed. Return nil if not found.

func (*TypeStringSlice) FindHasPrefix

func (ss *TypeStringSlice) FindHasPrefix(prefix string) *TypeString

FindHasPrefix find first string has prefix. Return nil if not found.

func (*TypeStringSlice) FindHasSuffix

func (ss *TypeStringSlice) FindHasSuffix(suffix string) *TypeString

FindHasSuffix find first string has prefix. Return nil if not found.

func (*TypeStringSlice) First

func (ss *TypeStringSlice) First() *TypeString

First return first element of slice in describe.Type. Panic if slice is empty.

func (*TypeStringSlice) From

func (ss *TypeStringSlice) From(i int) *TypeStringSlice

From return slice[i:], if out of range return empty slice

func (*TypeStringSlice) Get

func (ss *TypeStringSlice) Get() []string

Get return object slice

func (*TypeStringSlice) Has

func (ss *TypeStringSlice) Has(elms ...string) bool

Has whether slice has all elements

func (*TypeStringSlice) Include

func (ss *TypeStringSlice) Include(elms ...string) bool

Include return if slice has one of elements

func (*TypeStringSlice) IndexOf

func (ss *TypeStringSlice) IndexOf(s string) int

IndexOf get index of s, return -1 if not found

func (*TypeStringSlice) Join

func (ss *TypeStringSlice) Join(sep string) *TypeString

Join join slice. retrun TypeString

func (*TypeStringSlice) Last

func (ss *TypeStringSlice) Last() *TypeString

Last return last element of slice in describe.Type. Panic if slice is empty.

func (*TypeStringSlice) Len

func (ss *TypeStringSlice) Len() int

Len return len(slice)

func (*TypeStringSlice) Map

func (ss *TypeStringSlice) Map(mapper func(*TypeString) *TypeString) *TypeStringSlice

Map update elements by func, return a new slice

func (*TypeStringSlice) NotHave

func (ss *TypeStringSlice) NotHave(elms ...string) bool

NotHave whether slice doesn't have any of elements

func (*TypeStringSlice) NotInclude

func (ss *TypeStringSlice) NotInclude(elms ...string) bool

NotInclude return if slice does not include any of elements

func (*TypeStringSlice) Push

func (ss *TypeStringSlice) Push(elm string, more ...string) *TypeStringSlice

Push push new elements into slice. Return new slice

func (*TypeStringSlice) Range

func (ss *TypeStringSlice) Range(i int, j int) *TypeStringSlice

Range return slice[i:j], panic when out of range or i > j

func (*TypeStringSlice) Same

func (ss *TypeStringSlice) Same(target []string) bool

Same whether it is totally same as target slice

func (*TypeStringSlice) Set

func (ss *TypeStringSlice) Set(i int, s string) *TypeStringSlice

Set set element at position of slice. Panic if index is invalid.

func (*TypeStringSlice) Shift

func (ss *TypeStringSlice) Shift(elm string, more ...string) *TypeStringSlice

Shift shift elements into slice. Return new slice

func (*TypeStringSlice) To

func (ss *TypeStringSlice) To(i int) *TypeStringSlice

To return slice[:i], if out of range return slice[:last]

func (*TypeStringSlice) Trim

func (ss *TypeStringSlice) Trim(elm string) *TypeStringSlice

Trim remove target element from both sides of slice

func (*TypeStringSlice) TrimSpace

func (ss *TypeStringSlice) TrimSpace() *TypeStringSlice

TrimSpace remove empty string from both sides of slice

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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