diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index be7ad18..85d0ffc 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,6 +13,30 @@ jobs: build: runs-on: ubuntu-latest + + services: + redis: + image: redis + ports: + - 6379:6379 + postgres: + image: postgres + env: + POSTGRES_PASSWORD: jcourse + POSTGRES_DB: jcourse + POSTGRES_USER: jcourse + ports: + - 5432:5432 + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_PASSWORD: jcourse + POSTGRES_HOST: localhost + REDIS_HOST: localhost + steps: - uses: actions/checkout@v4 - name: Set up Go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d42da7c --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +export LOCAL_MODULE := jcourse_go + +.PHONY :lint +lint: + @go fmt ./... + @goimports -local $(LOCAL_MODULE) -w $$(find . -type f -name '*.go') + @go mod tidy diff --git a/cmd/load/teacher/extend_teacher_profile.go b/cmd/load/teacher/extend_teacher_profile.go index a8514d3..a126d1a 100644 --- a/cmd/load/teacher/extend_teacher_profile.go +++ b/cmd/load/teacher/extend_teacher_profile.go @@ -1,11 +1,12 @@ package main import ( + "log" + "os" + "jcourse_go/dal" "jcourse_go/model/po" seleniumget "jcourse_go/util/selenium-get" - "log" - "os" ) func main() { diff --git a/cmd/load/trainingplan/extend_training_plan.go b/cmd/load/trainingplan/extend_training_plan.go index 521e38c..6943097 100644 --- a/cmd/load/trainingplan/extend_training_plan.go +++ b/cmd/load/trainingplan/extend_training_plan.go @@ -2,13 +2,14 @@ package main import ( "errors" - "jcourse_go/dal" - "jcourse_go/model/po" - seleniumget "jcourse_go/util/selenium-get" "log" "os" "strconv" + "jcourse_go/dal" + "jcourse_go/model/po" + seleniumget "jcourse_go/util/selenium-get" + "gorm.io/gorm" ) diff --git a/go.mod b/go.mod index 83ed460..e5bbda7 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module jcourse_go go 1.22 require ( - github.com/DATA-DOG/go-sqlmock v1.5.2 github.com/SJTU-jCourse/password_hasher v0.0.0-20240731144855-1f64f055ff5c github.com/bytedance/sonic v1.12.1 github.com/gin-gonic/contrib v0.0.0-20240508051311-c1c6bf0061b0 @@ -41,6 +40,7 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/context v1.1.2 // indirect github.com/gorilla/securecookie v1.1.2 // indirect @@ -66,11 +66,11 @@ require ( github.com/ugorji/go/codec v1.2.12 // indirect github.com/vcaesar/cedar v0.20.2 // indirect golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.25.0 // indirect - golang.org/x/net v0.25.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/protobuf v1.34.2 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect diff --git a/go.sum b/go.sum index 5297578..df2ba74 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,3 @@ -github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU= -github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/SJTU-jCourse/password_hasher v0.0.0-20240731144855-1f64f055ff5c h1:WGY3netUDrvhBsc0HOaorABwvTYjbbq8BG7Dyy9tbkk= github.com/SJTU-jCourse/password_hasher v0.0.0-20240731144855-1f64f055ff5c/go.mod h1:vdxJOQaD9MexhM0evO8XgV8m+dkiXxA9M/WkOgeB3P4= github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff h1:RmdPFa+slIr4SCBg4st/l/vZWVe9QJKMXGO60Bxbe04= @@ -61,8 +59,8 @@ github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNu github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -100,7 +98,6 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= @@ -177,20 +174,20 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= -golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -199,13 +196,13 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= diff --git a/handler/admin.go b/handler/admin.go index e5b4970..2393807 100644 --- a/handler/admin.go +++ b/handler/admin.go @@ -1,10 +1,11 @@ package handler import ( + "net/http" + "jcourse_go/model/domain" "jcourse_go/model/dto" "jcourse_go/service" - "net/http" "github.com/gin-gonic/gin" ) diff --git a/handler/teacher.go b/handler/teacher.go index 6f35f7d..d996c60 100644 --- a/handler/teacher.go +++ b/handler/teacher.go @@ -1,11 +1,12 @@ package handler import ( + "net/http" + "jcourse_go/constant" "jcourse_go/model/converter" "jcourse_go/model/domain" "jcourse_go/model/dto" - "net/http" "jcourse_go/service" diff --git a/handler/trainingplan.go b/handler/trainingplan.go index 9d66640..fcd6e01 100644 --- a/handler/trainingplan.go +++ b/handler/trainingplan.go @@ -2,11 +2,12 @@ package handler import ( "fmt" + "net/http" + "jcourse_go/model/converter" "jcourse_go/model/domain" "jcourse_go/model/dto" "jcourse_go/service" - "net/http" "github.com/gin-gonic/gin" ) diff --git a/handler/user.go b/handler/user.go index 30a82a2..e3a0833 100644 --- a/handler/user.go +++ b/handler/user.go @@ -2,13 +2,14 @@ package handler import ( "errors" + "net/http" + "strconv" + "jcourse_go/constant" "jcourse_go/model/converter" "jcourse_go/model/domain" "jcourse_go/model/dto" "jcourse_go/service" - "net/http" - "strconv" "github.com/gin-gonic/gin" ) diff --git a/model/converter/trainingplan.go b/model/converter/trainingplan.go index e2f12cd..3a7c177 100644 --- a/model/converter/trainingplan.go +++ b/model/converter/trainingplan.go @@ -1,10 +1,11 @@ package converter import ( + "strconv" + "jcourse_go/model/domain" "jcourse_go/model/dto" "jcourse_go/model/po" - "strconv" ) func ConvertTrainingPlanCourseDomainToDTO(courseDomain domain.TrainingPlanCourse) dto.TrainingPlanCourseDTO { diff --git a/model/converter/user.go b/model/converter/user.go index eea9dab..4050e53 100644 --- a/model/converter/user.go +++ b/model/converter/user.go @@ -1,10 +1,11 @@ package converter import ( + "time" + "jcourse_go/model/domain" "jcourse_go/model/dto" "jcourse_go/model/po" - "time" ) func ConvertUserPOToDomain(userPO po.UserPO) domain.User { diff --git a/model/po/search.go b/model/po/search.go index 247ec77..6ab477f 100755 --- a/model/po/search.go +++ b/model/po/search.go @@ -3,9 +3,10 @@ package po import ( "context" "database/sql/driver" - "jcourse_go/util" "strings" + "jcourse_go/util" + "gorm.io/gorm" "gorm.io/gorm/clause" ) diff --git a/util/segword_test.go b/util/segword_test.go index 56f02a9..8733458 100755 --- a/util/segword_test.go +++ b/util/segword_test.go @@ -1,9 +1,10 @@ package util_test import ( - "jcourse_go/util" "testing" + "jcourse_go/util" + "github.com/stretchr/testify/assert" ) diff --git a/util/selenium-get/load2db.go b/util/selenium-get/load2db.go index 79cc97f..920b4f4 100644 --- a/util/selenium-get/load2db.go +++ b/util/selenium-get/load2db.go @@ -5,12 +5,13 @@ import ( "encoding/json" "errors" "fmt" - "jcourse_go/model/po" "log" "os" "strconv" "strings" + "jcourse_go/model/po" + "gorm.io/gorm" ) diff --git a/util/selenium-get/load2db_test.go b/util/selenium-get/load2db_test.go index 6e1004d..b222d7a 100644 --- a/util/selenium-get/load2db_test.go +++ b/util/selenium-get/load2db_test.go @@ -2,11 +2,12 @@ package seleniumget import ( "fmt" + "reflect" + "testing" + "jcourse_go/dal" "jcourse_go/model/po" "jcourse_go/util" - "reflect" - "testing" ) func migrate() {