修改ci文件

This commit is contained in:
loser 2022-06-15 12:55:19 +08:00
parent 05f8043672
commit 23261f0af5
8 changed files with 5 additions and 1352 deletions

View File

@ -1,20 +1,18 @@
FROM golang:1.18 as builder
# 启用go module
ENV GO111MODULE=on \
GOPROXY=https://goproxy.cn,direct
WORKDIR /builder
COPY . .
RUN go mod download && go build -o app && upx -9 app
RUN go mod download && go build -o app
RUN ls -lh && chmod +x ./app
COPY . .
# 指定OS等并go build
RUN GOOS=linux GOARCH=amd64 go build .
# 运行阶段指定scratch作为基础镜像
FROM alpine
WORKDIR /app

View File

@ -1,13 +1,7 @@
package api
import (
"docDemo/client"
"docDemo/model"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/xuri/excelize/v2"
"strings"
)
type scaleApi struct{}
@ -16,76 +10,6 @@ func ScaleApi() *scaleApi {
return &scaleApi{}
}
func (scaleApi) AddScale(ctx *gin.Context) {
var p model.AddQuestion
if ctx.ShouldBind(&p) != nil {
fmt.Println("参数错误")
return
}
open, err := p.File.Open()
if err != nil {
fmt.Println("文件打开失败", err)
return
}
file, err := excelize.OpenReader(open)
defer file.Close()
if err != nil {
return
}
rows, err := file.GetRows("Sheet1")
if err != nil {
return
}
for _, row := range rows[1:3] {
if row[0] == "" {
break
}
var ques []map[string]string
if len(row) > 2 {
//ques = append(ques, map[string]string{"A": row[2]})
//ques = append(ques, map[string]string{"B": row[3]})
//ques = append(ques, map[string]string{"C": row[4]})
//ques = append(ques, map[string]string{"D": row[5]})
for i := range rows {
ques = append(ques, map[string]string{row[i]: row[3]})
}
}
awssJson, err := json.Marshal(ques)
if err != nil {
return
}
var Questions model.Question
Questions.Content = row[1]
Questions.Answer = string(awssJson)
Questions.Analysis = "A"
Questions.Subject = "大学语文"
if strings.Contains(row[0], "单选") || strings.Contains(row[0], "单项") {
Questions.SubjectType = "single"
}
if strings.Contains(row[0], "多选") || strings.Contains(row[0], "多项") {
Questions.SubjectType = "mutil"
}
if strings.Contains(row[0], "判断") {
Questions.SubjectType = "judge"
}
if strings.Contains(row[0], "应用") || strings.Contains(row[0], "简答") {
Questions.SubjectType = "application"
}
err = client.MySQL.Table("sys_question_bank").Create(&Questions).Error
if err != nil {
fmt.Println("导入题库失败:", err)
}
}
}
func (scaleApi) Test(ctx *gin.Context) {
ctx.JSON(200, gin.H{
"message": "drone-Test",

View File

@ -1,23 +0,0 @@
package client
import (
"gitee.ltd/lxh/logger"
"gitee.ltd/lxh/logger/log"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
var MySQL *gorm.DB
// InitMySQLClient 初始化MySQL客户端
func InitMySQLClient() {
// 创建连接对象
conn, err := gorm.Open(mysql.Open("root:Tw2022!@#@tcp(47.109.17.77:3306)/tuowei?charset=utf8mb4&parseTime=True&loc=Local&timeout=1000ms"), &gorm.Config{Logger: logger.DefaultGormLogger()})
if err != nil {
log.Panicf("初始化MySQL连接失败, 错误信息: %v", err)
} else {
log.Debug("[MySQL] 连接成功")
}
MySQL = conn
}

46
go.mod
View File

@ -2,67 +2,27 @@ module docDemo
go 1.18
require (
gitee.ltd/lxh/logger v1.0.14
github.com/gin-gonic/gin v1.8.1
github.com/xuri/excelize/v2 v2.6.0
gorm.io/driver/mysql v1.3.2
gorm.io/gorm v1.23.5
)
require github.com/gin-gonic/gin v1.8.1
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/caarlos0/env/v6 v6.9.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.10.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lixh00/loki-client-go v1.0.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.34.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/prometheus v1.8.2-0.20201028100903-3245b3267b24 // indirect
github.com/richardlehane/mscfb v1.0.4 // indirect
github.com/richardlehane/msoleps v1.0.1 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/xuri/efp v0.0.0-20220407160117-ad0f7a785be8 // indirect
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
golang.org/x/net v0.0.0-20220517181318-183a9ca12b87 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220517195934-5e4e11fc645e // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220505152158-f39f71e6c8f3 // indirect
google.golang.org/grpc v1.46.2 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

1171
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -6,10 +6,6 @@ import (
"github.com/gin-gonic/gin"
)
//func init() {
// client.InitMySQLClient()
//}
func main() {
app := gin.Default()

View File

@ -1,30 +0,0 @@
package model
import (
"gorm.io/gorm"
"mime/multipart"
"time"
)
type Question struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码" comment:"主键ID"`
KnowledgePointId int `json:"knowledge_point_id" comment:"知识点ID"`
SubjectType string `json:"subject_type" gorm:"type:varchar(10);comment:题目类型 1-大学英语/2-大学英语/3-大学数学/4-大学计算机"`
Content string `json:"content" gorm:"type:text;comment:题目内容"`
Answer string `json:"answer" gorm:"type:text;not null;comment:答案"`
CorrectAnswer string `json:"correct_answer" gorm:"type:text;comment:正确答案"`
Analysis string `json:"analysis" gorm:"type:text;comment:题目解析"`
Score float64 `json:"score"`
Subject string `json:"subject" gorm:"type:varchar(10);comment:科目类型 大学英语/大学数学/大学语文"`
CreatedAt time.Time `json:"createdAt" gorm:"comment:创建时间"`
UpdatedAt time.Time `json:"updatedAt" gorm:"comment:最后更新时间"`
DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:删除时间"`
}
func (Question) TableName() string {
return "sys_question_bank"
}
type AddQuestion struct {
File *multipart.FileHeader `json:"file" form:"file" binding:"required"`
}

View File

@ -13,6 +13,5 @@ func InitRouter(app *gin.RouterGroup) {
// 内部开放接口
func openRouter(g *gin.RouterGroup) {
g.POST("/scale/upload", api.ScaleApi().AddScale) // 获取单个量表信息
g.GET("/test", api.ScaleApi().Test)
}