From 05f8043672834e3b57062522789150dc9dd76f81 Mon Sep 17 00:00:00 2001 From: Eg <1711788888@qq.com> Date: Wed, 15 Jun 2022 11:57:45 +0800 Subject: [PATCH] :zap: commit ci file --- Dockerfile | 19 ++++++++---- main.go | 1 - map_test.go | 69 -------------------------------------------- utils/excel_utils.go | 62 --------------------------------------- 4 files changed, 13 insertions(+), 138 deletions(-) delete mode 100644 map_test.go delete mode 100644 utils/excel_utils.go diff --git a/Dockerfile b/Dockerfile index 9540d8f..859f345 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,24 @@ 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 ls -lh && chmod +x ./app +COPY . . + +# 指定OS等,并go build +RUN GOOS=linux GOARCH=amd64 go build . + +# 运行阶段指定scratch作为基础镜像 +FROM alpine -# 指定创建的基础镜像 -FROM alpine as runner -# 替换阿里云的源 -RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/main/" > /etc/apk/repositories -RUN echo "http://mirrors.aliyun.com/alpine/latest-stable/community/" >> /etc/apk/repositories WORKDIR /app COPY --from=builder /builder/app ./app -CMD ./app \ No newline at end of file +CMD ./app + +ENTRYPOINT ["./app"] \ No newline at end of file diff --git a/main.go b/main.go index 79f7c8e..ff43b0a 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,5 @@ package main -import "C" import ( "docDemo/router" "fmt" diff --git a/map_test.go b/map_test.go deleted file mode 100644 index c31b17b..0000000 --- a/map_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "docDemo/client" - "docDemo/model" - "encoding/json" - "fmt" - "github.com/xuri/excelize/v2" - "strings" - "testing" -) - -var AZ = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} - -func TestMap(t *testing.T) { - - file, err := excelize.OpenFile("result.xlsx") - - 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 - for i := range row[2:] { - ques = append(ques, map[string]string{AZ[i]: row[2:][i]}) - } - - 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.CorrectAnswer = "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) - } - } - -} diff --git a/utils/excel_utils.go b/utils/excel_utils.go deleted file mode 100644 index 06d07a5..0000000 --- a/utils/excel_utils.go +++ /dev/null @@ -1,62 +0,0 @@ -package utils - -import ( - "docDemo/model" - "errors" - "fmt" - "gitee.ltd/lxh/logger/log" - "github.com/xuri/excelize/v2" - "strings" -) - -var AZ = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"} - -type excel struct{} - -func ExcelUtils() *excel { - return &excel{} -} - -// ParseQuestion 转换Excel为量表问题答案信息 -func (e excel) ParseQuestion(ef *excelize.File) (es []model.Question, err error) { - // 获取指定sheet - rows, err := ef.GetRows("question") - if err != nil { - return - } - log.Debugf("读取成功,共%d行%d列数据", len(rows), len(rows[0])) - // 循环行,处理为结构体,不处理第一行,因为是标题 - for i, row := range rows[1:] { - // 如果问题出现空行,终止解析 - if row[0] == "" { - break - } - // 创建一个问题结构体 - var q model.Question - q.QuestionSerial = i + 1 - q.Question = row[0] - // 开始解析答案 - var answers []model.AnswerEntity - for j, a := range row[1:] { - // 如果答案出现空行,终止解析 - if a == "" { - break - } - // 拆开答案,获取答案和分值 - if !strings.Contains(a, "|") { - log.Errorf("异常数据: %v", a) - err = errors.New(fmt.Sprintf("模板文件格式错误(%v行%v列),答案和分值必须以|隔开", i+2, j+2)) - return - } - answerInfo := strings.Split(a, "|") - answers = append(answers, model.AnswerEntity{ - Code: AZ[j], - Answer: answerInfo[0], - Score: StrToInt(answerInfo[1]), - }) - } - q.Answers = answers - es = append(es, q) - } - return -}