feat: add tls server binder
This commit is contained in:
parent
3f8590d96c
commit
982182d231
5 changed files with 44 additions and 7 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -5,3 +5,7 @@ public/
|
|||
|
||||
config.toml
|
||||
!config.sample.toml
|
||||
|
||||
*.key
|
||||
*.pem
|
||||
*.csr
|
||||
|
|
26
app.go
26
app.go
|
@ -31,11 +31,29 @@ func daemon(n *commando.Node) error {
|
|||
return fmt.Errorf("unknown environment: %s", cnf.Environment)
|
||||
}
|
||||
|
||||
app := gin.Default()
|
||||
app.StaticFS("/", gin.Dir("public/", false))
|
||||
fmt.Printf("Current Environment: %s\n", cnf.Environment)
|
||||
|
||||
fmt.Printf("web server binding at: http://%s:%d\n", cnf.Service.Host, cnf.Service.Port)
|
||||
if err = app.Run(fmt.Sprintf("%s:%d", cnf.Service.Host, cnf.Service.Port)); err != nil {
|
||||
app := gin.Default()
|
||||
app.StaticFS("/", gin.Dir(cnf.Service.Index, false))
|
||||
|
||||
if !cnf.Service.TLS {
|
||||
fmt.Printf("web server binding at: http://%s:%d\n", cnf.Service.Host, cnf.Service.Port)
|
||||
if err = app.Run(fmt.Sprintf("%s:%d", cnf.Service.Host, cnf.Service.Port)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
key := cnf.Service.TLSOpt.KeyFile
|
||||
cert := cnf.Service.TLSOpt.CertFile
|
||||
|
||||
fmt.Printf("Key File: %s\n", cnf.Service.TLSOpt.KeyFile)
|
||||
fmt.Printf("Cert File: %s\n", cnf.Service.TLSOpt.CertFile)
|
||||
fmt.Printf("web server binding TLS at: https://%s:%d\n", cnf.Service.Host, cnf.Service.Port)
|
||||
|
||||
if err = app.RunTLS(
|
||||
fmt.Sprintf("%s:%d", cnf.Service.Host, cnf.Service.Port), cert, key); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -2,5 +2,12 @@
|
|||
environment = "development"
|
||||
|
||||
[service]
|
||||
index = "public/"
|
||||
host = "0.0.0.0"
|
||||
port = 8080
|
||||
tls = false
|
||||
|
||||
[service.tls-opt]
|
||||
key_file = ""
|
||||
cert_file = ""
|
||||
|
||||
|
|
|
@ -13,8 +13,16 @@ type Config struct {
|
|||
}
|
||||
|
||||
type ServiceConfig struct {
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
Index string `toml:"index"`
|
||||
Host string `toml:"host"`
|
||||
Port int `toml:"port"`
|
||||
TLS bool `toml:"tls"`
|
||||
TLSOpt TLSOption `toml:"tls-opt"`
|
||||
}
|
||||
|
||||
type TLSOption struct {
|
||||
KeyFile string `toml:"key-file"`
|
||||
CertFile string `toml:"cert-file"`
|
||||
}
|
||||
|
||||
var version *string
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"version": "0.1.0-alpha"
|
||||
"version": "0.2.0-alpha"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue