From 3c2bac1b29d8072ba9de58a0ece472c1c4eb45b3 Mon Sep 17 00:00:00 2001 From: ddvk Date: Mon, 27 Sep 2021 00:23:11 +0200 Subject: [PATCH] add doc for config --- .gitignore | 1 + README.md | 8 ++++++++ main.go | 12 +++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f53f6d3..7bf263a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ version.go +dist/ diff --git a/README.md b/README.md index 4653e81..29d2f37 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ usage: secure [-addr host:port] -cert certfile -key keyfile upstream path to cert file -key string path to key file + -c configfile upstream string upstream url ``` @@ -22,3 +23,10 @@ usage: secure [-addr host:port] -cert certfile -key keyfile upstream secure -cert cert.pem -key key.pem http://localhost:6060 ``` +## Configfile +```yaml +cert: proxy.crt +key: proxy.key +upstream: https://somehost:123 +addr: 8080 +``` diff --git a/main.go b/main.go index 87c0a10..5c30780 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "context" "flag" "fmt" - "gopkg.in/yaml.v3" "io/ioutil" "log" "net/http" @@ -16,13 +15,16 @@ import ( "os" "os/signal" "path/filepath" + "strconv" "strings" "syscall" + + "gopkg.in/yaml.v3" ) type Config struct { - CertFile string `yaml:"certfile"` - KeyFile string `yaml:"keyfile"` + CertFile string `yaml:"cert"` + KeyFile string `yaml:"key"` Upstream string `yaml:"upstream"` Addr string `yaml:"addr"` } @@ -65,6 +67,10 @@ func getConfig() (config *Config, err error) { if err != nil { return nil, fmt.Errorf("cant parse config, %v", err) } + if _, err := strconv.Atoi(cfg.Addr); err == nil { + cfg.Addr = ":" + cfg.Addr + + } return &cfg, nil }