-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (57 loc) · 1.57 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
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"log"
"os"
"iredmail-create-email-account/controllers"
"iredmail-create-email-account/middleware"
"iredmail-create-email-account/pkg/remote_ssh"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/kelseyhightower/envconfig"
)
var cfg struct {
RemoteUser string `required:"true" split_words:"true"`
RemoteServer string `required:"true" split_words:"true"`
RemoteKeyPath string `required:"true" split_words:"true"`
RemotePort string `required:"true" split_words:"true"`
ApiPort string `required:"true" split_words:"true"`
SupportEmail string `required:"true" split_words:"true"`
TrustedProxies []string `split_words:"true"`
}
func main() {
env := os.Getenv("ENV")
if env != "prod" {
err := godotenv.Load(".env")
if err != nil {
log.Fatal(
fmt.Errorf("environment variable ENV is empty and an error occurred while loading the .env file"),
)
}
}
err := envconfig.Process("", &cfg)
if err != nil {
log.Fatal(err)
}
config := remote_ssh.Config{
User: cfg.RemoteUser,
Server: cfg.RemoteServer,
KeyPath: cfg.RemoteKeyPath,
Port: cfg.RemotePort,
}
router := gin.Default()
if len(cfg.TrustedProxies) > 0 {
err = router.SetTrustedProxies(cfg.TrustedProxies)
if err != nil {
log.Fatal(err)
}
}
router.Use(middleware.Json())
router.Use(middleware.Error(cfg.SupportEmail))
user_controller := controllers.NewUser(config)
router.POST("/user", user_controller.CreateUser)
err = router.Run(fmt.Sprintf("localhost:%s", cfg.ApiPort))
if err != nil {
panic(err)
}
}