Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
so-operation-api
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
smart-operation
so-operation-api
Commits
7d952a14
Commit
7d952a14
authored
Jul 02, 2023
by
陈子龙
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
状态检测解析minio文件流 fix
parent
0e3f88f5
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
88 additions
and
8 deletions
+88
-8
go.mod
go.mod
+2
-0
go.sum
go.sum
+3
-0
src/bean/vo/request/host_manage.go
src/bean/vo/request/host_manage.go
+4
-4
src/controller/host_manage.go
src/controller/host_manage.go
+49
-1
src/main.go
src/main.go
+1
-1
src/router/router.go
src/router/router.go
+1
-1
src/service/doc_lib.go
src/service/doc_lib.go
+28
-1
No files found.
go.mod
View file @
7d952a14
...
@@ -6,6 +6,7 @@ require (
...
@@ -6,6 +6,7 @@ require (
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/360EntSecGroup-Skylar/excelize v1.4.1
github.com/Luzifer/go-openssl/v4 v4.1.0
github.com/Luzifer/go-openssl/v4 v4.1.0
github.com/bytedance/go-tagexpr v2.7.4+incompatible
github.com/bytedance/go-tagexpr v2.7.4+incompatible
github.com/ghodss/yaml v1.0.0
github.com/gin-gonic/gin v1.9.0
github.com/gin-gonic/gin v1.9.0
github.com/go-playground/locales v0.14.1
github.com/go-playground/locales v0.14.1
github.com/go-playground/universal-translator v0.18.1
github.com/go-playground/universal-translator v0.18.1
...
@@ -72,6 +73,7 @@ require (
...
@@ -72,6 +73,7 @@ require (
golang.org/x/text v0.9.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
...
...
go.sum
View file @
7d952a14
...
@@ -81,6 +81,7 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB
...
@@ -81,6 +81,7 @@ github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVB
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
...
@@ -650,6 +651,8 @@ gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRN
...
@@ -650,6 +651,8 @@ gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRN
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
...
...
src/bean/vo/request/host_manage.go
View file @
7d952a14
...
@@ -36,10 +36,10 @@ type ListHostManageReq struct {
...
@@ -36,10 +36,10 @@ type ListHostManageReq struct {
// StateHostManageReq 状态检测
// StateHostManageReq 状态检测
type
StateHostManageReq
struct
{
type
StateHostManageReq
struct
{
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2 3"`
//1主页列表手动检测 2输入ip列表保存时检测 3上传ip列表文件保存时检测
DetectionType
int
`json:"detection_type" form:"detection_type" binding:"oneof=1 2 3"`
//1主页列表手动检测 2输入ip列表保存时检测 3上传ip列表文件保存时检测
Id
int
`json:"id" form:"id"`
//主机分组ID
Id
int
`json:"id" form:"id"`
//主机分组ID
//HostFile file `form:"host_file"` // 主机文件
HostManageList
string
`json:"host_manage_list" form:"host_manage_list"`
//主机ip列表
HostManageList
string
`json:"host_manage_list" form:"host_manage_list"`
//主机ip列表
FileName
string
`json:"file_name" form:"file_name"`
//文件名称
}
}
// HostIpExceptionListReq 异常列表
// HostIpExceptionListReq 异常列表
...
...
src/controller/host_manage.go
View file @
7d952a14
...
@@ -57,6 +57,52 @@ func ParsingHostFiles(c *gin.Context) (hostManageList []request.HostManageList,
...
@@ -57,6 +57,52 @@ func ParsingHostFiles(c *gin.Context) (hostManageList []request.HostManageList,
return
return
}
}
// GetMinioFiles 解析minio中xlsx类型文件
func
GetMinioFiles
(
fileName
string
)
(
hostManageList
[]
request
.
HostManageList
,
err
error
)
{
obj
,
err
:=
service
.
DocLibSvc
{}
.
GetFile
(
fileName
)
if
err
!=
nil
{
err
=
resp
.
GetFileStreamError
.
WithError
(
err
)
return
}
xlsxData
,
err
:=
excelize
.
OpenReader
(
obj
)
if
err
!=
nil
{
err
=
resp
.
ReadFileError
.
WithError
(
err
)
return
}
//读取工作簿
rows
:=
xlsxData
.
GetRows
(
"Sheet1"
)
if
len
(
rows
)
>
1001
{
err
=
resp
.
FailedToParseFile
.
WithError
(
errors
.
New
(
"ip数量不可超过1000"
))
return
}
for
i
:=
0
;
i
<
len
(
rows
);
i
++
{
//默认跳过第一行
if
i
<
1
{
continue
}
var
voucherType
int
if
rows
[
i
][
2
]
==
"密码验证"
{
voucherType
=
0
}
else
{
voucherType
=
1
}
hostManageList
=
append
(
hostManageList
,
request
.
HostManageList
{
Ip
:
rows
[
i
][
0
],
Port
:
rows
[
i
][
1
],
VoucherType
:
voucherType
,
UserName
:
rows
[
i
][
3
],
Password
:
rows
[
i
][
4
],
})
}
return
}
// AddHostManage 新增
// AddHostManage 新增
func
AddHostManage
(
c
*
gin
.
Context
)
{
func
AddHostManage
(
c
*
gin
.
Context
)
{
var
(
var
(
...
@@ -237,7 +283,9 @@ func StateHostManage(c *gin.Context) {
...
@@ -237,7 +283,9 @@ func StateHostManage(c *gin.Context) {
}
}
case
3
:
case
3
:
//解析主机文件
//解析主机文件
hostManageList
,
err
=
ParsingHostFiles
(
c
)
//hostManageList, err = ParsingHostFiles(c)
hostManageList
,
err
=
GetMinioFiles
(
req
.
FileName
)
if
err
!=
nil
{
if
err
!=
nil
{
SendJsonResponse
(
c
,
resp
.
ReadFileError
.
WithError
(
errors
.
New
(
"解析主机文件失败"
)),
nil
)
SendJsonResponse
(
c
,
resp
.
ReadFileError
.
WithError
(
errors
.
New
(
"解析主机文件失败"
)),
nil
)
return
return
...
...
src/main.go
View file @
7d952a14
...
@@ -60,7 +60,7 @@ func initConfig() {
...
@@ -60,7 +60,7 @@ func initConfig() {
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
LogMode
:
util
.
SetEnvInt
(
"LOG_MODE"
,
1
),
// 1.标准打印 2.输出文件
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgBool
:
util
.
SetEnvBool
(
"ARG_BOOL"
,
false
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
ArgInt
:
util
.
SetEnvInt
(
"ARG_INT"
,
10
),
// 示例参数
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"
cache.wodcloud.com"
),
// Minio 服务地址
MinioServer
:
util
.
SetEnvStr
(
"MINIO_SERVER"
,
"
https://cache.wodcloud.com"
),
// Minio 服务地址
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioAccessKey
:
util
.
SetEnvStr
(
"MINIO_ACCESS_KEY"
,
"beagleadmin"
),
// Minio Access Key
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioSecretKey
:
util
.
SetEnvStr
(
"MINIO_SECRET_KEY"
,
"H76cPmwvH7vJ"
),
// Minio Secret
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
MinioBucket
:
util
.
SetEnvStr
(
"MINIO_BUCKET"
,
"so-operation"
),
// Minio Bucket
...
...
src/router/router.go
View file @
7d952a14
...
@@ -28,7 +28,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
...
@@ -28,7 +28,7 @@ func Load(r *gin.Engine, middleware ...gin.HandlerFunc) {
base
.
GET
(
"/example/list"
,
controller
.
GetExampleList
)
// 示例获取列表
base
.
GET
(
"/example/list"
,
controller
.
GetExampleList
)
// 示例获取列表
}
}
base
.
POST
(
"add_file"
,
controller
.
AddFile
)
//文件上传
base
.
POST
(
"
/
add_file"
,
controller
.
AddFile
)
//文件上传
// 初始化自动化运维路由
// 初始化自动化运维路由
InitAutomatedMaintenRouter
(
r
)
InitAutomatedMaintenRouter
(
r
)
...
...
src/service/doc_lib.go
View file @
7d952a14
package
service
package
service
import
(
import
(
"context"
"fmt"
"fmt"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/google/uuid"
...
@@ -8,6 +9,7 @@ import (
...
@@ -8,6 +9,7 @@ import (
"github.com/pkg/errors"
"github.com/pkg/errors"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf"
"io"
"mime/multipart"
"mime/multipart"
"net/http"
"net/http"
"path"
"path"
...
@@ -81,6 +83,31 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) {
...
@@ -81,6 +83,31 @@ func (d *DocLibSvc) AddFile(c *gin.Context) (fileUrl string, err error) {
err
=
errors
.
Wrap
(
err
,
"上传文件失败"
)
err
=
errors
.
Wrap
(
err
,
"上传文件失败"
)
return
return
}
}
fileUrl
=
fmt
.
Sprintf
(
"
https://
%s/%s/%s%s"
,
conf
.
Options
.
MinioServer
,
conf
.
Options
.
MinioBucket
,
id
,
ext
)
fileUrl
=
fmt
.
Sprintf
(
"%s/%s/%s%s"
,
conf
.
Options
.
MinioServer
,
conf
.
Options
.
MinioBucket
,
id
,
ext
)
return
return
}
}
// GetFile 读取minio文件
func
(
d
DocLibSvc
)
GetFile
(
fileName
string
)
(
obj
io
.
Reader
,
err
error
)
{
minioClient
,
err
:=
client
.
GetMinioConnect
()
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"getMinio"
)
return
}
object
,
err
:=
minioClient
.
GetObject
(
context
.
Background
(),
conf
.
Options
.
MinioBucket
,
fileName
,
minio
.
GetObjectOptions
{})
if
err
!=
nil
{
err
=
errors
.
Wrap
(
err
,
"download object error"
)
return
}
obj
=
io
.
Reader
(
object
)
return
obj
,
nil
//localFile, err := os.Create("C:/Users/25238/Desktop/123456.xlsx")
//if err != nil {
// log.Fatalf("create local object error " + err.Error())
//}
//_, err = io.Copy(localFile, object)
//if err != nil {
// log.Fatalf("write object from object to local file error " + err.Error())
// return
//}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment