first commit

This commit is contained in:
Blizzard
2026-02-27 13:54:01 +08:00
commit fc585fa4df
127 changed files with 18548 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
package utils
import (
"fmt"
"log"
"sundynix-go/utils/location"
"sundynix-go/utils/timer"
"sundynix-go/utils/uniqueid"
"testing"
"time"
)
func TestHashPwd(t *testing.T) {
hash := BcryptHash("sundynix")
fmt.Println(hash) // $2a$10$QC/zkQ/ohPmvjF/goDyicu7cHgAEj8gHg6OTDHWhbYQMHHn4dwxX2
//check := BcryptCheck("sundynix", "$2a$10$QC/zkQ/ohPmvjF/goDyicu7cHgAEj8gHg6OTDHWhbYQMHHn4dwxX2")
//fmt.Println(check)
}
func TestUuid(t *testing.T) {
id := uniqueid.GenerateId()
fmt.Println(id)
}
func TestTimePeriod(t *testing.T) {
str := "2025-11-19 10:29:20.597"
parse, _ := time.ParseInLocation("2006-01-02 15:04:05.999999999", str, time.Local)
interval := timer.TimeInterval(parse)
fmt.Println(interval)
}
func TestPoint2Code(t *testing.T) {
//latitude := float32(39.90882)
//longitude := float32(116.39748)
longitude := float32(102.74837)
latitude := float32(25.02847)
// 调用逆地理编码
entity, err := location.Point2code(longitude, latitude)
if err != nil {
log.Fatalf("获取地址失败: %v", err)
}
// 打印结果
// 打印结果
fmt.Println("=== 解析结果 ===")
fmt.Println("格式化地址:", entity.Address)
fmt.Println("省份:", entity.AddressComponent.Province.String())
fmt.Println("城市:", entity.AddressComponent.City.String())
fmt.Println("区县:", entity.AddressComponent.District.String())
fmt.Println("乡镇:", entity.AddressComponent.Township)
fmt.Println("街道:", entity.AddressComponent.Street)
fmt.Println("门牌号:", entity.AddressComponent.StreetNumber.Number)
fmt.Println("门牌号所属街道:", entity.AddressComponent.StreetNumber.Street)
fmt.Println("行政区划编码:", entity.AddressComponent.Adcode)
fmt.Println("国家:", entity.AddressComponent.Country)
}
func TestWeather(t *testing.T) {
adcode := "532325"
// 可选:extensions="all" 查询实时+未来3天预报
weatherResp, err := location.GetWeather(adcode, "base")
if err != nil {
log.Fatalf("查询天气失败: %v", err)
}
// 打印实时天气
fmt.Println("=== 实时天气 ===")
live := weatherResp.Lives[0] // 实时天气数组仅1条数据
fmt.Printf("省份:%s\n", live.Province)
fmt.Printf("城市:%s\n", live.City)
fmt.Printf("行政区划编码:%s\n", live.Adcode)
fmt.Printf("天气:%s\n", live.Weather)
fmt.Printf("实时气温:%s℃\n", live.Temperature)
fmt.Printf("风向:%s\n", live.WindDirection)
fmt.Printf("风力:%s级\n", live.WindPower)
fmt.Printf("湿度:%s%%\n", live.Humidity)
fmt.Printf("数据更新时间:%s\n", live.ReportTime)
// 若查询的是all(实时+预报),打印预报数据
// if len(weatherResp.Forecasts) > 0 {
// fmt.Println("\n=== 未来3天预报 ===")
// forecast := weatherResp.Forecasts[0]
// for _, day := range forecast.Casts {
// fmt.Printf("\n日期:%s(星期%s\n", day.Date, day.Week)
// fmt.Printf("白天天气:%s,温度:%s℃\n", day.DayWeather, day.DayTemp)
// fmt.Printf("夜间天气:%s,温度:%s℃\n", day.NightWeather, day.NightTemp)
// fmt.Printf("白天风向/风力:%s/%s级\n", day.DayWindDir, day.DayWindPower)
// }
// }
}
func TestGenOrderNo(t *testing.T) {
no := uniqueid.GenOrderNo()
fmt.Println(no)
}
func TestTime(t *testing.T) {
milliTimestamp := time.Now().UnixMilli()
microTimestamp := time.Now().UnixMicro()
fmt.Printf("毫秒级时间戳: %d\n", milliTimestamp)
fmt.Printf("微秒级时间戳: %d\n", microTimestamp)
}
func TestGetZeroTime(t *testing.T) {
zeroTime := timer.GetZeroTime()
fmt.Printf("当天零点: %v\n", zeroTime)
fmt.Printf("时间戳(秒): %v\n", zeroTime.Unix())
}