1
0
mirror of https://github.com/gusaul/grpcox.git synced 2024-11-17 06:26:56 +00:00

Merge pull request #29 from davidgoitia/env_bind_address

allow specifying bind address
This commit is contained in:
Muhammad Auliya 2021-02-16 17:47:07 +07:00 committed by GitHub
commit 6eccacc39f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 | | MAX_LIFE_CONN | maximum idle time connection before closed | number | minute |
| TICK_CLOSE_CONN | ticker interval to sweep expired connection | number | second | | 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. set value `0 (zero)` to disable auto close idle connection.

View File

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