aboutsummaryrefslogtreecommitdiff
path: root/solver.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-01-13 20:14:08 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-01-13 20:14:08 +0100
commit92023bf6e060e2adf240964d2d7589c43eca7f75 (patch)
tree3c1cc8901c13dd7f7dc6ab8b45e8eb7a6f773da4 /solver.go
parente7c8224a468b860ff21fa04ad00a3d74a5ea91e7 (diff)
Not sure where to put it
Diffstat (limited to 'solver.go')
-rw-r--r--solver.go45
1 files changed, 45 insertions, 0 deletions
diff --git a/solver.go b/solver.go
new file mode 100644
index 0000000..5bc7f85
--- /dev/null
+++ b/solver.go
@@ -0,0 +1,45 @@
+package acme
+
+import (
+ "io"
+ "net/http"
+ "path"
+)
+
+type httpSolver struct {
+ http.Server
+}
+
+func NewHTTPSolver(addr string) Solver {
+ var s httpSolver
+ s.Server = http.Server{Addr: addr}
+ go s.ListenAndServe()
+ return &s
+}
+
+func (s httpSolver) Solve(token, keyAuth string) error {
+ p := path.Join(WellKnown, token)
+ http.HandleFunc(p, func(w http.ResponseWriter, r *http.Request) {
+ io.WriteString(w, keyAuth)
+ })
+ return nil
+}
+
+type webRootSolver struct {
+ webroot string
+}
+
+func NewWebRootSolver(webroot string) Solver {
+ return &webRootSolver{webroot}
+}
+
+func (s webRootSolver) Solve(token, keyAuth string) error {
+ p := path.Join(s.webroot, WellKnown, token)
+ fd, err := CreatePubFile(p)
+ if err != nil {
+ return err
+ }
+ defer fd.Close()
+ _, err = io.WriteString(fd, keyAuth)
+ return err
+}