add function comments

This commit is contained in:
iyear 2021-06-14 22:12:18 +08:00
parent d82ace223b
commit dd5f3fa3ba

View File

@ -8,11 +8,10 @@ import (
"log"
"net/url"
"os"
"strings"
"time"
)
//true=>no error
// Min true=>no error
func Min(x, y int) int {
if x < y {
return x
@ -38,21 +37,6 @@ func PathExists(path string) bool {
}
return false
}
func GetBetweenStr(str, start, end string) string {
n := strings.Index(str, start)
if n == -1 {
n = 0
} else {
n = n + len(start)
}
str = string([]byte(str)[n:])
m := strings.Index(str, end)
if m == -1 {
m = len(str)
}
str = string([]byte(str)[:m])
return str
}
func GetURLValue(Url, key string) string {
u, _ := url.Parse(Url)
query := u.Query()
@ -60,19 +44,17 @@ func GetURLValue(Url, key string) string {
return query.Get(key)
}
//返回一个32位md5加密后的字符串
func GetMD5Encode(data string) string {
h := md5.New()
h.Write([]byte(data))
return hex.EncodeToString(h.Sum(nil))
}
//返回一个16位md5加密后的字符串
func Get16MD5Encode(data string) string {
return GetMD5Encode(data)[8:24]
}
//只返回文件名
// GetPathFiles only return file name
func GetPathFiles(path string) []string {
files, _ := ioutil.ReadDir(path)
var t []string
@ -86,7 +68,7 @@ func GetPathFiles(path string) []string {
return t
}
//输入文件夹路径返回最近n个log的路径不到n个返回所有
// GetRecentLogs 输入文件夹路径返回最近n个log的路径不到n个返回所有
func GetRecentLogs(path string, n int) []string {
var paths []string
if !PathExists(path) {
@ -110,3 +92,9 @@ func GetRecentLogs(path string, n int) []string {
}
return paths
}
func IF(f bool, a interface{}, b interface{}) interface{} {
if f {
return a
}
return b
}