-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 🚚 move validating config into separate function
- Loading branch information
1 parent
78b6dfb
commit 24549f1
Showing
2 changed files
with
30 additions
and
14 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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package config | ||
|
||
import "fmt" | ||
|
||
func ValidateConfig(cfg Config) error { | ||
if cfg.Username == "" { | ||
return fmt.Errorf("username cannot be empty") | ||
} | ||
|
||
if cfg.Token == "" { | ||
return fmt.Errorf("token cannot be empty. See here: https://github.com/AkashRajpurohit/git-sync#how-do-i-create-a-github-personal-access-token") | ||
} | ||
|
||
if cfg.BackupDir == "" { | ||
return fmt.Errorf("backup directory cannot be empty") | ||
} | ||
|
||
if cfg.Server.Domain == "" { | ||
return fmt.Errorf("server domain cannot be empty") | ||
} | ||
|
||
if cfg.Server.Protocol != "https" && cfg.Server.Protocol != "http" { | ||
return fmt.Errorf("server protocol can only be http or https") | ||
} | ||
|
||
return nil | ||
} |