utility

package module
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: Apache-2.0 Imports: 21 Imported by: 10

README

GoLang_Utility

It provides following utility class

  • StringBuilder: like StringBuilder on Java, but it has only minimum functions for me
  • LogUtil: for management output log

Version history

  • 2016.03.18 v0.0.1: release
  • 2017.11.28 v0.0.2: bug fix
  • 2018.02.08 v0.1.0: add ReflectHelper
  • 2018.02.09 v1.0.0: add unit test

Documentation

Overview

LogUtil.go

Index

Constants

View Source
const CUIParamExpectExist = "exist"
View Source
const CUIParamExpectFile = "file"
View Source
const CUIParamExpectFolder = "folder"
View Source
const CUIParamExpectIn = "in("
View Source
const CUIParamExpectNotExist = "not_exist"
View Source
const LogLevelD = 15
View Source
const LogLevelE = 1
View Source
const LogLevelI = 7
View Source
const LogLevelV = 31
View Source
const LogLevelW = 3
View Source
const PwValidLargeAlpha = 2
View Source
const PwValidNumeric = 4
View Source
const PwValidSmallAlpha = 1
View Source
const PwValidSymbol = 8

Variables

View Source
var EnableDebug bool = true
View Source
var NotFoundErr = fmt.Errorf("not found the value")

Functions

func AppendPrefix added in v1.7.0

func AppendPrefix(path, prefix string) string

func AppendSuffix added in v1.7.0

func AppendSuffix(path, suffix string) string

func CallAfterDelay added in v1.10.0

func CallAfterDelay(delayTime time.Duration, funcValue reflect.Value, parameters ...interface{}) []reflect.Value

func CallAfterRandomDelay added in v1.10.0

func CallAfterRandomDelay(funcValue reflect.Value, parameters ...interface{}) []reflect.Value

func CamelToSnakeCase added in v1.1.0

func CamelToSnakeCase(text string) string

func ChangeExtension added in v1.6.0

func ChangeExtension(path string, newExtension string) string

func ChangeLogLevel

func ChangeLogLevel(logLevel int)

func ChangeLogLevelByText added in v1.4.3

func ChangeLogLevelByText(logLevelText string)

func ChangeOutput added in v1.10.0

func ChangeOutput(outputFile string)

func CreatePassword added in v1.10.0

func CreatePassword(length int, validTypes ...int) string

func ExchangeAlphabetToHalfAlphabet added in v1.13.0

func ExchangeAlphabetToHalfAlphabet(originalText string) string

func ExchangeHalfAlphabetToAlphabet added in v1.13.0

func ExchangeHalfAlphabetToAlphabet(originalText string) string

func ExchangeHalfKanaToKana added in v1.13.0

func ExchangeHalfKanaToKana(originalText string) string

func ExchangeHalfNumberToNumber added in v1.13.0

func ExchangeHalfNumberToNumber(originalText string) string

func ExchangeHalfSpaceToSpace added in v1.13.0

func ExchangeHalfSpaceToSpace(originalText string) string

func ExchangeHalfSymbolToSymbol added in v1.13.0

func ExchangeHalfSymbolToSymbol(originalText string) string

func ExchangeHiraganaToKana added in v1.13.0

func ExchangeHiraganaToKana(originalText string) string

func ExchangeKanaToHiragana added in v1.13.0

func ExchangeKanaToHiragana(originalText string) string

func ExchangeNFCtoNFD added in v1.13.0

func ExchangeNFCtoNFD(originalText string) string

func ExchangeNFDtoNFC added in v1.13.0

func ExchangeNFDtoNFC(originalText string) string

func ExchangeNumberToHalfNumber added in v1.13.0

func ExchangeNumberToHalfNumber(originalText string) string

func ExchangePath added in v1.13.0

func ExchangePath(originalPath string) string

func ExchangeRomanNumberToHalfNumber added in v1.13.0

func ExchangeRomanNumberToHalfNumber(originalText string) string

func ExchangeSpaceToHalfSpace added in v1.13.0

func ExchangeSpaceToHalfSpace(originalText string) string

func ExchangeSymbolToHalfSymbol added in v1.13.0

func ExchangeSymbolToHalfSymbol(originalText string) string

func GetCUIParameter added in v1.10.0

func GetCUIParameter(receiver interface{}, debug bool) []error

func GetFiles added in v1.6.0

func GetFiles(path string, allowExtensions []string) []string

func GetFilesV added in v1.6.1

func GetFilesV(path string, allowExtensions ...string) []string

func GetInterface added in v1.10.0

func GetInterface(mapObject interface{}, key interface{}) (interface{}, error)

func GetLogLevel

func GetLogLevel() int

func GetMIMETypeFromExtension added in v1.8.0

func GetMIMETypeFromExtension(filePath string) string

func GetNumber added in v1.10.0

func GetNumber(mapObject interface{}, key interface{}) (float64, error)

func GetParent added in v1.10.0

func GetParent(itemPath string) string

func GetRealFilepath added in v1.13.0

func GetRealFilepath(filePath string, ignoreNameCase, ignoreExtCase bool) (outputFilepath string, exist bool)

func GetString added in v1.10.0

func GetString(mapObject interface{}, key interface{}) (string, error)

func GetUserInput added in v1.10.0

func GetUserInput(prefix string, caseSensitive bool, inputHandler *InputHandler, otherInputHandlers ...(*InputHandler)) (userInput string, ret bool)

func HasPrefix added in v1.9.0

func HasPrefix(s, prefix []rune) bool

func HasSuffix added in v1.9.0

func HasSuffix(s, suffix []rune) bool

func IndexRunes added in v1.9.0

func IndexRunes(s []rune, subRunes []rune) int

func IsDir added in v1.6.0

func IsDir(path string) bool

func IsExist added in v1.6.0

func IsExist(path string) bool

func IsFile added in v1.6.0

func IsFile(path string) bool

func IsFileByFileInfo added in v1.10.0

func IsFileByFileInfo(fileInfo os.FileInfo) bool

func IsNotFound added in v1.10.0

func IsNotFound(err error) bool
func IsSymlink(path string) bool

func IsSymlinkByFileInfo added in v1.10.0

func IsSymlinkByFileInfo(fileInfo os.FileInfo) bool

func LastIndexRunes added in v1.9.0

func LastIndexRunes(s []rune, subRunes []rune) int

func LogD

func LogD(content string)

func LogE

func LogE(content string)

func LogI

func LogI(content string)

func LogInit

func LogInit()

func LogV

func LogV(content string)

func LogW

func LogW(content string)

func LogfD added in v1.10.0

func LogfD(format string, args ...interface{})

func LogfE added in v1.10.0

func LogfE(format string, args ...interface{})

func LogfI added in v1.10.0

func LogfI(format string, args ...interface{})

func LogfV added in v1.10.0

func LogfV(format string, args ...interface{})

func LogfW added in v1.10.0

func LogfW(format string, args ...interface{})

func MapKeys added in v1.6.0

func MapKeys(mapObj interface{}) interface{}

func Open added in v1.13.0

func Open(filePath string) (*os.File, error)

func OpenFile added in v1.13.0

func OpenFile(filePath string, flag int, perm os.FileMode) (*os.File, error)

func ParseNumber added in v1.10.0

func ParseNumber(str string) (float64, error)

func PrepareOutputFilepath added in v1.10.0

func PrepareOutputFilepath(inputTopFolderpath, inputFilepath, outputTopFolderpath, distExtension string) string

func ReadFile added in v1.13.0

func ReadFile(filePath string) ([]byte, error)

func RemoveSliceItem added in v1.10.0

func RemoveSliceItem(slice interface{}, position int) (interface{}, bool)

func SnakeToCamelCase added in v1.1.0

func SnakeToCamelCase(text string) string

func Split added in v1.5.0

func Split(originalText string, sepTextSlice []string, invalidSpaceStarters ...string) []string

func ToIntSlice added in v1.13.0

func ToIntSlice(fromInterface interface{}) (ret []int, retErr error)

func ToInterfaceSlice added in v1.13.0

func ToInterfaceSlice(fromInterface interface{}) (ret []interface{}, retErr error)

func ToLowerFirst added in v1.2.0

func ToLowerFirst(text string) string

func ToUpperFirst added in v1.2.0

func ToUpperFirst(text string) string

func UseStdout added in v1.12.0

func UseStdout(useStdout bool)

func Version added in v1.0.0

func Version() string

func VersionMajorCode added in v1.0.0

func VersionMajorCode() int

func VersionMinorCode added in v1.0.0

func VersionMinorCode() int

func VersionRevisionCode added in v1.0.0

func VersionRevisionCode() int

Types

type ConfigHelper added in v1.4.2

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

func NewConfigHelper added in v1.4.2

func NewConfigHelper(configData interface{}, configFilePath string) *ConfigHelper

func (*ConfigHelper) ExpandConfigData added in v1.4.2

func (helper *ConfigHelper) ExpandConfigData() error

func (*ConfigHelper) ExpandConfigData2 added in v1.9.1

func (helper *ConfigHelper) ExpandConfigData2() (error, bool)

func (*ConfigHelper) StoreConfigData added in v1.10.0

func (helper *ConfigHelper) StoreConfigData() error

type FormData added in v1.10.0

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

func (*FormData) Filename added in v1.10.0

func (formData *FormData) Filename() string

func (*FormData) MimeType added in v1.10.0

func (formData *FormData) MimeType() string

func (*FormData) Part added in v1.10.0

func (formData *FormData) Part() ([]byte, error)

type InputHandler added in v1.10.0

type InputHandler struct {
	Key     string
	Handler func(string) bool
}

type InterfaceHelper added in v1.10.0

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

func NewInterfaceHelper added in v1.10.0

func NewInterfaceHelper(valueInterface interface{}) *InterfaceHelper

func (*InterfaceHelper) GetBool added in v1.10.0

func (helper *InterfaceHelper) GetBool() (bool, bool)

func (*InterfaceHelper) GetBoolArray added in v1.10.0

func (helper *InterfaceHelper) GetBoolArray() ([]bool, bool)

func (*InterfaceHelper) GetInterfaceArray added in v1.13.0

func (helper *InterfaceHelper) GetInterfaceArray() ([]interface{}, bool)

func (*InterfaceHelper) GetKind added in v1.10.0

func (helper *InterfaceHelper) GetKind() reflect.Kind

func (*InterfaceHelper) GetNumber added in v1.10.0

func (helper *InterfaceHelper) GetNumber() (float64, bool)

func (*InterfaceHelper) GetNumberArray added in v1.10.0

func (helper *InterfaceHelper) GetNumberArray() ([]float64, bool)

func (*InterfaceHelper) GetString added in v1.10.0

func (helper *InterfaceHelper) GetString() (string, bool)

func (*InterfaceHelper) GetStringArray added in v1.10.0

func (helper *InterfaceHelper) GetStringArray() ([]string, bool)

func (*InterfaceHelper) GetTime added in v1.11.0

func (helper *InterfaceHelper) GetTime() (time.Time, bool)

func (*InterfaceHelper) GetTimeArray added in v1.11.0

func (helper *InterfaceHelper) GetTimeArray() ([]time.Time, bool)

func (*InterfaceHelper) IsArrayOrSlice added in v1.10.0

func (helper *InterfaceHelper) IsArrayOrSlice() bool

func (*InterfaceHelper) IsBool added in v1.10.0

func (helper *InterfaceHelper) IsBool() bool

func (*InterfaceHelper) IsFloat added in v1.10.0

func (helper *InterfaceHelper) IsFloat() bool

func (*InterfaceHelper) IsInt added in v1.10.0

func (helper *InterfaceHelper) IsInt() bool

func (*InterfaceHelper) IsNumber added in v1.10.0

func (helper *InterfaceHelper) IsNumber() bool

func (*InterfaceHelper) IsString added in v1.10.0

func (helper *InterfaceHelper) IsString() bool

func (*InterfaceHelper) IsTime added in v1.11.0

func (helper *InterfaceHelper) IsTime() bool

func (*InterfaceHelper) IsUint added in v1.10.0

func (helper *InterfaceHelper) IsUint() bool

func (*InterfaceHelper) Set added in v1.10.0

func (helper *InterfaceHelper) Set(from interface{}) bool

type Logger

type Logger struct {
	LogLevel int
	// contains filtered or unexported fields
}

func (*Logger) ChangeLogLevel

func (this *Logger) ChangeLogLevel(logLevel int)

func (*Logger) ChangeLogLevelByText added in v1.4.3

func (this *Logger) ChangeLogLevelByText(logLevelText string)

func (*Logger) ChangeOutput added in v1.10.0

func (this *Logger) ChangeOutput(outputFile string)

func (*Logger) GetLogLevel

func (this *Logger) GetLogLevel() int

func (*Logger) LogD

func (this *Logger) LogD(content string)

func (*Logger) LogE

func (this *Logger) LogE(content string)

func (*Logger) LogI

func (this *Logger) LogI(content string)

func (*Logger) LogV

func (this *Logger) LogV(content string)

func (*Logger) LogW

func (this *Logger) LogW(content string)

func (*Logger) LogfD added in v1.10.0

func (this *Logger) LogfD(format string, args ...interface{})

func (*Logger) LogfE added in v1.10.0

func (this *Logger) LogfE(format string, args ...interface{})

func (*Logger) LogfI added in v1.10.0

func (this *Logger) LogfI(format string, args ...interface{})

func (*Logger) LogfV added in v1.10.0

func (this *Logger) LogfV(format string, args ...interface{})

func (*Logger) LogfW added in v1.10.0

func (this *Logger) LogfW(format string, args ...interface{})

func (*Logger) UseStdout added in v1.12.0

func (this *Logger) UseStdout(useStdout bool)

type LoggerIF

type LoggerIF interface {
	GetLogLevel() int
	ChangeLogLevel(logLevel int)
	LogV(content string)
	LogD(content string)
	LogI(content string)
	LogW(content string)
	LogE(content string)
	// contains filtered or unexported methods
}

type MultipartHelper added in v1.10.0

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

func NewMultipartHelper added in v1.10.0

func NewMultipartHelper(reader io.Reader, boundary string) (*MultipartHelper, error)

func NewMultipartHelperFromHttpRequest added in v1.10.0

func NewMultipartHelperFromHttpRequest(r *http.Request) (*MultipartHelper, error)

func (*MultipartHelper) Close added in v1.10.0

func (helper *MultipartHelper) Close() error

func (*MultipartHelper) Count added in v1.10.0

func (helper *MultipartHelper) Count() int

func (*MultipartHelper) GetByIndex added in v1.10.0

func (helper *MultipartHelper) GetByIndex(index int) (*FormData, error)

func (*MultipartHelper) GetByName added in v1.10.0

func (helper *MultipartHelper) GetByName(partName string) (*FormData, error)

func (*MultipartHelper) PartNames added in v1.10.0

func (helper *MultipartHelper) PartNames() []string

type RangeValue added in v1.10.0

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

func ParseNumberRange added in v1.10.0

func ParseNumberRange(str string) (value *RangeValue, retErr error)

func (*RangeValue) In added in v1.10.0

func (rValue *RangeValue) In(targetValue float64) bool

func (*RangeValue) Out added in v1.10.0

func (rValue *RangeValue) Out(targetValue float64) bool

type ReadHelper added in v1.13.0

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

func NewReadHelper added in v1.13.0

func NewReadHelper(reader io.Reader) *ReadHelper

func NewReadHelperFromFile added in v1.13.0

func NewReadHelperFromFile(filePath string) (ret *ReadHelper, retErr error)

func NewReadHelperFromReadCloser added in v1.13.0

func NewReadHelperFromReadCloser(reader io.ReadCloser) *ReadHelper

func (*ReadHelper) Close added in v1.13.0

func (helper *ReadHelper) Close() (ret error)

func (*ReadHelper) ReadLine added in v1.13.0

func (helper *ReadHelper) ReadLine() (ret string, retErr error)

type ReflectHelper added in v0.1.0

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

func NewReflectHelper added in v0.1.0

func NewReflectHelper(targetInterface interface{}) *ReflectHelper

func (*ReflectHelper) BoolValue added in v0.1.0

func (this *ReflectHelper) BoolValue(index int) bool

func (*ReflectHelper) Call added in v1.3.0

func (this *ReflectHelper) Call(methodName string, values []reflect.Value) []reflect.Value

func (*ReflectHelper) CanSet added in v0.1.0

func (this *ReflectHelper) CanSet(name string, value interface{}) bool

func (*ReflectHelper) FieldIndex added in v1.10.0

func (this *ReflectHelper) FieldIndex(name string) int

func (*ReflectHelper) FieldName added in v1.10.0

func (this *ReflectHelper) FieldName(index int) string

func (*ReflectHelper) FloatValue added in v0.1.0

func (this *ReflectHelper) FloatValue(index int) float64

func (*ReflectHelper) GetAddrByIndex added in v1.10.0

func (this *ReflectHelper) GetAddrByIndex(index int) reflect.Value

func (*ReflectHelper) GetByIndex added in v0.1.0

func (this *ReflectHelper) GetByIndex(index int) interface{}

func (*ReflectHelper) GetByName added in v0.1.0

func (this *ReflectHelper) GetByName(name string) interface{}

func (*ReflectHelper) GetByTagName added in v1.3.1

func (this *ReflectHelper) GetByTagName(key string, name string) interface{}

func (*ReflectHelper) GetPtrByIndex added in v1.10.0

func (this *ReflectHelper) GetPtrByIndex(index int) reflect.Value

func (*ReflectHelper) GetValueByIndex added in v1.10.0

func (this *ReflectHelper) GetValueByIndex(index int) reflect.Value

func (*ReflectHelper) IntValue added in v0.1.0

func (this *ReflectHelper) IntValue(index int) int64

func (*ReflectHelper) InterfaceName added in v0.1.0

func (this *ReflectHelper) InterfaceName() string

func (*ReflectHelper) IsBool added in v0.1.0

func (this *ReflectHelper) IsBool(index int) bool

func (*ReflectHelper) IsFloat added in v1.10.0

func (this *ReflectHelper) IsFloat(index int) bool

func (*ReflectHelper) IsFloat32 added in v0.1.0

func (this *ReflectHelper) IsFloat32(index int) bool

func (*ReflectHelper) IsFloat64 added in v0.1.0

func (this *ReflectHelper) IsFloat64(index int) bool

func (*ReflectHelper) IsInt added in v1.10.0

func (this *ReflectHelper) IsInt(index int) bool

func (*ReflectHelper) IsInt8 added in v0.1.0

func (this *ReflectHelper) IsInt8(index int) bool

func (*ReflectHelper) IsInt16 added in v0.1.0

func (this *ReflectHelper) IsInt16(index int) bool

func (*ReflectHelper) IsInt32 added in v0.1.0

func (this *ReflectHelper) IsInt32(index int) bool

func (*ReflectHelper) IsInt64 added in v0.1.0

func (this *ReflectHelper) IsInt64(index int) bool

func (*ReflectHelper) IsIntUint added in v1.10.0

func (this *ReflectHelper) IsIntUint(index int) bool

func (*ReflectHelper) IsNumber added in v1.10.0

func (this *ReflectHelper) IsNumber(index int) bool

func (*ReflectHelper) IsString added in v0.1.0

func (this *ReflectHelper) IsString(index int) bool

func (*ReflectHelper) IsTime added in v1.10.0

func (this *ReflectHelper) IsTime(index int) bool

func (*ReflectHelper) IsUint added in v1.10.0

func (this *ReflectHelper) IsUint(index int) bool

func (*ReflectHelper) IsUint8 added in v0.1.0

func (this *ReflectHelper) IsUint8(index int) bool

func (*ReflectHelper) IsUint16 added in v0.1.0

func (this *ReflectHelper) IsUint16(index int) bool

func (*ReflectHelper) IsUint32 added in v0.1.0

func (this *ReflectHelper) IsUint32(index int) bool

func (*ReflectHelper) IsUint64 added in v0.1.0

func (this *ReflectHelper) IsUint64(index int) bool

func (*ReflectHelper) NumField added in v0.1.0

func (this *ReflectHelper) NumField() int

func (*ReflectHelper) SetByIndex added in v0.1.0

func (this *ReflectHelper) SetByIndex(index int, valueInf interface{}) bool

func (*ReflectHelper) SetByName added in v0.1.0

func (this *ReflectHelper) SetByName(name string, value interface{}) bool

func (*ReflectHelper) String added in v0.1.0

func (this *ReflectHelper) String(index int) string

func (*ReflectHelper) StringValue added in v0.1.0

func (this *ReflectHelper) StringValue(index int) string

func (*ReflectHelper) Tag added in v0.1.0

func (this *ReflectHelper) Tag(index int) reflect.StructTag

func (*ReflectHelper) TimeValue added in v1.10.0

func (this *ReflectHelper) TimeValue(index int) time.Time

func (*ReflectHelper) UintValue added in v0.1.0

func (this *ReflectHelper) UintValue(index int) uint64

func (*ReflectHelper) ValueKind added in v0.1.0

func (this *ReflectHelper) ValueKind(index int) reflect.Kind

type StringBuilder

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

func (*StringBuilder) Append

func (this *StringBuilder) Append(text string) *StringBuilder

func (*StringBuilder) AppendByte added in v1.1.0

func (this *StringBuilder) AppendByte(text byte) *StringBuilder

func (*StringBuilder) Appendf added in v1.10.0

func (this *StringBuilder) Appendf(fmtText string, params ...interface{}) *StringBuilder

func (*StringBuilder) Bytes added in v1.0.0

func (this *StringBuilder) Bytes() []byte

func (*StringBuilder) Delete

func (this *StringBuilder) Delete()

func (*StringBuilder) Length added in v1.0.0

func (this *StringBuilder) Length() int

func (*StringBuilder) String

func (this *StringBuilder) String() string

type StringBuilderIF

type StringBuilderIF interface {
	Append(text string) StringBuilder
	AppendByte(text byte) StringBuilder
	Delete()
	String() string
	Length() int
	Bytes() []byte
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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