Skip to content

Commit

Permalink
feat(runner): implement TLS server
Browse files Browse the repository at this point in the history
  • Loading branch information
dwisiswant0 committed Jul 11, 2023
1 parent e9fafe4 commit 7b7baa9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions internal/runner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
func ParseOptions() *common.Options {
opt := &common.Options{}
cfg := &common.Config{}
tls := &common.TLS{}

flag.IntVar(&opt.Port, "p", 1337, "")
flag.IntVar(&opt.Port, "port", 1337, "")
Expand All @@ -23,6 +24,9 @@ func ParseOptions() *common.Options {
flag.StringVar(&cfg.Format, "f", "yaml", "")
flag.StringVar(&cfg.Format, "format", "yaml", "")

flag.StringVar(&tls.CertPath, "cert", "", "")
flag.StringVar(&tls.KeyPath, "key", "", "")

flag.BoolVar(&version, "V", false, "")
flag.BoolVar(&version, "version", false, "")

Expand All @@ -45,6 +49,7 @@ func ParseOptions() *common.Options {
common.PrintBanner()

opt.Config = cfg
opt.TLS = tls

return opt
}
22 changes: 19 additions & 3 deletions internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,25 @@ func New(opt *common.Options) error {
}

func (r *Runner) start() error {
log.Info("Server started", "port", r.Options.Port, "pid", os.Getpid())
var err error

cert := r.Options.TLS.CertPath
key := r.Options.TLS.KeyPath
tls := (cert != "" && key != "")

log.Info(
"Server started!",
"port", r.Options.Port,
"tls", tls,
"pid", os.Getpid(),
)

if tls {
err = r.Server.ListenAndServeTLS(cert, key)
} else {
err = r.Server.ListenAndServe()
}

err := r.Server.ListenAndServe()
if err != nil && err != http.ErrServerClosed {
return err
}
Expand All @@ -111,7 +127,7 @@ func (r *Runner) shutdown() error {
}

func (r *Runner) restart() error {
log.Info("Restarting server...")
log.Info("Restarting...")

if err := r.shutdown(); err != nil {
return err
Expand Down

0 comments on commit 7b7baa9

Please sign in to comment.