gutil

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

README

gutil

介绍
安装

go get -u gitee.com/white-ravens/gutil

示例

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat

func Concat[T any](v ...[]T) []T

Concat 合并切片

func Create

func Create(p string) (*os.File, error)

Create 创建文件时自动创建不存在的文件夹

func Every

func Every[T any](s []T, handler func(T, int) bool) bool

Every 判断是否全部满足条件

func Filter

func Filter[T any](s []T, handler func(T, int) bool) []T

Filter 过滤出满足条件的切片

func Find

func Find[T any](s []T, handler func(T, int) bool) T

Find 返回满足条件的元素

func FindIndex

func FindIndex[T any](s []T, handler func(T, int) bool) int

FindIndex 返回满足条件的元素的索引, 未找到为-1

func Includes

func Includes[T Compare](s []T, v T) bool

Includes 判断切片中是否包含某个元素

func InitLog

func InitLog(p string, prefix string, flags int) error

func Keys

func Keys[T Compare, K any](m map[T]K) []T

Keys 返回切片的键

func LogPrintln

func LogPrintln(v ...any)

LogPrintln 格式化log打印

func Map

func Map[T any](s []T, handle func(T, int) T) []T

Map 返回处理后的切片

func Or

func Or[T any](flag bool, a, b T) T

Or 代替三元运算符

func Pop

func Pop[T any](s []T) []T

Pop 删除最后一位元素 不改变原切片

func Println

func Println(v ...any)

Println 格式化打印

func Push

func Push[T any](s []T, v ...T) []T

Push 向末尾添加0个或多个元素 不改变原切片

func Request

func Request(method string, url string, body io.Reader, header map[string]string, client *http.Client) (*http.Response, error)

Request http请求并响应

func Shift

func Shift[T any](s []T) []T

Shift 删除第一位元素 不改变原切片

func Some

func Some[T any](s []T, handler func(T, int) bool) bool

Some 判断是否有一项满足条件

func Splice

func Splice[T any](s []T, start int, del int, v ...T) []T

Splice 添加或删除元素 不改变原切片

func Sprintln

func Sprintln(v any) string

Sprintln 格式化输出

func Unshift

func Unshift[T any](s []T, v ...T) []T

Unshift 向开头添加元素 不改变原切片

func UrlWithParams added in v1.0.1

func UrlWithParams(baseUrl string, params map[string]string) string

UrlWithParams url参数处理

func Values

func Values[T Compare, K any](m map[T]K) []K

Values 返回切片的值

func WriteResponse

func WriteResponse(w http.ResponseWriter, v any) error

WriteResponse 写入响应

Types

type Compare

type Compare interface {
	uint8 | uint16 | uint32 | uint64 | uint | int8 | int16 | int32 | int64 | int | float32 | float64 | string | bool
}

Compare 可比较类型

type FormData

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

FormData 包含buffer, write, err。 不可直接访问属性

func NewFormData

func NewFormData() *FormData

NewFormData 新建FormData, err为nil

func (*FormData) Buffer

func (fd *FormData) Buffer() *bytes.Buffer

Buffer 返回FormData的数据, buffer

func (*FormData) Close

func (fd *FormData) Close() error

Close 关闭FormData 如果之前步骤存在error, 则返回error

func (*FormData) ConentType

func (fd *FormData) ConentType() string

ConentType 返回FormData的content-type

func (*FormData) SetFile

func (fd *FormData) SetFile(key string, name string, file io.Reader)

SetFile 向FormData中写入file key: 键, name: 文件名(包含后缀), file: io.Reader

func (*FormData) SetValue

func (fd *FormData) SetValue(key, value string)

SetValue 向FormData中写入string key: 键, value: 值

func (*FormData) Write

func (fd *FormData) Write() *multipart.Writer

返回FormData的write

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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