From 96696392250a8ca5754fe663a37136d8e7f8d5b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Thu, 30 Mar 2023 10:22:46 +0800 Subject: [PATCH] - update log - update storage --- CHANGELOG.md | 5 ++ go.mod | 1 + go.sum | 3 +- library.go | 2 +- utils/golog/gin.custom.go | 3 + utils/gostorage/aliyun.go | 155 +++----------------------------------- vendor/modules.txt | 2 + 7 files changed, 23 insertions(+), 148 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fd8cac..16e0cfc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v1.0.115 + +- update [golog](utils%2Fgolog) +- update [gostorage](utils%2Fgostorage) + ## v1.0.114 - update [golog](utils%2Fgolog) diff --git a/go.mod b/go.mod index e644ae33..5bff73d2 100644 --- a/go.mod +++ b/go.mod @@ -48,6 +48,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/clbanning/mxj v1.8.4 // indirect + github.com/clbanning/mxj/v2 v2.5.7 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/fatih/color v1.15.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect diff --git a/go.sum b/go.sum index f9e166dc..84bf97b6 100644 --- a/go.sum +++ b/go.sum @@ -59,8 +59,9 @@ github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhD github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk= github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I= github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng= -github.com/clbanning/mxj/v2 v2.5.5 h1:oT81vUeEiQQ/DcHbzSytRngP6Ky9O+L+0Bw0zSJag9E= github.com/clbanning/mxj/v2 v2.5.5/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= +github.com/clbanning/mxj/v2 v2.5.7 h1:7q5lvUpaPF/WOkqgIDiwjBJaznaLCCBd78pi8ZyAnE0= +github.com/clbanning/mxj/v2 v2.5.7/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s= github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= diff --git a/library.go b/library.go index 5a91a1d8..de486a8d 100644 --- a/library.go +++ b/library.go @@ -1,5 +1,5 @@ package go_library func Version() string { - return "1.0.114" + return "1.0.115" } diff --git a/utils/golog/gin.custom.go b/utils/golog/gin.custom.go index 51a44660..77e68f7d 100644 --- a/utils/golog/gin.custom.go +++ b/utils/golog/gin.custom.go @@ -28,6 +28,7 @@ type GinCustomClient struct { type ConfigGinCustomClient struct { IpService *goip.Client // ip服务 GormClientFun dorm.GormClientTableFun // 日志配置 + CurrentIp string // 当前ip } func NewGinCustomClient(config *ConfigGinCustomClient) (*GinCustomClient, error) { @@ -36,6 +37,8 @@ func NewGinCustomClient(config *ConfigGinCustomClient) (*GinCustomClient, error) c := &GinCustomClient{} + c.config.systemOutsideIp = config.CurrentIp + c.config.systemOutsideIp = goip.IsIp(c.config.systemOutsideIp) if c.config.systemOutsideIp == "" { return nil, currentIpNoConfig diff --git a/utils/gostorage/aliyun.go b/utils/gostorage/aliyun.go index 22ded5fe..2a4e06cb 100644 --- a/utils/gostorage/aliyun.go +++ b/utils/gostorage/aliyun.go @@ -4,46 +4,25 @@ import ( "errors" "github.com/aliyun/aliyun-oss-go-sdk/oss" "io" - "sync" ) // AliYunConfig 阿里云配置 type AliYunConfig struct { - AccessKeyId string // 账号信息 - AccessKeySecret string // 账号信息 - Endpoint string // 地域节点 外网访问 test3 - EndpointEcs string // 地域节点 ECS 的经典网络访问(内网) test1 - EndpointAccelerate string // 地域节点 传输加速域名(全地域上传下载加速 test4 - BucketName string // 存储空间名称 + AccessKeyId string // 账号信息 + AccessKeySecret string // 账号信息 + Endpoint string // 地域节点 + BucketName string // 存储空间名称 } // AliYun 阿里云 type AliYun struct { accessKeyId string // 账号信息 accessKeySecret string // 账号信息 - bucketName string // 存储空间名称 endpoint string // 地域节点 + bucketName string // 存储空间名称 error error // 错误信息 client *oss.Client // 驱动 bucket *oss.Bucket // 存储空间 - endpointEcsInfo struct { - error error // 错误信息 - endpoint string // 地域节点 - client *oss.Client // 驱动 - bucket *oss.Bucket // 存储空间 - } // 外网访问 - endpointInfo struct { - error error // 错误信息 - endpoint string // 地域节点 - client *oss.Client // 驱动 - bucket *oss.Bucket // 存储空间 - } // 内网访问 - endpointAccelerateInfo struct { - error error // 错误信息 - endpoint string // 地域节点 - client *oss.Client // 驱动 - bucket *oss.Bucket // 存储空间 - } // 传输加速域名访问 } // NewAliYun 初始化 @@ -53,133 +32,17 @@ func NewAliYun(config *AliYunConfig) (*AliYun, error) { app := &AliYun{} app.accessKeyId = config.AccessKeyId app.accessKeySecret = config.AccessKeySecret + app.endpoint = config.Endpoint app.bucketName = config.BucketName - app.endpointEcsInfo.endpoint = config.Endpoint - app.endpointInfo.endpoint = config.EndpointEcs - app.endpointAccelerateInfo.endpoint = config.EndpointAccelerate - - wg := sync.WaitGroup{} - wg.Add(3) - go app.configEndpointEcs(&wg) - go app.configEndpoint(&wg) - go app.configEndpointAccelerate(&wg) - wg.Wait() - // 判断结果 - if app.endpointEcsInfo.error == nil { - app.endpoint = app.endpointEcsInfo.endpoint - app.client = app.endpointEcsInfo.client - app.bucket = app.endpointEcsInfo.bucket - return app, nil - } - if app.endpointInfo.error == nil { - app.endpoint = app.endpointInfo.endpoint - app.client = app.endpointInfo.client - app.bucket = app.endpointInfo.bucket - return app, nil - } - if app.endpointAccelerateInfo.error == nil { - app.endpoint = app.endpointAccelerateInfo.endpoint - app.client = app.endpointAccelerateInfo.client - app.bucket = app.endpointAccelerateInfo.bucket - return app, nil + app.client, app.error = oss.New(app.endpoint, app.accessKeyId, app.accessKeySecret) + if app.error != nil { + return nil, app.error } return app, errors.New("链接失败") } -func (c *AliYun) configEndpoint(wg *sync.WaitGroup) { - defer wg.Done() - - if c.endpointInfo.endpoint == "" { - c.endpointInfo.error = errors.New("没有配置") - return - } - - // 创建链接 - c.endpointInfo.client, c.endpointInfo.error = oss.New(c.endpointInfo.endpoint, c.accessKeyId, c.accessKeySecret) - if c.endpointInfo.error != nil { - return - } - - // 填写存储空间名称 - c.endpointInfo.bucket, c.endpointInfo.error = c.endpointInfo.client.Bucket(c.bucketName) - if c.endpointInfo.error != nil { - return - } - - // 判断存储空间是否存在 - _, c.endpointInfo.error = c.endpointInfo.client.IsBucketExist(c.bucketName) - if c.endpointInfo.error != nil { - return - } - - c.endpointInfo.error = nil - return -} - -func (c *AliYun) configEndpointEcs(wg *sync.WaitGroup) { - defer wg.Done() - - if c.endpointEcsInfo.endpoint == "" { - c.endpointEcsInfo.error = errors.New("没有配置") - return - } - - // 创建链接 - c.endpointEcsInfo.client, c.endpointEcsInfo.error = oss.New(c.endpointEcsInfo.endpoint, c.accessKeyId, c.accessKeySecret) - if c.endpointEcsInfo.error != nil { - return - } - - // 填写存储空间名称 - c.endpointEcsInfo.bucket, c.endpointEcsInfo.error = c.endpointEcsInfo.client.Bucket(c.bucketName) - if c.endpointEcsInfo.error != nil { - return - } - - // 判断存储空间是否存在 - _, c.endpointEcsInfo.error = c.endpointEcsInfo.client.IsBucketExist(c.bucketName) - if c.endpointEcsInfo.error != nil { - return - } - - c.endpointEcsInfo.error = nil - - return -} - -func (c *AliYun) configEndpointAccelerate(wg *sync.WaitGroup) { - defer wg.Done() - - if c.endpointAccelerateInfo.endpoint == "" { - c.endpointAccelerateInfo.error = errors.New("没有配置") - return - } - - // 创建链接 - c.endpointAccelerateInfo.client, c.endpointAccelerateInfo.error = oss.New(c.endpointAccelerateInfo.endpoint, c.accessKeyId, c.accessKeySecret) - if c.endpointAccelerateInfo.error != nil { - return - } - - // 填写存储空间名称 - c.endpointAccelerateInfo.bucket, c.endpointAccelerateInfo.error = c.endpointAccelerateInfo.client.Bucket(c.bucketName) - if c.endpointAccelerateInfo.error != nil { - return - } - - // 判断存储空间是否存在 - _, c.endpointAccelerateInfo.error = c.endpointAccelerateInfo.client.IsBucketExist(c.bucketName) - if c.endpointAccelerateInfo.error != nil { - return - } - - c.endpointAccelerateInfo.error = nil - - return -} - // PutObject 上传文件流 // @param file 文件流 // @param filePath 文件路径 diff --git a/vendor/modules.txt b/vendor/modules.txt index f98ba472..a0675645 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -54,6 +54,8 @@ github.com/chenzhuoyu/base64x # github.com/clbanning/mxj v1.8.4 ## explicit github.com/clbanning/mxj +# github.com/clbanning/mxj/v2 v2.5.7 +## explicit; go 1.15 # github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f ## explicit github.com/dgryski/go-rendezvous