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
|
/**
* ConfigService - configservice
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Paolo Lulli <kevwe.com>
* @copyright Paolo Lulli 2022-2024
*/
package main
import (
"fmt"
"os"
"github.com/gin-gonic/gin"
)
func main() {
var instanceName string
args := os.Args
if len(args) < 2 {
instanceName = "default"
fmt.Println("Loading default config")
} else {
instanceName = args[1]
fmt.Printf("Loading instance: [%s] config", instanceName)
}
cfg, err := LoadConfig(os.Getenv("HOME") + "/.config/cfg-service-" + instanceName + ".cfg")
if err != nil {
fmt.Println("Could not load config file", err)
os.Exit(1)
}
fmt.Println(instanceName)
router := gin.Default()
router.SetTrustedProxies([]string{"127.0.0.1"})
gin.SetMode(gin.ReleaseMode)
router.GET("/secret/:secretname", ReadSecret(cfg))
if cfg.ServerTLSCertificate == "" || cfg.ServerTLSKey == "" {
router.Run(cfg.Endpoint)
} else {
router.RunTLS(cfg.Endpoint, cfg.ServerTLSCertificate, cfg.ServerTLSKey)
}
}
|