helper

package module
v0.0.0-...-8057cf2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 18 Imported by: 3

README

go-helper

Go Report Card GoDoc Github All Releases GitHub release GitHub Release Date GitHub license GitHub stars GitHub forks Sourcegraph

A help package for golang, provide some utilities, encryption and database orm struct.

helper package

ByteHelper

ByteHelper provides Hex and Byte format conversion.

ConsoleColorHelper

ConsoleColorHelper provides console color support.

FileHelper

FileHelper provides file copy and gzip compression support.

HttpHelper

HttpHelper provides http GET, POST and PostForm support.

PathHelper
RandHelper

RandHelper provides rand specified number of numbers or strings.

StringHelper
TimeHelper

TimeHelper provides full format of time format support.

algo package

A golang crypto package extended, including encryption and padding.

encryption:

  • AES
  • DES
  • TripleDES
  • HMac
  • SHA

Padding:

  • ZeroPadding
  • PKCS5Padding

orm package

Database xorm struct, including:

  • PostgreSQL
  • MySQL
  • Redis
  • SQLite

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConsoleColor = NewConsoleColorHelper()
View Source
var Exec = NewExecHelper()
View Source
var File = NewFileHelper()
View Source
var Http = NewHttpHelper(90, false)
View Source
var Path = NewPathHelper()
View Source
var Rand = NewRandHelper()
View Source
var String = NewStringHelper()
View Source
var Time = NewTimeHelper()

Functions

This section is empty.

Types

type BufferPool

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

BufferPool implements a pool of bytes.Buffers in the form of a bounded channel.

func NewBufferPool

func NewBufferPool(size int) (bp *BufferPool)

NewBufferPool creates a new BufferPool bounded to the given size.

func (*BufferPool) Get

func (this *BufferPool) Get() (buffer *bytes.Buffer)

Get gets a Buffer from the BufferPool, or creates a new one if none are available in the pool.

func (*BufferPool) Set

func (this *BufferPool) Set(buffer *bytes.Buffer)

Set returns the given Buffer to the BufferPool.

type ByteHelper

type ByteHelper struct{}

func NewByteHelper

func NewByteHelper() *ByteHelper

func (*ByteHelper) Bin2Byte

func (this *ByteHelper) Bin2Byte(bin []byte) (buf []byte)

func (*ByteHelper) Byte2Bin

func (this *ByteHelper) Byte2Bin(buf []byte) (bin []byte)

func (*ByteHelper) Byte2Hex

func (this *ByteHelper) Byte2Hex(buf []byte) (hex []byte)

func (*ByteHelper) Hex2Byte

func (this *ByteHelper) Hex2Byte(hex []byte) (buf []byte)

type ConsoleColorHelper

type ConsoleColorHelper struct{}

func NewConsoleColorHelper

func NewConsoleColorHelper() *ConsoleColorHelper

func (*ConsoleColorHelper) Blue

func (this *ConsoleColorHelper) Blue() string

func (*ConsoleColorHelper) BlueBackground

func (this *ConsoleColorHelper) BlueBackground() string

func (*ConsoleColorHelper) Clear

func (this *ConsoleColorHelper) Clear() string

func (*ConsoleColorHelper) Cyan

func (this *ConsoleColorHelper) Cyan() string

func (*ConsoleColorHelper) CyanBackground

func (this *ConsoleColorHelper) CyanBackground() string

func (*ConsoleColorHelper) GrayBackground

func (this *ConsoleColorHelper) GrayBackground() string

\033[90;47m

func (*ConsoleColorHelper) Green

func (this *ConsoleColorHelper) Green() string

func (*ConsoleColorHelper) GreenBackground

func (this *ConsoleColorHelper) GreenBackground() string

func (*ConsoleColorHelper) Magenta

func (this *ConsoleColorHelper) Magenta() string

func (*ConsoleColorHelper) MagentaBackground

func (this *ConsoleColorHelper) MagentaBackground() string

func (*ConsoleColorHelper) Red

func (this *ConsoleColorHelper) Red() string

func (*ConsoleColorHelper) RedBackground

func (this *ConsoleColorHelper) RedBackground() string

func (*ConsoleColorHelper) White

func (this *ConsoleColorHelper) White() string

func (*ConsoleColorHelper) WhiteBackground

func (this *ConsoleColorHelper) WhiteBackground() string

func (*ConsoleColorHelper) Yello

func (this *ConsoleColorHelper) Yello() string

func (*ConsoleColorHelper) YelloBackground

func (this *ConsoleColorHelper) YelloBackground() string

type ExecHelper

type ExecHelper struct{}

func NewExecHelper

func NewExecHelper() *ExecHelper

func (*ExecHelper) Run

func (this *ExecHelper) Run(name string, args ...string) ([]byte, error)

type FileHelper

type FileHelper struct{}

func NewFileHelper

func NewFileHelper() *FileHelper

func (*FileHelper) CopyFile

func (this *FileHelper) CopyFile(src, dst string) (int64, error)

Copy copies from src to dst until either EOF is reached on src or an error occurs. It returns the number of bytes copied and the first error encountered while copying, if any.

A successful Copy returns err == nil, not err == EOF. Because Copy is defined to read from src until EOF, it does not treat an EOF from Read as an error to be reported.

If src implements the WriterTo interface, the copy is implemented by calling src.WriteTo(dst). Otherwise, if dst implements the ReaderFrom interface, the copy is implemented by calling dst.ReadFrom(src).

func (*FileHelper) GZipFile

func (this *FileHelper) GZipFile(src, dst string) error

Use gzip to compress src to dst until either EOF is reached or an error occurs.

func (*FileHelper) Save

func (this *FileHelper) Save(fileName string, body []byte) error

type HttpHelper

type HttpHelper struct {
	UserAgent string
	// contains filtered or unexported fields
}

func NewHttpHelper

func NewHttpHelper(timeout int, insecure bool) *HttpHelper

func (*HttpHelper) Do

func (this *HttpHelper) Do(r *http.Request) (*http.Response, error)

func (*HttpHelper) Get

func (this *HttpHelper) Get(addr string) ([]byte, error)

func (*HttpHelper) NewRequest

func (this *HttpHelper) NewRequest(method, addr string, body io.Reader) (*http.Request, error)

func (*HttpHelper) Post

func (this *HttpHelper) Post(addr string, body io.Reader) ([]byte, error)

func (*HttpHelper) PostForm

func (this *HttpHelper) PostForm(addr string, data url.Values) ([]byte, error)

func (*HttpHelper) RemoteAddr

func (this *HttpHelper) RemoteAddr(req *http.Request) string

type PathHelper

type PathHelper struct{}

func NewPathHelper

func NewPathHelper() *PathHelper

func (*PathHelper) Abs

func (this *PathHelper) Abs(filePath string) (string, error)

func (*PathHelper) Create

func (this *PathHelper) Create(dir string, perm os.FileMode) error

func (*PathHelper) CreateDir

func (this *PathHelper) CreateDir(filePath string, perm os.FileMode) error

func (*PathHelper) Dir

func (this *PathHelper) Dir(filePath string) (string, error)

func (*PathHelper) ExecPath

func (this *PathHelper) ExecPath() string

func (*PathHelper) FileName

func (this *PathHelper) FileName(filePath string) (string, error)

func (*PathHelper) IsExist

func (this *PathHelper) IsExist(path string) (bool, error)

判断文件夹是否存在

func (*PathHelper) Split

func (this *PathHelper) Split(filePath string) []string

func (*PathHelper) WorkDir

func (this *PathHelper) WorkDir() string

WorkDir returns absolute path of work directory.

func (*PathHelper) WorkName

func (this *PathHelper) WorkName() string

type RandHelper

type RandHelper struct{}

func NewRandHelper

func NewRandHelper() *RandHelper

func (*RandHelper) Bytes

func (this *RandHelper) Bytes(length int) []byte

生成随机字符串

func (*RandHelper) Num

func (this *RandHelper) Num(length int) int64

func (*RandHelper) String

func (this *RandHelper) String(length int) string

生成随机字符串

type StringHelper

type StringHelper struct{}

func NewStringHelper

func NewStringHelper() *StringHelper

func (*StringHelper) Empty

func (this *StringHelper) Empty() string

func (*StringHelper) IsEmpty

func (this *StringHelper) IsEmpty(str string) bool

func (*StringHelper) IsEqual

func (this *StringHelper) IsEqual(str, equal string) bool

func (*StringHelper) IsNotEmpty

func (this *StringHelper) IsNotEmpty(str string) bool

func (*StringHelper) IsNotEqual

func (this *StringHelper) IsNotEqual(str, equal string) bool

type StructMapHelper

type StructMapHelper struct {
	Name  string `map:"Name"`  // example
	Value string `map:"Value"` // example
}

func NewStructMapHelper

func NewStructMapHelper() *StructMapHelper

func (*StructMapHelper) FromMap

func (this *StructMapHelper) FromMap(obj interface{}, m map[string]interface{}, tag string)

func (*StructMapHelper) FromMapString

func (this *StructMapHelper) FromMapString(obj interface{}, m map[string]string, tag string)

func (*StructMapHelper) MapString

func (this *StructMapHelper) MapString() string

func (*StructMapHelper) ToMap

func (this *StructMapHelper) ToMap(obj interface{}, tag string) map[string]interface{}

func (*StructMapHelper) ToMapString

func (this *StructMapHelper) ToMapString(obj interface{}, tag string) map[string]string

type TimeHelper

type TimeHelper struct{}

func NewTimeHelper

func NewTimeHelper() *TimeHelper

func (*TimeHelper) ConvertLocation

func (this *TimeHelper) ConvertLocation(t time.Time, name string) (time.Time, error)

Convert time to the given location

func (*TimeHelper) DefaultFormat

func (this *TimeHelper) DefaultFormat(t time.Time) string

Use yyyy-mm-dd HH:MM:SS.ms format the time

func (*TimeHelper) Format

func (this *TimeHelper) Format(format string, t time.Time) string

Format time with easy-to-understand strings, e.g. yyyy-mm-dd HH:MM:SS.ms

func (*TimeHelper) Parse

func (this *TimeHelper) Parse(format, value string) (time.Time, error)

Parse time with easy-to-understand strings, e.g. yyyy-mm-dd HH:MM:SS.ms

Jump to

Keyboard shortcuts

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