chore: move global and repo to root

This commit is contained in:
Paul Pan 2022-10-13 16:32:44 +08:00
parent cb10c3b28c
commit cb79b2090a
33 changed files with 62 additions and 41 deletions

View File

@ -1,8 +1,8 @@
package main
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/app"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/urfave/cli/v2"
"math/rand"
"time"

View File

@ -6,6 +6,7 @@ WebServer:
Redis:
Db: 0
QueueDb: 0
Address: '127.0.0.1:6379'
Password: ''

View File

@ -9,6 +9,7 @@ type ConfigWebServer struct {
type ConfigRedis struct {
Db int `yaml:"Db"`
QueueDb int `yaml:"QueueDb"`
Address string `yaml:"Address"`
Password string `yaml:"Password"`
}

2
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/gin-gonic/gin v1.8.1
github.com/go-redis/redis/v8 v8.11.5
github.com/golang-jwt/jwt/v4 v4.4.2
github.com/hibiken/asynq v0.23.0
github.com/lib/pq v1.10.2
github.com/prometheus/client_golang v1.13.0
github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a
@ -42,7 +43,6 @@ require (
github.com/goccy/go-json v0.9.7 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hibiken/asynq v0.23.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect

6
go.sum
View File

@ -80,6 +80,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
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.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
@ -439,9 +440,8 @@ go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/goleak v0.10.0/go.mod h1:VCZuO8V8mFPlL0F5J5GK1rtHV3DrFcQ1R8ryq7FK0aI=
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
@ -616,8 +616,6 @@ golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI=
golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=

View File

@ -1,7 +1,7 @@
package debug
import (
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)

View File

@ -1,7 +1,7 @@
package problem
import (
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/service/problem"
"github.com/gin-gonic/gin"
"go.uber.org/zap"

View File

@ -1,8 +1,8 @@
package problem
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/model"
"github.com/gin-gonic/gin"
)

View File

@ -1,8 +1,8 @@
package user
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/internal/service/user"
"github.com/gin-gonic/gin"
)

View File

@ -1,7 +1,7 @@
package user
import (
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/service/user"
"github.com/gin-gonic/gin"
"go.uber.org/zap"

View File

@ -1,8 +1,8 @@
package user
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/model"
"github.com/gin-gonic/gin"
)

View File

@ -1,8 +1,8 @@
package user
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/gin-gonic/gin"
)

View File

@ -1,8 +1,8 @@
package user
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/model"
"github.com/gin-gonic/gin"
)

View File

@ -3,11 +3,11 @@ package app
import (
"context"
"fmt"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/internal/repo/postgresql"
"github.com/WHUPRJ/woj-server/internal/repo/redis"
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/router"
"github.com/WHUPRJ/woj-server/internal/service/jwt"
"github.com/WHUPRJ/woj-server/repo/postgresql"
"github.com/WHUPRJ/woj-server/repo/redis"
"go.uber.org/zap"
"net/http"
"os"

View File

@ -1,10 +1,10 @@
package router
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/api/debug"
"github.com/WHUPRJ/woj-server/internal/api/problem"
"github.com/WHUPRJ/woj-server/internal/api/user"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/gin-gonic/gin"
)

View File

@ -1,7 +1,7 @@
package router
import (
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/pkg/metrics"
_ "github.com/WHUPRJ/woj-server/internal/router/docs"
"github.com/WHUPRJ/woj-server/pkg/utils"

View File

@ -1,7 +1,7 @@
package jwt
import (
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/go-redis/redis/v8"
"go.uber.org/zap"
)

View File

@ -3,8 +3,8 @@ package jwt
import (
"context"
"fmt"
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/pkg/utils"
"github.com/golang-jwt/jwt/v4"
"go.uber.org/zap"

View File

@ -1,8 +1,8 @@
package problem
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/model"
"go.uber.org/zap"
"gorm.io/gorm"

View File

@ -21,7 +21,7 @@ func (s *service) submit(typename string, payload []byte) (*asynq.TaskInfo, e.St
}
func (s *service) GetTaskInfo(id string) (*asynq.TaskInfo, e.Status) {
task, err := s.inspector.GetTaskInfo("", id)
task, err := s.inspector.GetTaskInfo("default", id)
if err != nil {
s.log.Debug("get task info failed", zap.Error(err), zap.String("id", id))
return nil, e.TaskGetInfoFailed

View File

@ -7,14 +7,14 @@ import (
"go.uber.org/zap"
)
func (s *service) NewJudge(submission model.Submission) e.Status {
func (s *service) NewJudge(submission model.Submission) (string, e.Status) {
payload, err := json.Marshal(model.SubmitJudge{Submission: submission})
if err != nil {
s.log.Warn("json marshal error", zap.Error(err), zap.Any("payload", submission))
return e.InternalError
return "", e.InternalError
}
_, status := s.submit(model.TypeSubmitJudge, payload)
info, status := s.submit(model.TypeSubmitJudge, payload)
return status
return info.ID, status
}

View File

@ -0,0 +1,23 @@
package task
import (
"encoding/json"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/model"
"go.uber.org/zap"
)
func (s *service) PushProblem(id uint, file string) (string, e.Status) {
payload, err := json.Marshal(model.ProblemPushPayload{
ProblemID: id,
ProblemFile: file,
})
if err != nil {
s.log.Warn("json marshal error", zap.Error(err), zap.Any("id", id), zap.String("file", file))
return "", e.InternalError
}
info, status := s.submit(model.TypeSubmitJudge, payload)
return info.ID, status
}

View File

@ -1,8 +1,8 @@
package task
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/model"
"github.com/hibiken/asynq"
"go.uber.org/zap"
@ -11,7 +11,9 @@ import (
var _ Service = (*service)(nil)
type Service interface {
NewJudge(submission model.Submission) e.Status
NewJudge(submission model.Submission) (string, e.Status)
PushProblem(id uint, file string) (string, e.Status)
GetTaskInfo(id string) (*asynq.TaskInfo, e.Status)
submit(typename string, payload []byte) (*asynq.TaskInfo, e.Status)
}
@ -25,7 +27,7 @@ func NewService(g *global.Global) Service {
redisOpt := asynq.RedisClientOpt{
Addr: g.Conf.Redis.Address,
Password: g.Conf.Redis.Password,
DB: g.Conf.Redis.Db,
DB: g.Conf.Redis.QueueDb,
}
return &service{
log: g.Log,

View File

@ -1,8 +1,8 @@
package user
import (
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/model"
"github.com/go-redis/redis/v8"
"go.uber.org/zap"

View File

@ -15,5 +15,6 @@ type Problem struct {
Provider User `json:"-" gorm:"foreignKey:ProviderID"`
Languages pq.Int32Array `json:"languages" gorm:"type:int[]"`
Points pq.Int32Array `json:"points" gorm:"type:int[]"`
StorageKey string `json:"storage_key" gorm:"not null"`
IsEnabled bool `json:"is_enabled" gorm:"not null;index"`
}

View File

@ -1,17 +1,12 @@
package model
const (
TypeProblemResolve = "problem:resolve"
TypeProblemPush = "problem:push"
TypeSubmitJudge = "submit:judge"
TypeProblemPush = "problem:push"
TypeSubmitJudge = "submit:judge"
)
type ProblemResolvePayload struct {
ProblemID uint
ProblemFile string
}
type ProblemPushPayload struct {
ProblemID uint
ProblemFile string
}

View File

@ -4,7 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/WHUPRJ/woj-server/model"
"go.uber.org/zap"
"gorm.io/driver/postgres"

View File

@ -2,7 +2,7 @@ package redis
import (
"context"
"github.com/WHUPRJ/woj-server/internal/global"
"github.com/WHUPRJ/woj-server/global"
"github.com/go-redis/redis/v8"
"go.uber.org/zap"
)