diff --git a/README.md b/README.md index 8e52a2f..c25f788 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/grpcox.go b/grpcox.go index e10204a..47199bd 100644 --- a/grpcox.go +++ b/grpcox.go @@ -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()) }()