-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (48 loc) · 1.03 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"errors"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/ericklima-ca/mailer_api/http_server"
"github.com/ericklima-ca/mailer_api/mailer"
)
func main() {
var (
HOST_SMTP = os.Getenv("HOST_SMTP")
)
if HOST_SMTP == "" {
HOST_SMTP = "smtp.gmail.com:465"
}
ms := mailer.MailerService{
HostPort: HOST_SMTP,
}
server := http_server.HTTPServer{
MailerService: ms,
}
app := http_server.NewServer(server)
httpSrv := &http.Server{
Addr: ":8080",
Handler: app,
}
go func() {
if err := httpSrv.ListenAndServe(); err != nil &&
errors.Is(err, http.ErrServerClosed) {
log.Printf("Error on %s\n", err)
}
}()
quit := make(chan os.Signal, 2)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutting down server...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := httpSrv.Shutdown(ctx); err != nil {
log.Fatal("Server forced to shutdown: ", err)
}
log.Println("Server exiting...")
}