-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (71 loc) · 2.36 KB
/
Copy pathmain.go
File metadata and controls
88 lines (71 loc) · 2.36 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: GPL-3.0-or-later
package main
import (
"fmt"
"log"
"os"
"github.com/scribe-org/scribe-server/api"
"github.com/spf13/viper"
_ "github.com/scribe-org/scribe-server/docs"
)
// MARK: Environment Logging
// logEnvironment prints out key runtime environment info such as ENV and GIN_MODE.
func logEnvironment() {
env := os.Getenv("ENV")
if env == "" {
env = "dev"
}
ginMode := os.Getenv("GIN_MODE")
if ginMode == "" {
ginMode = "debug"
}
log.Println("========================================")
log.Printf("🌍 Environment: %s", env)
log.Printf("🚀 GIN_MODE: %s", ginMode)
log.Println("========================================")
fmt.Println()
}
// MARK: Swagger Annotations
//
// These annotations define Scribe Server's API documentation,
// versioning, and contact/license information.
// @title Scribe Server API
// @version 1.0
// @description Scribe-Server is a backend service that provides the API by which data is available for download within Scribe apps.
// @termsOfService https://github.com/scribe-org/Scribe-Server/blob/main/.github/CODE_OF_CONDUCT.md
// @contact.name Scribe Team
// @contact.url https://scri.be/
// @contact.email team@scri.be
// @license.name GPL-3.0 license
// @license.url https://github.com/scribe-org/Scribe-Server/blob/main/LICENSE.txt
// @host scribe-server.toolforge.org
// @BasePath /
// @externalDocs.description GitHub Repository
// @externalDocs.url https://github.com/scribe-org/Scribe-Server
// MARK: Main Entry Point
func main() {
logEnvironment()
// MARK: Config Setup
// Read configuration from file or environment variables.
viper.SetConfigName("config")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
_, configFileNotFound := err.(viper.ConfigFileNotFoundError)
// Config file not found; fall back to environment variables.
if configFileNotFound {
viper.AutomaticEnv()
// Environment variables also not set.
if !viper.IsSet("hostPort") || !viper.IsSet("fileSystem") {
panic(fmt.Errorf("fatal error config environment: %w", err))
}
} else {
// Config file was found, but another error occurred.
panic(fmt.Errorf("fatal error config file: %w", err))
}
}
viper.SetDefault("contractsDir", "./contracts")
// MARK: Start Server
api.HandleRequests()
}