goutl

package
v1.10.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
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

View Source
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 Curl

func Curl(curl string) (string, error)

Curl 执行curl

func DistinctArr

func DistinctArr[V comparable](arr ...[]V) []V

DistinctArr 数组去重

func DistinctCustomArr

func DistinctCustomArr[V any, C comparable](keyFn func(V) C, arr ...[]V) []V

DistinctCustomArr 数组去重,自定义去重key

func DownloadFromHttp

func DownloadFromHttp(url string, filePath string, bufferSize int) error

DownloadFromHttp 下载http数据

func FileExist

func FileExist(path string) (bool, error)

func FilterArr

func FilterArr[V any](filterFn func(V) bool, arr ...[]V) []V

FilterArr 数组过滤,filterFn为true则保存到输出数组,false则过滤

func GenerateGoFileFromDDL

func GenerateGoFileFromDDL(pkg string, ddlPath string, outPath string) error

func GetAbsolutePath

func GetAbsolutePath(filePath string) string

GetAbsolutePath 获取绝对路径

func GetCsvFromFile

func GetCsvFromFile(filePath string) ([][]string, error)

GetCsvFromFile 获取csv格式文件内容

func GetCsvFromHttp

func GetCsvFromHttp(url string) ([][]string, error)

GetCsvFromHttp 获取csv格式文件内容

func GetFromFile

func GetFromFile(filePath string) ([]byte, error)

GetFromFile 获取文件内容

func GetLinesFromFile

func GetLinesFromFile[V any](filePath string, skip func(string) bool, deal func(string) V) ([]V, error)

GetLinesFromFile 按行获取文件内容

func GetMatrixFromFile

func GetMatrixFromFile(filePath string, sep string) ([][]string, error)

func GetProjectRoot

func GetProjectRoot() string

GetProjectRoot 获取go项目根目录的绝对路径

func GetStringFromFile

func GetStringFromFile(filePath string) (string, error)

GetStringFromFile 获取文件内容

func GetStringFromHttp

func GetStringFromHttp(url string) (string, error)

GetStringFromHttp 获取http返回结果

func GetTopLinesFromFile

func GetTopLinesFromFile[V any](filePath string, top int, skip func(string) bool, deal func(string) V) ([]V, error)

func Json

func Json(v interface{}) string

func JsonFormat

func JsonFormat(d interface{}) string

func LoadJsonFromFile

func LoadJsonFromFile[V any](filePath string) (V, error)

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 MustUnMarshal[V any](json string) V

func ParseArrToArr

func ParseArrToArr[V any, E any](arr []V, parse func(V) E) []E

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 ReadLineParseToArr[V any](arr *[]V) func(i int, line V)

func ReadTopLineFromFile

func ReadTopLineFromFile[V any](filePath string, top int, skip func(string) bool, deal func(string) V, fn func(index int, line V)) error

func ReadTopLineFromFileWithErr

func ReadTopLineFromFileWithErr[V any](filePath string, top int, skip func(string) bool, deal func(string) V, fn func(index int, line V) error) error

func ReadTopLineFromHttp

func ReadTopLineFromHttp[V any](url string, top int, skip func(string) bool, deal func(string) V, fn func(index int, line V)) error

func ReadTopLineFromHttpWithErr

func ReadTopLineFromHttpWithErr[V any](url string, top int, skip func(string) bool, deal func(string) V, fn func(index int, line V) error) error

func RepeatString

func RepeatString(str string, count int) string

func ReverseArr

func ReverseArr[T any](arr []T)

ReverseArr 翻转数组

func ShuffleArr

func ShuffleArr[V any](arr []V) []V

ShuffleArr 数组随机

func Sort

func Sort[T any](arr []T, compare func(a, b T) bool)

func SortAsc

func SortAsc[T constraints.Ordered](arr []T)

func SortDesc

func SortDesc[T constraints.Ordered](arr []T)

func Split

func Split(s, sep string) []string

func Swap

func Swap[T any](arr []T, i, j int)

func UnMarshal

func UnMarshal[V any](json string) (V, error)

func UnderscoreToCamel

func UnderscoreToCamel(str string) string

func WriteBytesToFile

func WriteBytesToFile(filePath string, data []byte) error

func WriteCsvToFile

func WriteCsvToFile(filePath string, content [][]string) error

WriteCsvToFile 写csv格式文件

func WriteLineToFile

func WriteLineToFile(filePath string, line ...string) error

WriteLineToFile 按行写文件

func WriteLinesToFile

func WriteLinesToFile(filePath string, lines []string) error

WriteLinesToFile 按行写文件

func WriteMatrixToFile

func WriteMatrixToFile(filePath string, content [][]string, sep string, byRow bool, fillSep bool) error

WriteMatrixToFile 二维表到文件

func Zero

func Zero[V any]() V

Types

type Csv

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

func GetCsvWithTitleFromFile

func GetCsvWithTitleFromFile(filePath string) (*Csv, error)

GetCsvWithTitleFromFile 获取csv格式文件内容

func (*Csv) Data

func (c *Csv) Data() [][]string

func (*Csv) Foreach

func (c *Csv) Foreach(fn func(index int, row *CsvRow))

func (*Csv) Get

func (c *Csv) Get(index int, title string) string

func (*Csv) GetInt64

func (c *Csv) GetInt64(index int, title string) int64

func (*Csv) GetRow

func (c *Csv) GetRow(index int) *CsvRow

func (*Csv) Len

func (c *Csv) Len() int

type CsvRow

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

func (*CsvRow) Data

func (r *CsvRow) Data() []string

func (*CsvRow) Get

func (r *CsvRow) Get(title string) string

func (*CsvRow) GetInt64

func (r *CsvRow) GetInt64(title string) int64

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]) Add

func (s *CustomSet[V, K]) Add(v V)

func (*CustomSet[V, K]) Contain

func (s *CustomSet[V, K]) Contain(v V) bool

func (*CustomSet[V, K]) ContainKey

func (s *CustomSet[V, K]) ContainKey(k K) bool

func (*CustomSet[V, K]) Foreach

func (s *CustomSet[V, K]) Foreach(fn func(V))

func (*CustomSet[V, K]) GetCustomKeys

func (s *CustomSet[V, K]) GetCustomKeys() []K

func (*CustomSet[V, K]) Remove

func (s *CustomSet[V, K]) Remove(v V)

func (*CustomSet[V, K]) RemoveKey

func (s *CustomSet[V, K]) RemoveKey(k K)

func (*CustomSet[V, K]) Size

func (s *CustomSet[V, K]) Size() int

func (*CustomSet[V, K]) ToArr

func (s *CustomSet[V, K]) ToArr() []V

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) Write

func (f *FileWriter) Write(str ...string) error

Write 接前文,多个str空格隔开

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

type HttpReq struct {
	Request *http.Request
}

func NewHttpReq

func NewHttpReq(method, url string, body interface{}) (*HttpReq, error)

NewHttpReq 创建http req

func NewHttpReqByCurl

func NewHttpReqByCurl(curl string) (*HttpReq, error)

NewHttpReqByCurl 根据curl创建http req, 必须有-X参数

func (*HttpReq) Ask

func (h *HttpReq) Ask() (string, error)

func (*HttpReq) Do

func (h *HttpReq) Do() (*http.Response, error)

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 NewScannerFromFile(filePath string) (*Scanner, error)

func NewScannerFromHttp

func NewScannerFromHttp(url string) (*Scanner, error)

func (*Scanner) Close

func (s *Scanner) Close() error

func (*Scanner) Next

func (s *Scanner) Next() (string, bool)

type Set

type Set[V comparable] struct {
	// contains filtered or unexported fields
}

func NewSet

func NewSet[V comparable](cap int) *Set[V]

func (*Set[V]) Add

func (s *Set[V]) Add(v V)

func (*Set[V]) Combine

func (s *Set[V]) Combine(set *Set[V])

func (*Set[V]) Contain

func (s *Set[V]) Contain(v V) bool

func (*Set[V]) Empty

func (s *Set[V]) Empty() bool

func (*Set[V]) Foreach

func (s *Set[V]) Foreach(fn func(V))

func (*Set[V]) Remove

func (s *Set[V]) Remove(v V)

func (*Set[V]) Size

func (s *Set[V]) Size() int

func (*Set[V]) ToArr

func (s *Set[V]) ToArr() []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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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