aboutsummaryrefslogtreecommitdiff
path: root/challange_http.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-25 16:35:31 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-25 16:35:31 +0100
commitfd22e783696f2984e0fb252ea7d205576e1d49c7 (patch)
tree94a7c84e47a6a44603f80d6237376ec8bc7c09d9 /challange_http.go
parent1e28cc43c5691f90aae4d2b77e5ecaf52432f2eb (diff)
WaitGroup
Diffstat (limited to 'challange_http.go')
-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
}