File tree Expand file tree Collapse file tree 3 files changed +33
-10
lines changed Expand file tree Collapse file tree 3 files changed +33
-10
lines changed Original file line number Diff line number Diff line change @@ -71,11 +71,6 @@ func main() {
71
71
}
72
72
73
73
// Start API listener
74
- logger .Infof (
75
- "starting API listener on %s:%d" ,
76
- cfg .Api .ListenAddress ,
77
- cfg .Api .ListenPort ,
78
- )
79
74
if err := api .Start (cfg ); err != nil {
80
75
logger .Fatalf ("failed to start API: %s" , err )
81
76
}
Original file line number Diff line number Diff line change @@ -35,6 +35,21 @@ import (
35
35
)
36
36
37
37
func Start (cfg * config.Config ) error {
38
+ // Standard logging
39
+ logger := logging .GetLogger ()
40
+ if cfg .Tls .CertFilePath != "" && cfg .Tls .KeyFilePath != "" {
41
+ logger .Infof (
42
+ "starting API TLS listener on %s:%d" ,
43
+ cfg .Api .ListenAddress ,
44
+ cfg .Api .ListenPort ,
45
+ )
46
+ } else {
47
+ logger .Infof (
48
+ "starting API listener on %s:%d" ,
49
+ cfg .Api .ListenAddress ,
50
+ cfg .Api .ListenPort ,
51
+ )
52
+ }
38
53
// Disable gin debug output
39
54
gin .SetMode (gin .ReleaseMode )
40
55
gin .DisableConsoleColor ()
@@ -52,11 +67,18 @@ func Start(cfg *config.Config) error {
52
67
router .GET ("/healthcheck" , handleHealthcheck )
53
68
router .POST ("/api/submit/tx" , handleSubmitTx )
54
69
55
- // Start listener
56
- err := router .Run (
57
- fmt .Sprintf ("%s:%d" , cfg .Api .ListenAddress , cfg .Api .ListenPort ),
58
- )
59
- return err
70
+ // Start API listener
71
+ if cfg .Tls .CertFilePath != "" && cfg .Tls .KeyFilePath != "" {
72
+ return router .RunTLS (
73
+ fmt .Sprintf ("%s:%d" , cfg .Api .ListenAddress , cfg .Api .ListenPort ),
74
+ cfg .Tls .CertFilePath ,
75
+ cfg .Tls .KeyFilePath ,
76
+ )
77
+ } else {
78
+ return router .Run (fmt .Sprintf ("%s:%d" ,
79
+ cfg .Api .ListenAddress ,
80
+ cfg .Api .ListenPort ))
81
+ }
60
82
}
61
83
62
84
func handleHealthcheck (c * gin.Context ) {
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import (
25
25
type Config struct {
26
26
Logging LoggingConfig `yaml:"logging"`
27
27
Api ApiConfig `yaml:"api"`
28
+ Tls TlsConfig `yaml:"tls"`
28
29
Backends []string `yaml:"backends" envconfig:"BACKENDS"`
29
30
}
30
31
@@ -38,6 +39,11 @@ type ApiConfig struct {
38
39
ClientTimeout uint `yaml:"client_timeout" envconfig:"CLIENT_TIMEOUT"`
39
40
}
40
41
42
+ type TlsConfig struct {
43
+ CertFilePath string `yaml:"certFilePath" envconfig:"TLS_CERT_FILE_PATH"`
44
+ KeyFilePath string `yaml:"keyFilePath" envconfig:"TLS_KEY_FILE_PATH"`
45
+ }
46
+
41
47
// Singleton config instance with default values
42
48
var globalConfig = & Config {
43
49
Logging : LoggingConfig {
You can’t perform that action at this time.
0 commit comments