-
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.
all it is left is template one; refine config management
- Loading branch information
1 parent
22fb7ec
commit 2da27c9
Showing
10 changed files
with
751 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,5 @@ | |
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
*.pb.go | ||
*.pb.go | ||
app.env |
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 |
---|---|---|
@@ -1,2 +1,11 @@ | ||
# email-microservice | ||
gRPC based emailing service | ||
|
||
## Environment Variables | ||
``` | ||
SMTP_HOST: SMTP host | ||
SMTP_PORT: SMTP port | ||
SMTP_SENDER: SMTP user | ||
SMTP_PASSWORD: SMTP password | ||
PORT: Port to listen on | ||
``` |
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
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
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,5 @@ | ||
SMTP_HOST=smtp.gmail.com | ||
SMTP_PORT=587 | ||
SMTP_EMAIL=crossphoton@gmail.com | ||
SMTP_PASSWORD=password | ||
PORT=5555 |
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,55 @@ | ||
package src | ||
|
||
import ( | ||
"crypto/tls" | ||
"log" | ||
"time" | ||
|
||
"github.com/spf13/viper" | ||
mail "github.com/xhit/go-simple-mail/v2" | ||
) | ||
|
||
type Config struct { | ||
SMTPHost string `mapstructure:"SMTP_HOST"` | ||
SMTPPort int `mapstructure:"SMTP_PORT"` | ||
SMTPEmail string `mapstructure:"SMTP_EMAIL"` | ||
SMTPPassword string `mapstructure:"SMTP_PASSWORD"` | ||
} | ||
|
||
var ( | ||
config Config | ||
) | ||
|
||
func init() { | ||
viper.AddConfigPath(".") | ||
viper.AddConfigPath("../") | ||
viper.SetConfigType("env") | ||
viper.SetConfigName("app") | ||
viper.AutomaticEnv() | ||
err := viper.ReadInConfig() | ||
if err != nil { | ||
if _, ok := err.(viper.ConfigFileNotFoundError); ok { | ||
} else { | ||
log.Fatalf("error reading config file: %v", err) | ||
} | ||
} | ||
|
||
viper.Unmarshal(&config) | ||
|
||
smtpServer := mail.NewSMTPClient() | ||
smtpServer.Host = config.SMTPHost | ||
smtpServer.Port = config.SMTPPort | ||
smtpServer.Username = config.SMTPEmail | ||
smtpServer.Password = config.SMTPPassword | ||
smtpServer.Encryption = mail.EncryptionSTARTTLS | ||
|
||
smtpServer.KeepAlive = true | ||
smtpServer.ConnectTimeout = 10 * time.Second | ||
smtpServer.SendTimeout = 10 * time.Second | ||
smtpServer.TLSConfig = &tls.Config{InsecureSkipVerify: true} | ||
|
||
smtpClient, err = smtpServer.Connect() | ||
if err != nil { | ||
log.Fatalf("connection to remote smtp server failed: %v", 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