Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/network/network.go
Jeff Becker 73f77f1624 properly handle os.Interrupt Signal
This makes systemd not put unit into fail mode when stopping

INFO:

* make sure to use signals.RegisterCloser for everything that should be closed on interrupt

* for any net.Listeners created make sure to wrap them with network.WrapListener and register with signals.RegisterCloser
2017-05-10 08:23:29 -04:00

27 lignes
630 o
Go

package network
import (
"fmt"
"github.com/ewhal/nyaa/config"
"github.com/ewhal/nyaa/util/log"
"github.com/majestrate/i2p-tools/lib/i2p"
"net"
)
// CreateHTTPListener creates a net.Listener for main http webapp given main config
func CreateHTTPListener(conf *config.Config) (l net.Listener, err error) {
if conf.I2P == nil {
l, err = net.Listen("tcp", fmt.Sprintf("%s:%d", conf.Host, conf.Port))
} else {
s := i2p.NewSession(conf.I2P.Name, conf.I2P.Addr, conf.I2P.Keyfile)
err = s.Open()
if s != nil {
log.Infof("i2p address: %s", s.B32Addr())
l = s
}
}
if l != nil {
l = WrapListener(l)
}
return
}