settings: Rename struct to remove FIC occurence

This commit is contained in:
nemunaire 2022-05-01 22:15:16 +02:00
parent 457cd307dd
commit e8f6a03cd9
6 changed files with 13 additions and 13 deletions

View File

@ -54,7 +54,7 @@ func getSettings(_ httprouter.Params, body []byte) (interface{}, error) {
} }
func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) { func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
var config *settings.FICSettings var config *settings.Settings
if err := json.Unmarshal(body, &config); err != nil { if err := json.Unmarshal(body, &config); err != nil {
return nil, err return nil, err
} }
@ -67,7 +67,7 @@ func saveSettings(_ httprouter.Params, body []byte) (interface{}, error) {
} }
} }
func ApplySettings(config *settings.FICSettings) { func ApplySettings(config *settings.Settings) {
fic.PartialValidation = config.PartialValidation fic.PartialValidation = config.PartialValidation
fic.UnlockedChallengeDepth = config.UnlockedChallengeDepth fic.UnlockedChallengeDepth = config.UnlockedChallengeDepth
fic.DisplayAllFlags = config.DisplayAllFlags fic.DisplayAllFlags = config.DisplayAllFlags

View File

@ -203,7 +203,7 @@ func main() {
log.Fatal("Unable to initialize settings.json:", err) log.Fatal("Unable to initialize settings.json:", err)
} }
} else { } else {
var config *settings.FICSettings var config *settings.Settings
if config, err = settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil { if config, err = settings.ReadSettings(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
log.Fatal("Unable to read settings.json:", err) log.Fatal("Unable to read settings.json:", err)
} else { } else {

View File

@ -67,7 +67,7 @@ var ChStarted = false
var lastRegeneration time.Time var lastRegeneration time.Time
var skipInitialGeneration = false var skipInitialGeneration = false
func reloadSettings(config *settings.FICSettings) { func reloadSettings(config *settings.Settings) {
allowRegistration = config.AllowRegistration allowRegistration = config.AllowRegistration
canJoinTeam = config.CanJoinTeam canJoinTeam = config.CanJoinTeam
denyTeamCreation = config.DenyTeamCreation denyTeamCreation = config.DenyTeamCreation

View File

@ -27,7 +27,7 @@ func touchStartedFile() {
} }
} }
func reloadSettings(config *settings.FICSettings) { func reloadSettings(config *settings.Settings) {
// Copy the new settings file for distribution // Copy the new settings file for distribution
if data, err := ioutil.ReadFile(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil { if data, err := ioutil.ReadFile(path.Join(settings.SettingsDir, settings.SettingsFile)); err != nil {
log.Println("Unable to read settings file:", err) log.Println("Unable to read settings file:", err)

View File

@ -28,7 +28,7 @@ type SessionZQDS struct {
Challenges []*ChallengeZQDS `json:"challenges"` Challenges []*ChallengeZQDS `json:"challenges"`
} }
func GenZQDSSessionFile(s *settings.FICSettings) (*SessionZQDS, error) { func GenZQDSSessionFile(s *settings.Settings) (*SessionZQDS, error) {
themes, err := GetThemes() themes, err := GetThemes()
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -20,8 +20,8 @@ const SettingsFile = "settings.json"
// SettingsDir is the relative location where the SettingsFile lies. // SettingsDir is the relative location where the SettingsFile lies.
var SettingsDir string = "./SETTINGS" var SettingsDir string = "./SETTINGS"
// FICSettings represents the settings panel. // Settings represents the settings panel.
type FICSettings struct { type Settings struct {
// Title is the displayed name of the challenge. // Title is the displayed name of the challenge.
Title string `json:"title"` Title string `json:"title"`
// Authors is the group name of people making the challenge. // Authors is the group name of people making the challenge.
@ -92,8 +92,8 @@ func ExistsSettings(settingsPath string) bool {
} }
// ReadSettings parses the file at the given location. // ReadSettings parses the file at the given location.
func ReadSettings(path string) (*FICSettings, error) { func ReadSettings(path string) (*Settings, error) {
var s FICSettings var s Settings
if fd, err := os.Open(path); err != nil { if fd, err := os.Open(path); err != nil {
return nil, err return nil, err
} else { } else {
@ -109,7 +109,7 @@ func ReadSettings(path string) (*FICSettings, error) {
} }
// SaveSettings saves settings at the given location. // SaveSettings saves settings at the given location.
func SaveSettings(path string, s *FICSettings) error { func SaveSettings(path string, s *Settings) error {
if fd, err := os.Create(path); err != nil { if fd, err := os.Create(path); err != nil {
return err return err
} else { } else {
@ -139,7 +139,7 @@ func ForceRegeneration() error {
// Giving the location and a callback, this function will first call your reload function // Giving the location and a callback, this function will first call your reload function
// before returning (if the file can be parsed); then it starts watching modifications made to // before returning (if the file can be parsed); then it starts watching modifications made to
// this file. Your callback is then run each time the file is modified. // this file. Your callback is then run each time the file is modified.
func LoadAndWatchSettings(settingsPath string, reload func(*FICSettings)) { func LoadAndWatchSettings(settingsPath string, reload func(*Settings)) {
// First load of configuration if it exists // First load of configuration if it exists
if _, err := os.Stat(settingsPath); !os.IsNotExist(err) { if _, err := os.Stat(settingsPath); !os.IsNotExist(err) {
if config, err := ReadSettings(settingsPath); err != nil { if config, err := ReadSettings(settingsPath); err != nil {
@ -184,7 +184,7 @@ func LoadAndWatchSettings(settingsPath string, reload func(*FICSettings)) {
} }
} }
func tryReload(settingsPath string, reload func(*FICSettings)) { func tryReload(settingsPath string, reload func(*Settings)) {
if config, err := ReadSettings(settingsPath); err != nil { if config, err := ReadSettings(settingsPath); err != nil {
log.Println("ERROR: Unable to read challenge settings:", err) log.Println("ERROR: Unable to read challenge settings:", err)
} else if time.Until(config.ActivateTime) > 0 { } else if time.Until(config.ActivateTime) > 0 {