-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73c74c0
commit 5d488a2
Showing
13 changed files
with
606 additions
and
50 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,17 @@ | ||
language: en | ||
port: 8000 | ||
dataabaseInfo: | ||
adminName: admin | ||
adminPass: admin | ||
databasePath: ./db.db | ||
sourceAndDestination: | ||
SourceServer: imap.example.com | ||
SourceMail: "@example.com" | ||
DestinationServer: imap.example.com | ||
DestinationMail: "@example.com" | ||
email: | ||
SMTPHost: smtp.example.com | ||
SMTPPort: 587 | ||
SMTPFrom: example | ||
SMTPUser: [email protected] | ||
SMTPPassword: password |
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,60 @@ | ||
package config | ||
|
||
import ( | ||
"flag" | ||
"imap-sync/logger" | ||
"os" | ||
|
||
"github.com/spf13/viper" | ||
) | ||
|
||
var log = logger.Log | ||
|
||
type Config struct { | ||
Language string | ||
Port string | ||
|
||
DatabaseInfo struct { | ||
AdminName string | ||
AdminPass string | ||
DatabasePath string | ||
} | ||
|
||
SourceAndDestination struct { | ||
SourceServer string | ||
SourceMail string | ||
DestinationServer string | ||
DestinationMail string | ||
} | ||
|
||
Email struct { | ||
SMTPHost string | ||
SMTPPort string | ||
SMTPFrom string | ||
SMTPUser string | ||
SMTPPassword string | ||
} | ||
} | ||
|
||
var Conf Config | ||
|
||
func ParseConfig() { | ||
filePath := flag.String("config", "/etc/monomail-sync.yml", "Path of the configuration file in YAML format") | ||
flag.Parse() | ||
|
||
if _, err := os.Stat(*filePath); os.IsNotExist(err) { | ||
log.Fatalf("Configuration file: %s does not exist, %v\n", *filePath, err) | ||
} | ||
|
||
viper.SetConfigFile(*filePath) | ||
viper.SetConfigType("yaml") | ||
|
||
if err := viper.ReadInConfig(); err != nil { | ||
log.Fatalf("Error reading config file, %s\n", err) | ||
} | ||
|
||
err := viper.Unmarshal(&Conf) | ||
if err != nil { | ||
log.Fatalf("Unable to decode into struct, %v\n", err) | ||
} | ||
} |
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
Oops, something went wrong.