diff options
-rw-r--r-- | .build.yml | 26 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | cmd/example/example.go | 2 | ||||
-rw-r--r-- | go.mod | 7 | ||||
-rw-r--r-- | go.sum | 3 | ||||
-rw-r--r-- | server.go | 19 |
7 files changed, 26 insertions, 39 deletions
diff --git a/.build.yml b/.build.yml deleted file mode 100644 index 0b1a1ff..0000000 --- a/.build.yml +++ /dev/null @@ -1,26 +0,0 @@ -image: fedora/latest -packages: - - go -sources: - - https://git.sr.ht/~yotam/go-gemini - - https://git.sr.ht/~sircmpwn/annotatego -secrets: - - f43da1db-697d-4101-8607-e96f574b035a -tasks: -- lint: | - cd go-gemini - go vet -- test: | - cd go-gemini - go test -- build: | - cd go-gemini - make -- annotatego: | - cd annotatego - go build - sudo cp annotatego /usr/bin/ -- annotate: | - cd go-gemini - annotatego -v git.sr.ht/~yotam/go-gemini... >annotations.json - ~/upload-annotations annotations.json yotam go-gemini @@ -3,7 +3,7 @@ all: build build: gemini-example gemini-example: cmd/example/*.go *.go - go build -o gemini-example git.sr.ht/~yotam/go-gemini/cmd/example + go build -o gemini-example sanctum.geek.nz/code/go-gemini.git/cmd/example clean: rm -rf gemini-example @@ -14,3 +14,9 @@ The repository comes with an example server that respond with an hardcoded text to the root page. To build the server run the following command: make build + +Fork +---- + +This is a fork by Tom Ryder <tom@sanctum.geek.nz> that replaces the default +listening socket with systemd activation. diff --git a/cmd/example/example.go b/cmd/example/example.go index 6e7ece2..49d3090 100644 --- a/cmd/example/example.go +++ b/cmd/example/example.go @@ -6,7 +6,7 @@ import ( "net/url" "strings" - gemini "git.sr.ht/~yotam/go-gemini" + gemini "sanctum.geek.nz/code/go-gemini.git" ) type ExampleHandler struct { @@ -1,5 +1,8 @@ -module git.sr.ht/~yotam/go-gemini +module sanctum.geek.nz/code/go-gemini.git.git go 1.12 -require github.com/google/go-cmp v0.3.1 +require ( + github.com/coreos/go-systemd/v22 v22.1.0 + github.com/google/go-cmp v0.3.1 +) @@ -1,2 +1,5 @@ +github.com/coreos/go-systemd/v22 v22.1.0 h1:kq/SbG2BCKLkDKkjQf5OWwKWUKj1lgs3lFI4PxnR5lg= +github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= +github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= @@ -4,6 +4,7 @@ import ( "bufio" "crypto/tls" "fmt" + "github.com/coreos/go-systemd/v22/activation" "io" "net" "strings" @@ -23,15 +24,18 @@ type Handler interface { // new connections to the given handler. // Each request is handled in a separate goroutine. func ListenAndServe(addr, certFile, keyFile string, handler Handler) error { - if addr == "" { - addr = "127.0.0.1:1965" + listeners, err := activation.Listeners() + if err != nil { + return err + } + if len(listeners) != 1 { + return err } - listener, err := listen(addr, certFile, keyFile) + listener, err := listen(listeners[0], certFile, keyFile) if err != nil { return err } - err = serve(listener, handler) if err != nil { return err @@ -45,17 +49,14 @@ func ListenAndServe(addr, certFile, keyFile string, handler Handler) error { return nil } -func listen(addr, certFile, keyFile string) (net.Listener, error) { +func listen(listener net.Listener, certFile, keyFile string) (net.Listener, error) { cer, err := tls.LoadX509KeyPair(certFile, keyFile) if err != nil { return nil, fmt.Errorf("failed to load certificates: %v", err) } config := &tls.Config{Certificates: []tls.Certificate{cer}} - ln, err := tls.Listen("tcp", addr, config) - if err != nil { - return nil, fmt.Errorf("failed to listen: %v", err) - } + ln := tls.NewListener(listener, config) return ln, nil } |