Migrate to go modules
Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
parent
d3f0e63e03
commit
95084c73c5
24 changed files with 30 additions and 91 deletions
|
@ -1,2 +0,0 @@
|
|||
gowerc
|
||||
|
10
LICENSE
Normal file
10
LICENSE
Normal file
|
@ -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.
|
Binary file not shown.
8
go.mod
Normal file
8
go.mod
Normal file
|
@ -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
|
||||
)
|
4
go.sum
Normal file
4
go.sum
Normal file
|
@ -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=
|
|
@ -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
|
||||
}
|
12
main.go
12
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)
|
||||
|
|
4
root/etc/config.json
Normal file
4
root/etc/config.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"mastersite": "example.com"
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"mastersite": "offblast.org"
|
||||
}
|
||||
|
Loading…
Reference in a new issue