2023-12-21 22:17:40 +08:00
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/aliyun/aliyun-oss-go-sdk/oss"
|
|
|
|
|
"github.com/bwmarrin/snowflake"
|
2023-12-24 13:24:01 +08:00
|
|
|
|
"net"
|
2023-12-21 22:17:40 +08:00
|
|
|
|
"os"
|
2024-04-15 15:17:30 +08:00
|
|
|
|
"service/bizcommon/util"
|
2023-12-21 22:17:40 +08:00
|
|
|
|
"service/library/configcenter"
|
|
|
|
|
"service/library/redis"
|
|
|
|
|
"strconv"
|
2023-12-24 13:24:01 +08:00
|
|
|
|
"strings"
|
2023-12-21 22:17:40 +08:00
|
|
|
|
)
|
|
|
|
|
|
2024-04-15 15:17:30 +08:00
|
|
|
|
type A struct {
|
|
|
|
|
Mid int `json:"mid"`
|
|
|
|
|
}
|
|
|
|
|
type B struct {
|
|
|
|
|
Mid int `json:"mid"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type C struct {
|
|
|
|
|
*A `json:"*_a"`
|
|
|
|
|
*B
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-21 22:17:40 +08:00
|
|
|
|
func main() {
|
2024-04-15 15:17:30 +08:00
|
|
|
|
c := C{
|
|
|
|
|
A: &A{Mid: 111},
|
|
|
|
|
B: &B{Mid: 222},
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(util.ToJson(c))
|
|
|
|
|
return
|
|
|
|
|
|
2023-12-21 22:17:40 +08:00
|
|
|
|
//fmt.Println(util.StringToMd5(""))
|
|
|
|
|
|
|
|
|
|
i, _ := strconv.ParseInt("1734551562589581312"[:13], 10, 64)
|
|
|
|
|
fmt.Println(i)
|
|
|
|
|
|
|
|
|
|
n, _ := snowflake.NewNode(6)
|
|
|
|
|
fmt.Println(n.Generate().Time())
|
2023-12-24 13:24:01 +08:00
|
|
|
|
|
|
|
|
|
fmt.Println(GetIp())
|
2023-12-21 22:17:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-24 13:24:01 +08:00
|
|
|
|
func GetIp() string {
|
|
|
|
|
addrs, err := net.InterfaceAddrs()
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println(err)
|
|
|
|
|
return "127.0.0.1"
|
|
|
|
|
}
|
|
|
|
|
retIp := ""
|
|
|
|
|
for _, address := range addrs {
|
|
|
|
|
// 检查ip地址判断是否回环地址
|
|
|
|
|
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
|
|
|
|
if ipnet.IP.To4() != nil {
|
|
|
|
|
ip := ipnet.IP.String()
|
|
|
|
|
if strings.HasPrefix(ip, "172.") {
|
|
|
|
|
retIp = ip
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retIp
|
|
|
|
|
}
|
2023-12-21 22:17:40 +08:00
|
|
|
|
func UploadImage() {
|
|
|
|
|
// yourEndpoint填写Bucket对应的Endpoint,以华东1(杭州)为例,填写为https://oss-cn-hangzhou.aliyuncs.com。其它Region请按实际情况填写。
|
|
|
|
|
// yourAccessKeyId以及yourAccessKeySecret分别填写从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
|
|
|
|
|
// yourSecurityToken填写从STS服务获取的安全令牌(SecurityToken)。
|
|
|
|
|
client, err := oss.New(
|
|
|
|
|
"https://oss-cn-beijing.aliyuncs.com",
|
|
|
|
|
"LTAI5tAkZof9AYoVzRGirqjo",
|
|
|
|
|
"dcSV0hceaoes3Xb5gCWfrrV8hvjAMj",
|
|
|
|
|
)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
|
os.Exit(-1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 填写存储空间名称,例如examplebucket。
|
|
|
|
|
bucket, err := client.Bucket("wishpal-media")
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
|
os.Exit(-1)
|
|
|
|
|
}
|
|
|
|
|
fmt.Println(bucket.BucketName)
|
|
|
|
|
|
|
|
|
|
// put
|
|
|
|
|
absPath := "/Users/erwin/Desktop/banner.png"
|
|
|
|
|
//bytes, err := ioutil.ReadFile(absPath)
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// fmt.Println("Error:", err)
|
|
|
|
|
// os.Exit(-1)
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
key := "test/raw/banner"
|
|
|
|
|
err = bucket.PutObjectFromFile(key, absPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
|
os.Exit(-1)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func ConnRedis() {
|
|
|
|
|
cfg := &configcenter.RedisConfig{
|
|
|
|
|
Uri: "",
|
|
|
|
|
Password: "",
|
|
|
|
|
MaxActive: 0,
|
|
|
|
|
MaxIdle: 0,
|
|
|
|
|
IdleTimeout: 0,
|
|
|
|
|
Prefix: "tttaaa",
|
|
|
|
|
}
|
|
|
|
|
cli, err := redis.NewRedisClient(cfg)
|
|
|
|
|
if err != nil {
|
|
|
|
|
fmt.Printf("err: %v", err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
cli.Set("jack", "1", 60*5)
|
|
|
|
|
}
|