-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate a default config.json if one is not present
- Loading branch information
1 parent
d203b34
commit 164e5aa
Showing
1 changed file
with
29 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,19 +137,46 @@ func getClient() (*gmail.Service, error) { | |
func readConfig() Configuration { | ||
configFile, err := os.Open("config.json") | ||
if err != nil { | ||
log.Fatal(err) | ||
if os.IsNotExist(err) { | ||
// Create a default config.json file if it doesn't exist | ||
defaultConfig := Configuration{ | ||
SteamCmdPath: "./steamcmd/steamcmd.exe", | ||
} | ||
err := createDefaultConfigFile(defaultConfig) | ||
if err != nil { | ||
log.Fatalf("Error creating default config file: %v", err) | ||
} | ||
return defaultConfig | ||
} | ||
log.Fatalf("Error opening config file: %v", err) | ||
} | ||
defer configFile.Close() | ||
|
||
decoder := json.NewDecoder(configFile) | ||
config := Configuration{} | ||
err = decoder.Decode(&config) | ||
if err != nil { | ||
log.Fatal(err) | ||
log.Fatalf("Error decoding config file: %v", err) | ||
} | ||
return config | ||
} | ||
|
||
func createDefaultConfigFile(config Configuration) error { | ||
configFile, err := os.Create("config.json") | ||
if err != nil { | ||
return err | ||
} | ||
defer configFile.Close() | ||
|
||
encoder := json.NewEncoder(configFile) | ||
encoder.SetIndent("", " ") | ||
err = encoder.Encode(config) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func fetchSteamGuardCode(srv *gmail.Service) string { | ||
user := "me" | ||
query := "from:[email protected] is:unread" | ||
|