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
|
version.go
|
||||||
|
dist/
|
||||||
|
|
|
@ -13,6 +13,7 @@ usage: secure [-addr host:port] -cert certfile -key keyfile upstream
|
||||||
path to cert file
|
path to cert file
|
||||||
-key string
|
-key string
|
||||||
path to key file
|
path to key file
|
||||||
|
-c configfile
|
||||||
upstream string
|
upstream string
|
||||||
upstream url
|
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
|
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"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -16,13 +15,16 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CertFile string `yaml:"certfile"`
|
CertFile string `yaml:"cert"`
|
||||||
KeyFile string `yaml:"keyfile"`
|
KeyFile string `yaml:"key"`
|
||||||
Upstream string `yaml:"upstream"`
|
Upstream string `yaml:"upstream"`
|
||||||
Addr string `yaml:"addr"`
|
Addr string `yaml:"addr"`
|
||||||
}
|
}
|
||||||
|
@ -65,6 +67,10 @@ func getConfig() (config *Config, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cant parse config, %v", err)
|
return nil, fmt.Errorf("cant parse config, %v", err)
|
||||||
}
|
}
|
||||||
|
if _, err := strconv.Atoi(cfg.Addr); err == nil {
|
||||||
|
cfg.Addr = ":" + cfg.Addr
|
||||||
|
|
||||||
|
}
|
||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue