-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (42 loc) · 1.16 KB
/
main.go
File metadata and controls
52 lines (42 loc) · 1.16 KB
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
package main
import (
"mailer-api/handler"
"os"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
func main() {
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) {
if username == os.Getenv("ADMIN_USER") && password == os.Getenv("ADMIN_PASSWORD") {
e.Logger.Info("Good credentials")
return true, nil
}
e.Logger.Error("Wrong credentials")
return false, nil
}))
SMTP := handler.SMTP{}
Template := handler.Template{}
Layout := handler.Layout{}
Mail := handler.Mail{}
conf := e.Group("/configuration")
// For smtp server conf
stmp := conf.Group("/smtp")
stmp.GET("/:id", SMTP.GetByID)
stmp.GET("", SMTP.GetAll)
stmp.POST("", SMTP.Save)
// For layout conf
layout := conf.Group("/layout")
layout.GET("/:id", Layout.GetByID)
layout.GET("", Layout.GetAll)
layout.POST("", Layout.Save)
// For template conf
template := conf.Group("/template")
template.GET("/:id", Template.GetByID)
template.GET("", Template.GetAll)
template.POST("", Template.Save)
e.POST("/send", Mail.Send)
e.Logger.Fatal(e.Start(":8080"))
}