mirror of
https://github.com/gusaul/grpcox.git
synced 2024-12-24 09:20:41 +00:00
allow specifying bind address
This commit is contained in:
parent
30fef12ac9
commit
f5768c3035
|
@ -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.
|
||||
|
||||
|
|
|
@ -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())
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue
Block a user