-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
56 lines (46 loc) · 1.52 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
package main
import (
"context"
"fmt"
"os"
"registry-backend/config"
"registry-backend/ent"
"registry-backend/ent/migrate"
drip_logging "registry-backend/logging"
"registry-backend/server"
"github.com/rs/zerolog/log"
_ "github.com/lib/pq"
)
func main() {
drip_logging.SetGlobalLogLevel(os.Getenv("LOG_LEVEL"))
connection_string := os.Getenv("DB_CONNECTION_STRING")
config := config.Config{
ProjectID: os.Getenv("PROJECT_ID"),
DripEnv: os.Getenv("DRIP_ENV"),
SlackRegistryChannelWebhook: os.Getenv("SLACK_REGISTRY_CHANNEL_WEBHOOK"),
JWTSecret: os.Getenv("JWT_SECRET"),
SecretScannerURL: os.Getenv("SECRET_SCANNER_URL"),
DiscordSecurityChannelWebhook: os.Getenv("SECURITY_COUNCIL_DISCORD_WEBHOOK"),
}
var dsn string
if os.Getenv("DRIP_ENV") == "localdev" {
dsn = fmt.Sprintf("%s sslmode=disable", connection_string)
} else {
dsn = connection_string
}
client, err := ent.Open("postgres", dsn)
if err != nil {
log.Fatal().Err(err).Msg("failed opening connection to postgres.")
}
defer client.Close()
// Run the auto migration tool for localdev.
if os.Getenv("DRIP_ENV") == "localdev" {
log.Info().Msg("Running migrations")
if err := client.Schema.Create(context.Background(), migrate.WithDropIndex(true),
migrate.WithDropColumn(true)); err != nil {
log.Fatal().Err(err).Msg("failed creating schema resources.")
}
}
server := server.NewServer(client, &config)
log.Fatal().Err(server.Start()).Msg("Server stopped")
}