Documentation
¶
Index ¶
- Constants
- Variables
- func Abs[V constraints.Number](a V) V
- func ArrContains[V comparable](arr []V, v V) bool
- func ArrNotContains[V comparable](arr []V, v V) bool
- func CompareArr[T constraints.Ordered](arrA, arrB []T) int
- func Curl(curl string) (string, error)
- func DistinctArr[V comparable](arr ...[]V) []V
- func DistinctCustomArr[V any, C comparable](keyFn func(V) C, arr ...[]V) []V
- func DownloadFromHttp(url string, filePath string, bufferSize int) error
- func FileExist(path string) (bool, error)
- func FilterArr[V any](filterFn func(V) bool, arr ...[]V) []V
- func GenerateGoFileFromDDL(pkg string, ddlPath string, outPath string) error
- func GetAbsolutePath(filePath string) string
- func GetCsvFromFile(filePath string) ([][]string, error)
- func GetCsvFromHttp(url string) ([][]string, error)
- func GetFromFile(filePath string) ([]byte, error)
- func GetLinesFromFile[V any](filePath string, skip func(string) bool, deal func(string) V) ([]V, error)
- func GetMatrixFromFile(filePath string, sep string) ([][]string, error)
- func GetProjectRoot() string
- func GetStringFromFile(filePath string) (string, error)
- func GetStringFromHttp(url string) (string, error)
- func GetTopLinesFromFile[V any](filePath string, top int, skip func(string) bool, deal func(string) V) ([]V, error)
- func Json(v interface{}) string
- func JsonFormat(d interface{}) string
- func LoadJsonFromFile[V any](filePath string) (V, error)
- func Max[V constraints.Number](a V, b ...V) V
- func Min[V constraints.Number](a V, b ...V) V
- func MustUnMarshal[V any](json string) V
- func ParseArrToArr[V any, E any](arr []V, parse func(V) E) []E
- func ParseCustomMapKeyToArr[K comparable, V any, E any](m map[K]V, parse func(K) E) []E
- func ParseCustomMapValueToArr[K comparable, V any, E any](m map[K]V, parse func(V) E) []E
- func ParseFloatToStr[V constraints.Float](a V) string
- func ParseIntToStr[V constraints.Integer](a V) string
- func ParseMapKeyToArr[K comparable, V any](m map[K]V) []K
- func ParseMapValueToArr[K comparable, V any](m map[K]V) []V
- func ParseStrToFloat[V constraints.Float](str string) V
- func ParseStrToInt[V constraints.Integer](str string) V
- func ReadLineFromFile[V any](filePath string, skip func(string) bool, deal func(string) V, ...) error
- func ReadLineFromFileWithErr[V any](filePath string, skip func(string) bool, deal func(string) V, ...) error
- func ReadLineFromHttp[V any](url string, skip func(string) bool, deal func(string) V, ...) error
- func ReadLineParseToArr[V any](arr *[]V) func(i int, line V)
- func ReadTopLineFromFile[V any](filePath string, top int, skip func(string) bool, deal func(string) V, ...) error
- func ReadTopLineFromFileWithErr[V any](filePath string, top int, skip func(string) bool, deal func(string) V, ...) error
- func ReadTopLineFromHttp[V any](url string, top int, skip func(string) bool, deal func(string) V, ...) error
- func ReadTopLineFromHttpWithErr[V any](url string, top int, skip func(string) bool, deal func(string) V, ...) error
- func RepeatString(str string, count int) string
- func ReverseArr[T any](arr []T)
- func ShuffleArr[V any](arr []V) []V
- func Sort[T any](arr []T, compare func(a, b T) bool)
- func SortAsc[T constraints.Ordered](arr []T)
- func SortDesc[T constraints.Ordered](arr []T)
- func Split(s, sep string) []string
- func Swap[T any](arr []T, i, j int)
- func UnMarshal[V any](json string) (V, error)
- func UnderscoreToCamel(str string) string
- func WriteBytesToFile(filePath string, data []byte) error
- func WriteCsvToFile(filePath string, content [][]string) error
- func WriteLineToFile(filePath string, line ...string) error
- func WriteLinesToFile(filePath string, lines []string) error
- func WriteMatrixToFile(filePath string, content [][]string, sep string, byRow bool, fillSep bool) error
- func Zero[V any]() V
- type Csv
- type CsvRow
- type CustomSet
- func (s *CustomSet[V, K]) Add(v V)
- func (s *CustomSet[V, K]) Contain(v V) bool
- func (s *CustomSet[V, K]) ContainKey(k K) bool
- func (s *CustomSet[V, K]) Foreach(fn func(V))
- func (s *CustomSet[V, K]) GetCustomKeys() []K
- func (s *CustomSet[V, K]) Remove(v V)
- func (s *CustomSet[V, K]) RemoveKey(k K)
- func (s *CustomSet[V, K]) Size() int
- func (s *CustomSet[V, K]) ToArr() []V
- type FileWriter
- type HttpReq
- type QueryStructField
- type Scanner
- type Set
- type StructFileMeta
- type StructMeta
Constants ¶
const StructModel = `
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
// Code generated by gorm.io/gen. DO NOT EDIT.
package {{.Package}}
import (
{{range .ImportPkgPaths}}"{{.}}" ` + "\n" + `{{end}}
)
{{range .StructMetas}}
const TableName{{.ModelStructName}} = "{{.TableName}}"
// {{.ModelStructName}} {{.StructComment}}
type {{.ModelStructName}} struct {
{{range .Fields}}
{{.ModelStructName}} {{.Type}} ` + "`{{.Tags}}` " +
"{{if .ColumnComment}}// {{.ColumnComment}}{{end}}" +
`{{end}}
}
func (*{{.ModelStructName}}) TableName() string {
return TableName{{.ModelStructName}}
}
{{end}}
`
Variables ¶
var ( // DealLineTrimSpace 清除前后空格 DealLineTrimSpace = strings.TrimSpace // DealLineTrim 清除前后指定字符 DealLineTrim = _DealLineTrim // DealLineSplit 字符串分割,生成字符串数组 DealLineSplit = _DealLineSplit // DealLineParseInt 转化为int DealLineParseInt = ParseStrToInt[int64] // DealLineParseFloat 转换为float DealLineParseFloat = ParseStrToFloat[float64] // SkipLineEmpty 跳过空字符串 SkipLineEmpty = _SkipLineEmpty // SkipLineSpace 跳过空白字符串(包括空格、制表等) SkipLineSpace = _SkipLineSpace )
Functions ¶
func Abs ¶
func Abs[V constraints.Number](a V) V
func ArrContains ¶
func ArrContains[V comparable](arr []V, v V) bool
func ArrNotContains ¶
func ArrNotContains[V comparable](arr []V, v V) bool
func CompareArr ¶
func CompareArr[T constraints.Ordered](arrA, arrB []T) int
func DistinctCustomArr ¶
func DistinctCustomArr[V any, C comparable](keyFn func(V) C, arr ...[]V) []V
DistinctCustomArr 数组去重,自定义去重key
func DownloadFromHttp ¶
DownloadFromHttp 下载http数据
func GenerateGoFileFromDDL ¶
func GetCsvFromFile ¶
GetCsvFromFile 获取csv格式文件内容
func GetCsvFromHttp ¶
GetCsvFromHttp 获取csv格式文件内容
func GetLinesFromFile ¶
func GetLinesFromFile[V any](filePath string, skip func(string) bool, deal func(string) V) ([]V, error)
GetLinesFromFile 按行获取文件内容
func GetStringFromFile ¶
GetStringFromFile 获取文件内容
func GetStringFromHttp ¶
GetStringFromHttp 获取http返回结果
func GetTopLinesFromFile ¶
func JsonFormat ¶
func JsonFormat(d interface{}) string
func LoadJsonFromFile ¶
func Max ¶
func Max[V constraints.Number](a V, b ...V) V
func Min ¶
func Min[V constraints.Number](a V, b ...V) V
func MustUnMarshal ¶
func ParseArrToArr ¶
func ParseCustomMapKeyToArr ¶
func ParseCustomMapKeyToArr[K comparable, V any, E any](m map[K]V, parse func(K) E) []E
ParseCustomMapKeyToArr 提取map key为数组
func ParseCustomMapValueToArr ¶
func ParseCustomMapValueToArr[K comparable, V any, E any](m map[K]V, parse func(V) E) []E
ParseCustomMapValueToArr 提取map value为数组
func ParseFloatToStr ¶
func ParseFloatToStr[V constraints.Float](a V) string
func ParseIntToStr ¶
func ParseIntToStr[V constraints.Integer](a V) string
func ParseMapKeyToArr ¶
func ParseMapKeyToArr[K comparable, V any](m map[K]V) []K
ParseMapKeyToArr 提取map key为数组
func ParseMapValueToArr ¶
func ParseMapValueToArr[K comparable, V any](m map[K]V) []V
ParseMapValueToArr 提取map value为数组
func ParseStrToFloat ¶
func ParseStrToFloat[V constraints.Float](str string) V
func ParseStrToInt ¶
func ParseStrToInt[V constraints.Integer](str string) V
func ReadLineFromFile ¶
func ReadLineFromFile[V any](filePath string, skip func(string) bool, deal func(string) V, fn func(index int, line V)) error
ReadLineFromFile 从文件中按行遍历文本
func ReadLineFromFileWithErr ¶
func ReadLineFromFileWithErr[V any](filePath string, skip func(string) bool, deal func(string) V, fn func(index int, line V) error) error
ReadLineFromFileWithErr 从文件中按行遍历文本,快速失败
func ReadLineFromHttp ¶
func ReadLineFromHttp[V any](url string, skip func(string) bool, deal func(string) V, fn func(index int, line V)) error
ReadLineFromHttp 按行遍历http返回结果
func ReadLineParseToArr ¶
func ReadTopLineFromFile ¶
func ReadTopLineFromHttp ¶
func RepeatString ¶
func SortAsc ¶
func SortAsc[T constraints.Ordered](arr []T)
func SortDesc ¶
func SortDesc[T constraints.Ordered](arr []T)
func UnderscoreToCamel ¶
func WriteBytesToFile ¶
func WriteCsvToFile ¶
WriteCsvToFile 写csv格式文件
func WriteLineToFile ¶
WriteLineToFile 按行写文件
func WriteLinesToFile ¶
WriteLinesToFile 按行写文件
Types ¶
type Csv ¶
type Csv struct {
// contains filtered or unexported fields
}
func GetCsvWithTitleFromFile ¶
GetCsvWithTitleFromFile 获取csv格式文件内容
type CustomSet ¶
type CustomSet[V any, K comparable] struct { // contains filtered or unexported fields }
func NewCustomSet ¶
func NewCustomSet[V any, K comparable](cap int, keyFun func(V) K) *CustomSet[V, K]
func (*CustomSet[V, K]) ContainKey ¶
func (*CustomSet[V, K]) GetCustomKeys ¶
func (s *CustomSet[V, K]) GetCustomKeys() []K
type FileWriter ¶
type FileWriter struct {
// contains filtered or unexported fields
}
func NewFileWriter ¶
func NewFileWriter(filePath string, append bool) (*FileWriter, error)
func (*FileWriter) Close ¶
func (f *FileWriter) Close() error
func (*FileWriter) WriteBytes ¶
func (f *FileWriter) WriteBytes(bs []byte) error
func (*FileWriter) WriteLine ¶
func (f *FileWriter) WriteLine(line ...string) error
WriteLine 另起一行(开头除外),保证每个line都是单独的一行
func (*FileWriter) WriteLines ¶
func (f *FileWriter) WriteLines(lines []string) error
WriteLines 另起一行(开头除外),保证每个line都是单独的一行
func (*FileWriter) Writeln ¶
func (f *FileWriter) Writeln(str ...string) error
Writeln 接前文,多个str空格隔开,并且结尾会换行
type HttpReq ¶
func NewHttpReq ¶
NewHttpReq 创建http req
func NewHttpReqByCurl ¶
NewHttpReqByCurl 根据curl创建http req, 必须有-X参数
type QueryStructField ¶
type QueryStructField struct {
Name string
ModelStructName string
Type string
ColumnComment string
}
func (*QueryStructField) Tags ¶
func (m *QueryStructField) Tags() string
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
func NewScanner ¶
func NewScanner(reader io.ReadCloser) *Scanner
func NewScannerFromFile ¶
func NewScannerFromHttp ¶
type Set ¶
type Set[V comparable] struct { // contains filtered or unexported fields }
func NewSet ¶
func NewSet[V comparable](cap int) *Set[V]
type StructFileMeta ¶
type StructFileMeta struct {
Package string
ImportPkgPaths []string
StructMetas []*StructMeta
}
type StructMeta ¶
type StructMeta struct {
TableName string // table name in db server
ModelStructName string // origin/model struct name
StructComment string
Fields []*QueryStructField
}