From 95084c73c585b23cd3e13a9afed11f037e5ae147 Mon Sep 17 00:00:00 2001
From: Sam Therapy <sam@samtherapy.net>
Date: Sun, 10 Jul 2022 15:57:19 +0200
Subject: [PATCH] Migrate to go modules

Signed-off-by: Sam Therapy <sam@samtherapy.net>
---
 .hgignore                                     |   2 -
 LICENSE                                       |  10 +++
 fixtures/site.zip                             | Bin 920 -> 0 bytes
 go.mod                                        |   8 ++
 go.sum                                        |   4 +
 letsencrypt.go                                |  77 ------------------
 main.go                                       |  12 +--
 root/etc/config.json                          |   4 +
 {werc => root}/lib/base.html                  |   0
 {werc => root}/lib/directory.html             |   0
 {werc => root}/lib/footer.html                |   0
 {werc => root}/lib/menu.html                  |   0
 {werc => root}/lib/text.html                  |   0
 {werc => root}/lib/topbar.html                |   0
 {werc => root}/pub/style/style.css            |   0
 .../sites/example.com}/_werc/config.json      |   0
 .../sites/example.com}/_werc/pub/style.css    |   0
 .../sites/example.com}/foo/bar.md             |   0
 .../sites/example.com}/index.md               |   0
 .../sites/example.com}/test/apage.md          |   0
 .../sites/example.com}/test/coolhtml.html     |   0
 .../sites/example.com}/test/file.txt          |   0
 .../sites/example.com}/test/index.md          |   0
 werc/etc/config.json                          |   4 -
 24 files changed, 30 insertions(+), 91 deletions(-)
 delete mode 100644 .hgignore
 create mode 100644 LICENSE
 delete mode 100644 fixtures/site.zip
 create mode 100644 go.mod
 create mode 100644 go.sum
 delete mode 100644 letsencrypt.go
 create mode 100644 root/etc/config.json
 rename {werc => root}/lib/base.html (100%)
 rename {werc => root}/lib/directory.html (100%)
 rename {werc => root}/lib/footer.html (100%)
 rename {werc => root}/lib/menu.html (100%)
 rename {werc => root}/lib/text.html (100%)
 rename {werc => root}/lib/topbar.html (100%)
 rename {werc => root}/pub/style/style.css (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/_werc/config.json (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/_werc/pub/style.css (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/foo/bar.md (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/index.md (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/test/apage.md (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/test/coolhtml.html (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/test/file.txt (100%)
 rename {werc/sites/offblast.org => root/sites/example.com}/test/index.md (100%)
 delete mode 100644 werc/etc/config.json

diff --git a/.hgignore b/.hgignore
deleted file mode 100644
index 72cf6d1..0000000
--- a/.hgignore
+++ /dev/null
@@ -1,2 +0,0 @@
-gowerc
-
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d2a45fa
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,10 @@
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/fixtures/site.zip b/fixtures/site.zip
deleted file mode 100644
index 411444199d97dc2d6a1e4a7d7bb6a6c95bd8cb2c..0000000000000000000000000000000000000000
GIT binary patch
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..f008014
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,8 @@
+module git.froth.zone/sam/go2werc
+
+go 1.18
+
+require (
+	github.com/russross/blackfriday/v2 v2.1.0
+	golang.org/x/tools v0.1.11
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..67ad0d8
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,4 @@
+github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
+github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY=
+golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4=
diff --git a/letsencrypt.go b/letsencrypt.go
deleted file mode 100644
index d7f9fbe..0000000
--- a/letsencrypt.go
+++ /dev/null
@@ -1,77 +0,0 @@
-package main
-
-import (
-	"crypto/tls"
-	"errors"
-	"flag"
-	"net"
-	"strings"
-
-	"github.com/dkumor/acmewrapper"
-)
-
-var (
-	letsencrypt = flag.Bool("letsencrypt", false, "enable Let’s Encrypt")
-	domainname  = flag.String("domain", "", "domain for certificate")
-	sannames    = flag.String("sans", "", "comma-seperate list of subject alternate names for certificate")
-	certfile    = flag.String("cert", "", "TLS cert file path")
-	keyfile     = flag.String("key", "", "TLS key file path")
-	regfile     = flag.String("reg", "", "user registration file path")
-	privfile    = flag.String("priv", "", "user private key file path")
-	test        = flag.Bool("test", false, "Use the Let's Encrypt staging server")
-	acme        = flag.String("server", acmewrapper.DefaultServer, "The ACME server to use")
-	accept      = flag.Bool("accept", false, "Accept the ACME server's TOS?")
-	email       = flag.String("email", "", "The email to use when registering")
-
-	ErrDisabled = errors.New("Let's Encrypt is disabled")
-)
-
-// setup a tls listener and config from let's encrypt settings.
-//
-// TODO(mischief): http redirect to https
-func doTLS(addr string) (net.Listener, *tls.Config, error) {
-	if *letsencrypt == false {
-		return nil, nil, ErrDisabled
-	}
-
-	if *test {
-		*acme = "https://acme-staging.api.letsencrypt.org/directory"
-	}
-
-	domains := []string{*domainname}
-
-	if *sannames != "" {
-		sans := strings.Split(*sannames, ",")
-		domains = append(domains, sans...)
-	}
-
-	aconf := acmewrapper.Config{
-		Address:          addr,
-		Domains:          domains,
-		Email:            *email,
-		TLSCertFile:      *certfile,
-		TLSKeyFile:       *keyfile,
-		RegistrationFile: *regfile,
-		PrivateKeyFile:   *privfile,
-		Server:           *acme,
-		TOSCallback:      acmewrapper.TOSAgree,
-	}
-
-	if *accept == false {
-		aconf.TOSCallback = acmewrapper.TOSDecline
-	}
-
-	w, err := acmewrapper.New(aconf)
-	if err != nil {
-		return nil, nil, err
-	}
-
-	tlsconfig := w.TLSConfig()
-
-	listener, err := tls.Listen("tcp", addr, tlsconfig)
-	if err != nil {
-		return nil, nil, err
-	}
-
-	return listener, tlsconfig, nil
-}
diff --git a/main.go b/main.go
index 80c127a..e914cee 100644
--- a/main.go
+++ b/main.go
@@ -18,12 +18,12 @@ import (
 	"strings"
 	"time"
 
-	"github.com/russross/blackfriday"
+	"github.com/russross/blackfriday/v2"
 )
 
 var (
 	listen = flag.String("l", ":8080", "set http listener to [ip]:port")
-	root   = flag.String("root", "werc", "werc webroot")
+	root   = flag.String("root", "root", "werc webroot")
 
 	indexFiles = []string{"index", "README"}
 )
@@ -294,7 +294,7 @@ func (werc *Werc) WercMd(w http.ResponseWriter, r *http.Request, site, path stri
 		http.Error(w, fmt.Sprintf("%s", err), 404)
 		return
 	}
-	md := blackfriday.MarkdownCommon(b)
+	md := blackfriday.Run(b)
 	werc.WercCommon(w, r, site, &WercPage{Title: ptitle(path), Content: template.HTML(string(md))})
 }
 
@@ -462,11 +462,7 @@ func main() {
 	var tlsconf *tls.Config
 	var err error
 
-	if *letsencrypt {
-		listener, tlsconf, err = doTLS(*listen)
-	} else {
-		listener, err = net.Listen("tcp", *listen)
-	}
+	listener, err = net.Listen("tcp", *listen)
 
 	if err != nil {
 		log.Fatal(err)
diff --git a/root/etc/config.json b/root/etc/config.json
new file mode 100644
index 0000000..d0f0ba0
--- /dev/null
+++ b/root/etc/config.json
@@ -0,0 +1,4 @@
+{
+    "mastersite": "example.com"
+}
+
diff --git a/werc/lib/base.html b/root/lib/base.html
similarity index 100%
rename from werc/lib/base.html
rename to root/lib/base.html
diff --git a/werc/lib/directory.html b/root/lib/directory.html
similarity index 100%
rename from werc/lib/directory.html
rename to root/lib/directory.html
diff --git a/werc/lib/footer.html b/root/lib/footer.html
similarity index 100%
rename from werc/lib/footer.html
rename to root/lib/footer.html
diff --git a/werc/lib/menu.html b/root/lib/menu.html
similarity index 100%
rename from werc/lib/menu.html
rename to root/lib/menu.html
diff --git a/werc/lib/text.html b/root/lib/text.html
similarity index 100%
rename from werc/lib/text.html
rename to root/lib/text.html
diff --git a/werc/lib/topbar.html b/root/lib/topbar.html
similarity index 100%
rename from werc/lib/topbar.html
rename to root/lib/topbar.html
diff --git a/werc/pub/style/style.css b/root/pub/style/style.css
similarity index 100%
rename from werc/pub/style/style.css
rename to root/pub/style/style.css
diff --git a/werc/sites/offblast.org/_werc/config.json b/root/sites/example.com/_werc/config.json
similarity index 100%
rename from werc/sites/offblast.org/_werc/config.json
rename to root/sites/example.com/_werc/config.json
diff --git a/werc/sites/offblast.org/_werc/pub/style.css b/root/sites/example.com/_werc/pub/style.css
similarity index 100%
rename from werc/sites/offblast.org/_werc/pub/style.css
rename to root/sites/example.com/_werc/pub/style.css
diff --git a/werc/sites/offblast.org/foo/bar.md b/root/sites/example.com/foo/bar.md
similarity index 100%
rename from werc/sites/offblast.org/foo/bar.md
rename to root/sites/example.com/foo/bar.md
diff --git a/werc/sites/offblast.org/index.md b/root/sites/example.com/index.md
similarity index 100%
rename from werc/sites/offblast.org/index.md
rename to root/sites/example.com/index.md
diff --git a/werc/sites/offblast.org/test/apage.md b/root/sites/example.com/test/apage.md
similarity index 100%
rename from werc/sites/offblast.org/test/apage.md
rename to root/sites/example.com/test/apage.md
diff --git a/werc/sites/offblast.org/test/coolhtml.html b/root/sites/example.com/test/coolhtml.html
similarity index 100%
rename from werc/sites/offblast.org/test/coolhtml.html
rename to root/sites/example.com/test/coolhtml.html
diff --git a/werc/sites/offblast.org/test/file.txt b/root/sites/example.com/test/file.txt
similarity index 100%
rename from werc/sites/offblast.org/test/file.txt
rename to root/sites/example.com/test/file.txt
diff --git a/werc/sites/offblast.org/test/index.md b/root/sites/example.com/test/index.md
similarity index 100%
rename from werc/sites/offblast.org/test/index.md
rename to root/sites/example.com/test/index.md
diff --git a/werc/etc/config.json b/werc/etc/config.json
deleted file mode 100644
index 49016b2..0000000
--- a/werc/etc/config.json
+++ /dev/null
@@ -1,4 +0,0 @@
-{
-    "mastersite": "offblast.org"
-}
-
