Compare commits

...

2 Commits

Author SHA1 Message Date
2a3ccb71df
refactor: move cmd/joj3/conf to internal/conf
Some checks failed
build / build (push) Failing after 4s
build / trigger-build-image (push) Has been skipped
submodules sync / sync (push) Successful in 31s
2024-11-28 10:32:57 -05:00
5236916858
refactor: conf with less import 2024-11-28 10:29:45 -05:00
7 changed files with 10 additions and 9 deletions

View File

@ -7,8 +7,8 @@ import (
"log/slog"
"os"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/internal/conf"
)
var runningTest bool

View File

@ -6,9 +6,10 @@ import (
"log/slog"
"os"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/cmd/joj3/stage"
"github.com/joint-online-judge/JOJ3/cmd/joj3/teapot"
"github.com/joint-online-judge/JOJ3/internal/conf"
internalStage "github.com/joint-online-judge/JOJ3/internal/stage"
)
@ -85,11 +86,12 @@ func mainImpl() (err error) {
return err
}
slog.Info("try to load conf", "path", confPath)
confObj, err = conf.ParseConfFile(confPath)
confObj, confName, err := conf.ParseConfFile(confPath)
if err != nil {
slog.Error("parse conf", "error", err)
return err
}
env.Attr.ConfName = confName
slog.Debug("conf loaded", "conf", confObj)
if err := setupSlog(confObj); err != nil { // after conf is loaded
slog.Error("setup slog", "error", err)

View File

@ -5,8 +5,8 @@ import (
"log/slog"
"strings"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
"github.com/joint-online-judge/JOJ3/cmd/joj3/teapot"
"github.com/joint-online-judge/JOJ3/internal/conf"
executors "github.com/joint-online-judge/JOJ3/internal/executor"
_ "github.com/joint-online-judge/JOJ3/internal/parser"
"github.com/joint-online-judge/JOJ3/internal/stage"

View File

@ -7,8 +7,8 @@ import (
"os"
"strings"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/internal/conf"
)
type CheckResult struct {

View File

@ -8,8 +8,8 @@ import (
"strconv"
"strings"
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/internal/conf"
)
type RunResult struct {

View File

@ -14,7 +14,6 @@ import (
"time"
"github.com/go-git/go-git/v5"
"github.com/joint-online-judge/JOJ3/cmd/joj3/env"
"github.com/joint-online-judge/JOJ3/internal/stage"
"github.com/koding/multiconfig"
)
@ -165,7 +164,7 @@ func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
return cc, nil
}
func ParseConfFile(path string) (conf *Conf, err error) {
func ParseConfFile(path string) (conf *Conf, name string, err error) {
conf = new(Conf)
d := &multiconfig.DefaultLoader{}
d.Loader = multiconfig.MultiLoader(
@ -181,7 +180,7 @@ func ParseConfFile(path string) (conf *Conf, err error) {
slog.Error("validate stages conf", "error", err)
return
}
env.Attr.ConfName = conf.Name
name = conf.Name
// TODO: remove the following backward compatibility codes
if conf.MaxTotalScore < 0 && conf.Teapot.MaxTotalScore >= 0 {
conf.MaxTotalScore = conf.Teapot.MaxTotalScore