tools

package
v0.0.0-...-2aceef8 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Overview

stringutil 包含有用于处理字符串的工具函数。

Index

Constants

View Source
const SECRET = "taoshihan"

Variables

View Source
var LimitQueue = &LimitQueeMap{
	LimitQueue: make(map[string][]int64),
}

Functions

func Base64Decode

func Base64Decode(str string) string

func BinarySearch

func BinarySearch(nums []int, target int) int

func BubbleSort

func BubbleSort(arr *[]int)

冒泡排序 比较相邻元素,较大的往右移

func FileGetContent

func FileGetContent(file string) string

获取文件内容,可以打包到二进制

func Get

func Get(url string) string

func GetCookie

func GetCookie(r *http.Request, name string) string

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

获取出站IP地址

func GetServerIP

func GetServerIP() (net.IP, error)

func GetUrlArg

func GetUrlArg(r *http.Request, name string) string

获取URL的GET参数

func HTTPGet

func HTTPGet(uri string) ([]byte, error)

HTTPGet get 请求

func HTTPGetContext

func HTTPGetContext(ctx context.Context, uri string) ([]byte, error)

HTTPGetContext get 请求

func HTTPPost

func HTTPPost(uri string, data string) ([]byte, error)

HTTPPost post 请求

func HTTPPostContext

func HTTPPostContext(ctx context.Context, uri string, data string) ([]byte, error)

HTTPPostContext post 请求

func InsertionSort

func InsertionSort(arr *[]int)

插入排序 将未排序部分插入到已排序部分的适当位置

func Int2Str

func Int2Str(i interface{}) string

func IsFileExist

func IsFileExist(path string) (bool, error)

判断文件文件夹是否存在(字节0也算不存在)

func IsFileNotExist

func IsFileNotExist(path string) (bool, error)

判断文件文件夹不存在

func IsMobile

func IsMobile(userAgent string) bool

func LeftBound

func LeftBound(nums []int, target int) int

func LeftBound2

func LeftBound2(nums []int, target int) int

func LimitFreqSingle

func LimitFreqSingle(queueName string, count uint, timeWindow int64) bool

单机时间滑动窗口限流法

func Logger

func Logger() *logrus.Logger

func MakeToken

func MakeToken(obj map[string]interface{}) (string, error)

func Md5

func Md5(src string) string

md5加密

func MergeSort

func MergeSort(arr *[]int, left int, right int)

归并排序 合久必分,分久必合,利用临时数组合并两个有序数组

func MyPointer

func MyPointer()

func MyStruct

func MyStruct()

func MyTest

func MyTest()

func NewLimitQueue

func NewLimitQueue()

func NilChannel

func NilChannel()

func ParseIp

func ParseIp(myip string) *ipdb.CityInfo

func ParseToken

func ParseToken(tokenStr string) map[string]interface{}

func Post

func Post(url string, contentType string, body []byte) (string, error)

Post("http://xxxx","application/json;charset=utf-8",[]byte("{'aaa':'bbb'}"))

func PostFile

func PostFile(fieldname, filename, uri string) ([]byte, error)

PostFile 上传文件

func PostForm

func PostForm(url string, data url.Values) (string, error)

发送http post请求数据为form

func PostHeader

func PostHeader(url string, msg []byte, headers map[string]string) (string, error)

func PostJSON

func PostJSON(uri string, obj interface{}) ([]byte, error)

PostJSON post json 数据请求

func PostJSONWithRespContentType

func PostJSONWithRespContentType(uri string, obj interface{}) ([]byte, string, error)

PostJSONWithRespContentType post json数据请求,且返回数据类型

func PostMultipartForm

func PostMultipartForm(fields []MultipartFormField, uri string) (respBody []byte, err error)

PostMultipartForm 上传文件或其他多个字段

func PostXML

func PostXML(uri string, obj interface{}) ([]byte, error)

PostXML perform a HTTP/POST request with XML body

func QuickSort

func QuickSort(arr *[]int, left int, right int)

递归

func QuickSort2

func QuickSort2(arr *[]int, left int, right int)

快速排序2 找到一个基准,左边是所有比它小的,右边是比它大的,分别递归左右

func RedirectStderr

func RedirectStderr(f *os.File)

redirectStderr to the file passed in

func Reverse

func Reverse(s string) string

Reverse 将其实参字符串以符文为单位左右反转。

func Reverse2

func Reverse2(s string) string

Reverse2 将其实参字符串以符文为单位左右反转。

func RightBound

func RightBound(nums []int, target int) int

func SelectionSort

func SelectionSort(arr *[]int)

选择排序 选择一个最小值,再寻找比它还小的进行交换

func SendSmtp

func SendSmtp(server string, from string, password string, to []string, subject string, body string) error

func Session

func Session(keyPairs string) gin.HandlerFunc

中间件,处理session

func SessionConfig

func SessionConfig() sessions.Store

func SetCookie

func SetCookie(name string, value string, w *http.ResponseWriter)

func Sha256

func Sha256(src string) string

Sha256加密

func ShowStringByte

func ShowStringByte(str string)

func SortMap

func SortMap(youMap map[string]interface{}) []interface{}

func Uuid

func Uuid() string

Types

type ImportSqlTool

type ImportSqlTool struct {
	SqlPath                                    string
	Username, Password, Server, Port, Database string
}

func (*ImportSqlTool) ImportSql

func (this *ImportSqlTool) ImportSql() error

type IndexData

type IndexData struct {
	ViewHtml
	Folders           map[string]int
	Mails             interface{}
	MailPagelist      []*MailItem
	CurrentPage       int
	Fid               string
	NextPage, PrePage string
	NumPages          template.HTML
}

type JsonListResult

type JsonListResult struct {
	JsonResult
	Result interface{} `json:"result"`
}

type JsonResult

type JsonResult struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
}

type LimitQueeMap

type LimitQueeMap struct {
	sync.RWMutex
	LimitQueue map[string][]int64
}

type ListNode

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

单链表节点的结构

func NewListNode

func NewListNode(x int) *ListNode

func ReverseBetween

func ReverseBetween(head *ListNode, m int, n int) *ListNode

func ReverseKGroup

func ReverseKGroup(head *ListNode, k int) *ListNode

func ReverseList

func ReverseList(head *ListNode) *ListNode

func ReverseListN

func ReverseListN(head *ListNode, n int) *ListNode

将链表的前 n 个节点反转(n <= 链表长度)

func ReverseSingleList

func ReverseSingleList(a *ListNode, b *ListNode) *ListNode

* 反转区间 [a, b) 的元素,注意是左闭右开

type MailItem

type MailItem struct {
	Subject string
	Fid     string
	Id      uint32
	From    string
	To      string
	Body    string
	Date    string
}

type MailPageList

type MailPageList struct {
	MailItems []*MailItem
}

type MailServer

type MailServer struct {
	Server, Email, Password string
}

func GetMailServerFromCookie

func GetMailServerFromCookie(r *http.Request) *MailServer

type MultipartFormField

type MultipartFormField struct {
	IsFile    bool
	Fieldname string
	Value     []byte
	Filename  string
}

MultipartFormField 保存文件或其他字段信息

type SmtpBody

type SmtpBody struct {
	Smtp     string
	From     string
	To       []string
	Password string
	Subject  string
	Body     string
}

type Snowflake

type Snowflake struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A Snowflake struct holds the basic information needed for a snowflake generator worker

func NewSnowflake

func NewSnowflake(workerid int64) (*Snowflake, error)

NewNode returns a new snowflake worker that can be used to generate snowflake IDs

func (*Snowflake) Generate

func (s *Snowflake) Generate() int64

Generate creates and returns a unique snowflake ID

type ViewData

type ViewData struct {
	Folders  map[string]int
	HtmlBody template.HTML
	MailItem
}

type ViewHtml

type ViewHtml struct {
	Header template.HTML
	Nav    template.HTML
}

Jump to

Keyboard shortcuts

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