aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challange_http.go11
1 files changed, 6 insertions, 5 deletions
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
}