Apply .gitignore rules

This commit is contained in:
皮蛋13361098506
2025-01-06 16:21:36 +08:00
parent 1b77f62820
commit ccd2c530cf
580 changed files with 69806 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
package timeUtil
import (
"time"
)
// 把时区转换到UTC时区但时间值不变(去掉时区的影响)
func GetUTCTime(timeVal time.Time) time.Time {
_, offset := timeVal.Zone()
timeVal = timeVal.Add(time.Duration(offset) * time.Second)
timeVal = timeVal.In(time.UTC)
return timeVal
}
// 把时间转换成本地时区,但时间值不变(去掉时区的影响)
func GetLocalTime(timeVal time.Time) time.Time {
// 获取本地时区的时间偏移
tmpVal := time.Now()
_, localOffset := tmpVal.Zone()
// 获取指定时间值的时区偏移
_, timeOffset := timeVal.Zone()
timeVal = timeVal.Add(time.Duration(timeOffset-localOffset) * time.Second)
timeVal = timeVal.In(time.Local)
return timeVal
}
// 增加本地时区的值到指定时间上
func AddLocalTimeZone(timeVal int64) int64 {
// 获取本地时区的时间偏移
tmpVal := time.Now()
_, localOffset := tmpVal.Zone()
return timeVal + int64(localOffset)
}
// 增加本地时区的值到指定时间上
func AddLocalTimeZone2(timeVal time.Time) time.Time {
// 获取本地时区的时间偏移
tmpVal := time.Now()
_, localOffset := tmpVal.Zone()
return timeVal.Add(time.Duration(localOffset) * time.Second)
}
// 减去本地时区到指定时间上
func SubLocalTimeZone(timeVal int64) int64 {
// 获取本地时区的时间偏移
tmpVal := time.Now()
_, localOffset := tmpVal.Zone()
return timeVal + -1*int64(localOffset)
}
// 减去本地时区到指定时间上
func SubLocalTimeZone2(timeVal time.Time) time.Time {
// 获取本地时区的时间偏移
tmpVal := time.Now()
_, localOffset := tmpVal.Zone()
return timeVal.Add(-1 * time.Duration(localOffset) * time.Second)
}

View File

@@ -0,0 +1,61 @@
package mathUtil
import (
"testing"
)
func TestGetSizeDesc(t *testing.T) {
var size int64
var expectedStr string
var finalStr string
size = 1
expectedStr = "1B"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
size *= 1024
expectedStr = "1KB"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
size *= 1024
expectedStr = "1MB"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
size *= 1024
expectedStr = "1.00GB"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
size *= 1024
expectedStr = "1.00TB"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
size *= 1024
expectedStr = "1.00PB"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
size *= 1024
expectedStr = "1.00EB"
finalStr = GetSizeDesc(size)
if finalStr != expectedStr {
t.Errorf("Expected %s, but got %s", expectedStr, finalStr)
}
}

View File

@@ -0,0 +1,36 @@
module logincenter
go 1.22.10
replace (
common => ../common
framework => ../framework
goutil => ../goutil
)
require common v0.0.0-00010101000000-000000000000
require (
filippo.io/edwards25519 v1.1.0 // indirect
framework v0.0.0-20230425160006-b2d0b0a0b0b0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210916085751-c2fb55d91ba4 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/gomodule/redigo v1.8.9 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/jinzhu/gorm v1.9.12 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gorm.io/driver/mysql v1.5.7 // indirect
gorm.io/gorm v1.25.12 // indirect
goutil v0.0.0-20230425160006-b2d0b0a0b0b0 // indirect
)

View File

@@ -0,0 +1,42 @@
package httpServer
import (
"fmt"
"net/http"
"sync"
"goutil/logUtil"
"goutil/logUtilPlus"
// "log"
"net/http/pprof"
config "common/configsYaml"
)
// Start
// @description: 启动服务器
// parameter:
// @wg: WaitGroup对象
// return:
func Start(wg *sync.WaitGroup) {
defer func() {
wg.Done()
}()
// 启动过程中不需要捕获异常
logUtilPlus.PrintAndWriteLog(logUtil.Info, fmt.Sprintf("Web服务器开始监听:%v", config.WebServerAddress))
// 启动Web服务器监听
mux := http.NewServeMux()
mux.Handle("/", &selfDefineMux{})
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
err := http.ListenAndServe(config.WebServerAddress, mux)
if err != nil {
panic(fmt.Errorf("ListenAndServe失败错误信息为%s", err))
}
}

View File

@@ -0,0 +1,16 @@
package stringUtil
import (
"hash/crc32"
)
// HashCode 获取字符串对应的hashCode值
func HashCode(s string) int {
v := int(crc32.ChecksumIEEE([]byte(s)))
if v < 0 {
return -v
}
return v
}

View File

@@ -0,0 +1,38 @@
package securityUtil
import (
"crypto/md5"
"errors"
"fmt"
)
// 对字符串进行MD5加密并且可以选择返回大、小写
// s:输入字符串
// ifUpper:输出是否大写
// 返回值md5加密后的字符串
func Md5String(s string, ifUpper bool) string {
if len(s) == 0 {
panic(errors.New("input string can't be empty"))
}
return Md5Bytes([]byte(s), ifUpper)
}
// 对字符数组进行MD5加密并且可以选择返回大、小写
// b:输入字符数组
// ifUpper:输出是否大写
// 返回值md5加密后的字符串
func Md5Bytes(b []byte, ifUpper bool) string {
if len(b) == 0 {
panic(errors.New("input []byte can't be empty"))
}
md5Instance := md5.New()
md5Instance.Write(b)
result := md5Instance.Sum([]byte(""))
if ifUpper {
return fmt.Sprintf("%X", result)
} else {
return fmt.Sprintf("%x", result)
}
}