wgliang / pgproxy

PostgreSQL proxy server.
Apache License 2.0
212 stars 37 forks source link

Tl/check if config exists #2

Closed tonylambiris closed 7 years ago

tonylambiris commented 7 years ago

Check to see if the configuration file exists and exit if it doesn't to avoid cluttering up the screen with panic output:

17:47:02 c1-macbook (tl/check-if-config-exists) ~/Documents/Go/src/github.com/tonylambiris/pgproxy $ ./pgproxy
E0430 17:48:21.319894   31550 utils.go:46] stat ./pgproxy.conf: no such file or directory

This changes the default output of

17:48:35 c1-macbook (tl/check-if-config-exists) ~/Documents/Go/src/github.com/tonylambiris/pgproxy $ pgproxy 
F0430 17:48:37.866207   31572 utils.go:44] open ./pgproxy.conf: no such file or directory
goroutine 1 [running]:
github.com/golang/glog.stacks(0xc42008d400, 0xc4200b6420, 0x5a, 0xaf)
    /home/tlambiris/Documents/Go/src/github.com/golang/glog/glog.go:769 +0xa7
github.com/golang/glog.(*loggingT).output(0x825280, 0xc400000003, 0xc4200b6370, 0x7f681e, 0x8, 0x2c, 0x0)
    /home/tlambiris/Documents/Go/src/github.com/golang/glog/glog.go:720 +0x36b
github.com/golang/glog.(*loggingT).println(0x825280, 0x3, 0xc42005fe00, 0x1, 0x1)
    /home/tlambiris/Documents/Go/src/github.com/golang/glog/glog.go:633 +0xe7
github.com/golang/glog.Fatalln(0xc42005fe00, 0x1, 0x1)
    /home/tlambiris/Documents/Go/src/github.com/golang/glog/glog.go:1141 +0x53
github.com/wgliang/pgproxy/cli.readConfig(0x6de653, 0xe, 0xa9000000006c4800, 0x8, 0xc42005fec8, 0x4116fc, 0xc4200a2f60)
    /home/tlambiris/Documents/Go/src/github.com/wgliang/pgproxy/cli/utils.go:44 +0xfd
github.com/wgliang/pgproxy/cli.Main(0x0, 0x0, 0x0, 0x0)
    /home/tlambiris/Documents/Go/src/github.com/wgliang/pgproxy/cli/cli.go:36 +0x4ed
main.main()
    /home/tlambiris/Documents/Go/src/github.com/tonylambiris/pgproxy/main.go:13 +0x45

This pull request also adds a -config flag to give the ability to put the configuration file anywhere, and it also refrains from exiting if the hostname cannot be looked up (sets it to <unknown>)

Thanks!

wgliang commented 7 years ago

Thx and I will merge this PR.