add doc for config
This commit is contained in:
parent
a6a59b1c3a
commit
3c2bac1b29
3 changed files with 18 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
version.go
|
||||
dist/
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
12
main.go
12
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue