gops

package
v1.0.116 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MulanPSL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STANDARD_FORMAT = "2006-01-02 15:04:05"
	DATE_FORMAT     = "2006-01-02"
	MONTH_FORMAT    = "2006-01"
	FLAT_DATE       = "20060102"
	FLAT_FORMAT     = "20060102150405"
)

常量:时间格式

Variables

This section is empty.

Functions

func AddDuration

func AddDuration(t time.Time, duration string) (time.Time, error)

AddDuration 给指定时间增加指定的时间间隔

func BackgroundExecuteWithInterval

func BackgroundExecuteWithInterval(execution func(), duration time.Duration, done <-chan struct{})

BackgroundExecuteWithInterval 启动后台执行函数,每隔 duration 执行一次,并在后台独立运行,不阻塞主进程

func BlueMessage

func BlueMessage(message string)

func Close

func Close(db *gorm.DB)

Close closes the database connection.

func ExecCommand

func ExecCommand(command string, timeout ...int) (string, error)

ExecCommand 执行shell命令 command 为要执行的命令 timeout 为超时时间

func Exists

func Exists(pathname string) bool

Exists 判断所给路径文件/文件夹是否存在

func FileMd5

func FileMd5(filename string) (string, error)

FileMd5 计算指定文件的MD5哈希值。

func ForegroundExecuteWithInterval

func ForegroundExecuteWithInterval(execution func(), duration time.Duration)

ForegroundExecuteWithInterval 执行函数,并每隔 duration 执行一次,阻塞进程执行

func FormatTimestamp

func FormatTimestamp(ts int64, layout string) string

FormatTimestamp 格式化时间戳为指定格式

func GetCurrentMilliTimestamp

func GetCurrentMilliTimestamp() int64

GetCurrentMilliTimestamp 获取当前时间戳(毫秒级)

func GetCurrentTime

func GetCurrentTime() string

GetCurrentTime 获取当前时间的标准格式字符串

func GetCurrentTimestamp

func GetCurrentTimestamp() int64

GetCurrentTimestamp 获取当前时间戳(秒级)

func GreenMessage

func GreenMessage(message string)

func IsDir

func IsDir(pathname string) bool

IsDir 判断所给路径是否为文件夹

func Message

func Message(message string, optionalParams ...string)

logMessage 记录日志到控制台或文件

func MkDir

func MkDir(dirname string) error

MkDir 创建目录

func MkDirIfNotExists

func MkDirIfNotExists(dirname string) error

MkDirIfNotExists 创建目录

func New

func New(dsn string) *gorm.DB

New initializes a new database connection.

func NewMail

func NewMail(host, user, password string, port int, smtpSSL bool) *mailer

func ParseTime

func ParseTime(value string) (time.Time, error)

ParseTime 按标准格式解析时间字符串

func ParseTimeWithFormat

func ParseTimeWithFormat(value, layout string) (time.Time, error)

ParseTimeWithFormat 按指定格式解析时间字符串

func ReadFile

func ReadFile(pathname string) []byte

ReadFile 读取文件

func RedMessage

func RedMessage(message string)

func Remove

func Remove(pathname string) error

Remove 删除文件

func RunPrompt

func RunPrompt[T any](label string, items []T) (string, error)

使用泛型定义RunPrompt

func SendMarkdownMessage

func SendMarkdownMessage(token string, content string) error

func StandardFormat

func StandardFormat(ts int64) string

StandardFormat 格式化时间戳为标准时间字符串

func StrMd5

func StrMd5(s string) (res string, err error)

Md5 计算指定字符串的MD5哈希值

func SubtractTimes

func SubtractTimes(t1, t2 time.Time) time.Duration

SubtractTimes 计算两个时间的差值

func SyncOne

func SyncOne()

func YellowMessage

func YellowMessage(message string)

Types

type RequestGetOptions

type RequestGetOptions struct {
	URL     string            `json:"url"`
	Params  map[string]string `json:"params"`
	Headers map[string]string `json:"headers"`
}

type RequestPostOptions

type RequestPostOptions struct {
	URL     string            `json:"url"`
	Data    map[string]any    `json:"data"`
	Headers map[string]string `json:"headers"`
}

RequestPostOptions 结构体用于封装POST请求的选项

type Response

type Response struct {
	Code    int    `json:"code"`
	Msg     string `json:"msg"`
	Content any    `json:"content"`
}

func Get

func Get(options RequestGetOptions) (Response, error)

func Post

func Post(options RequestPostOptions) (Response, error)

RequestPost 函数用于发送POST请求

Jump to

Keyboard shortcuts

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