Replace explicit channels with functions

This commit is contained in:
Quentin McGaw
2020-07-15 01:34:46 +00:00
parent 8c7c8f7d5a
commit 616ba0c538
7 changed files with 94 additions and 68 deletions

View File

@@ -17,11 +17,11 @@ type Server interface {
type server struct {
address string
logger logging.Logger
restartOpenvpn chan<- struct{}
restartUnbound chan<- struct{}
restartOpenvpn func()
restartUnbound func()
}
func New(address string, logger logging.Logger, restartOpenvpn, restartUnbound chan<- struct{}) Server {
func New(address string, logger logging.Logger, restartOpenvpn, restartUnbound func()) Server {
return &server{
address: address,
logger: logger.WithPrefix("http server: "),
@@ -58,9 +58,9 @@ func (s *server) makeHandler() http.HandlerFunc {
case http.MethodGet:
switch r.RequestURI {
case "/openvpn/actions/restart":
s.restartOpenvpn <- struct{}{}
s.restartOpenvpn()
case "/unbound/actions/restart":
s.restartUnbound <- struct{}{}
s.restartUnbound()
default:
routeDoesNotExist(s.logger, w, r)
}