HTTP Serverの止め方
結合テストの際にHTTP Serverを立ち上げて、テストが終わったらListenをやめる、というのをやりたかったので調べた。下のようにしてStopさせてみた。
hydrogen18/stoppableListener · GitHub では StoppableListenerを実装していて、net.TCPListenerにstopのchannelをあわせたものをListenerとして定義している。StoppableListener.Stop()するとstop channelがcloseされて、Listenerも閉じられる。
参考: Stopping a listening HTTP Server in Go - Eric's Apparatus