1
0
mirror of https://github.com/gusaul/grpcox.git synced 2024-09-29 04:10:39 +00:00

allow specifying bind address

This commit is contained in:
David Goitia 2021-02-05 20:26:15 +01:00
parent 30fef12ac9
commit f5768c3035
No known key found for this signature in database
GPG Key ID: 7C1B6DE586174DE9
2 changed files with 7 additions and 3 deletions

View File

@ -39,6 +39,7 @@ configure app preferences by editing `config.env` file
|-----------------|---------------------------------------------|--------|--------|
| MAX_LIFE_CONN | maximum idle time connection before closed | number | minute |
| TICK_CLOSE_CONN | ticker interval to sweep expired connection | number | second |
| BIND_ADDR | ip:port to bind service | string | |
set value `0 (zero)` to disable auto close idle connection.

View File

@ -25,20 +25,23 @@ func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
// start app
port := ":6969"
addr := "0.0.0.0:6969"
if value, ok := os.LookupEnv("BIND_ADDR"); ok {
addr = value
}
muxRouter := mux.NewRouter()
handler.Init(muxRouter)
var wait time.Duration = time.Second * 15
srv := &http.Server{
Addr: "0.0.0.0" + port,
Addr: addr,
WriteTimeout: time.Second * 15,
ReadTimeout: time.Second * 15,
IdleTimeout: time.Second * 60,
Handler: muxRouter,
}
fmt.Println("Service started on", port)
fmt.Println("Service started on", addr)
go func() {
log.Fatal(srv.ListenAndServe())
}()