refactor: conf with less import
This commit is contained in:
parent
31c310960f
commit
5236916858
|
@ -14,7 +14,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-git/go-git/v5"
|
"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/joint-online-judge/JOJ3/internal/stage"
|
||||||
"github.com/koding/multiconfig"
|
"github.com/koding/multiconfig"
|
||||||
)
|
)
|
||||||
|
@ -165,7 +164,7 @@ func parseConventionalCommit(commit string) (*ConventionalCommit, error) {
|
||||||
return cc, nil
|
return cc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseConfFile(path string) (conf *Conf, err error) {
|
func ParseConfFile(path string) (conf *Conf, name string, err error) {
|
||||||
conf = new(Conf)
|
conf = new(Conf)
|
||||||
d := &multiconfig.DefaultLoader{}
|
d := &multiconfig.DefaultLoader{}
|
||||||
d.Loader = multiconfig.MultiLoader(
|
d.Loader = multiconfig.MultiLoader(
|
||||||
|
@ -181,7 +180,7 @@ func ParseConfFile(path string) (conf *Conf, err error) {
|
||||||
slog.Error("validate stages conf", "error", err)
|
slog.Error("validate stages conf", "error", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
env.Attr.ConfName = conf.Name
|
name = conf.Name
|
||||||
// TODO: remove the following backward compatibility codes
|
// TODO: remove the following backward compatibility codes
|
||||||
if conf.MaxTotalScore < 0 && conf.Teapot.MaxTotalScore >= 0 {
|
if conf.MaxTotalScore < 0 && conf.Teapot.MaxTotalScore >= 0 {
|
||||||
conf.MaxTotalScore = conf.Teapot.MaxTotalScore
|
conf.MaxTotalScore = conf.Teapot.MaxTotalScore
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
|
"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/stage"
|
||||||
"github.com/joint-online-judge/JOJ3/cmd/joj3/teapot"
|
"github.com/joint-online-judge/JOJ3/cmd/joj3/teapot"
|
||||||
internalStage "github.com/joint-online-judge/JOJ3/internal/stage"
|
internalStage "github.com/joint-online-judge/JOJ3/internal/stage"
|
||||||
|
@ -85,11 +86,12 @@ func mainImpl() (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
slog.Info("try to load conf", "path", confPath)
|
slog.Info("try to load conf", "path", confPath)
|
||||||
confObj, err = conf.ParseConfFile(confPath)
|
confObj, confName, err := conf.ParseConfFile(confPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("parse conf", "error", err)
|
slog.Error("parse conf", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
env.Attr.ConfName = confName
|
||||||
slog.Debug("conf loaded", "conf", confObj)
|
slog.Debug("conf loaded", "conf", confObj)
|
||||||
if err := setupSlog(confObj); err != nil { // after conf is loaded
|
if err := setupSlog(confObj); err != nil { // after conf is loaded
|
||||||
slog.Error("setup slog", "error", err)
|
slog.Error("setup slog", "error", err)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user