util

package module
v0.0.0-...-c47863f Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: BSD-3-Clause Imports: 23 Imported by: 0

README

go-util

A simple util module in Go.

Features

TODO

Documentation

Index

Constants

View Source
const HandyLayout = "2006-01-02 15:04:05.000"

Variables

This section is empty.

Functions

func Capture

func Capture(s, left, right string) string

func ExecCommand

func ExecCommand(cmd string, args ...string) (string, error)

func ExecShell

func ExecShell(cmd string) (string, error)

func Exists

func Exists(path string) bool

func FromJson

func FromJson(s string, v interface{})

func GenUUids

func GenUUids() string

func GetVersion

func GetVersion() string

func HmacSha256

func HmacSha256(data string, secret string) string

func HttpRequest

func HttpRequest(method, url string, headers map[string]string, body io.Reader) ([]byte, error)

HttpRequest 发送request func SendRequest(url string, body io.Reader, addHeaders map[string]string, method string) ([]byte, error) {

func HttpRequestJson

func HttpRequestJson(method string, url string, headers map[string]string, req interface{}, resp interface{}) error

HttpRequestJson 发送http请求。请求体和响应体都是json。

func MakeDir

func MakeDir(path string) error

func Milliseconds

func Milliseconds() int64

func ReadFile

func ReadFile(path string) string

func RemoveDir

func RemoveDir(dirName string) error

func RemoveFile

func RemoveFile(fileName string)

func TimeNowString

func TimeNowString() string

func ToBinary

func ToBinary(vs ...interface{}) []byte

func ToJson

func ToJson(v interface{}) string

func Unzip

func Unzip(zipFile string, destDir string) error

zip解压

func Zip

func Zip(srcFile string, destZip string) error

zip压缩

Types

type Config

type Config struct {
	*sjson.Json
	ConfigFile        string
	DefaultConfigFile string
}

Config 配置

func NewConfig

func NewConfig(filePath, defaultFilePath string) (*Config, error)

NewConfig 从配置文件创建配置

func (*Config) LoadStruct

func (c *Config) LoadStruct(path string, v interface{})

LoadStruct 从配置文件加载到结构体

func (*Config) Reset

func (c *Config) Reset() error

Reset 恢复默认设置

func (*Config) Set

func (c *Config) Set(path string, v interface{})

Set 设置值。相当于sjson.Set()+c.save()

type Mutex

type Mutex struct {
	sync.Mutex
}

func (*Mutex) TryLock

func (m *Mutex) TryLock() bool

Jump to

Keyboard shortcuts

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