From fd22e783696f2984e0fb252ea7d205576e1d49c7 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 25 Dec 2015 16:35:31 +0100 Subject: WaitGroup --- challange_http.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'challange_http.go') diff --git a/challange_http.go b/challange_http.go index f971d87..7b2de54 100644 --- a/challange_http.go +++ b/challange_http.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "path" + "sync" ) const wellKnown = `/.well-known/acme-challenge/` @@ -18,30 +19,30 @@ func init() { type httpChallenge struct { Challenge Addr string - done chan bool + wg sync.WaitGroup } func (c *httpChallenge) ServeHTTP(w http.ResponseWriter, r *http.Request) { if r.URL.Path == path.Join(wellKnown, c.Token) { io.WriteString(w, c.KeyAuthorization) - c.done <- true + c.wg.Done() } } func (c *httpChallenge) Solve() error { - c.done = make(chan bool) l, err := net.Listen("tcp", c.Addr) if err != nil { return err } defer l.Close() + c.wg.Add(1) go http.Serve(l, c) - <-c.done + c.wg.Wait() return nil } func (c *httpChallenge) Abort() error { - c.done <- true + c.wg.Done() return nil } -- cgit v1.2.3