summaryrefslogtreecommitdiff
path: root/examples/gopher_fileserver/main.go
diff options
context:
space:
mode:
authortjpcc <tjp@ctrl-c.club>2023-01-28 14:52:35 -0700
committertjpcc <tjp@ctrl-c.club>2023-01-28 15:01:41 -0700
commit66a1b1f39a1e1d5499b548b36d18c8daa872d7da (patch)
tree96471dbd5486ede1a908790ac23e0c55b226dfad /examples/gopher_fileserver/main.go
parenta27b879accb191b6a6c6e76a6251ed751967f73a (diff)
gopher support.
Some of the contrib packages were originally built gemini-specific and had to be refactored into generic core functionality and thin protocol-specific wrappers for each of gemini and gopher.
Diffstat (limited to 'examples/gopher_fileserver/main.go')
-rw-r--r--examples/gopher_fileserver/main.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/gopher_fileserver/main.go b/examples/gopher_fileserver/main.go
new file mode 100644
index 0000000..172ca87
--- /dev/null
+++ b/examples/gopher_fileserver/main.go
@@ -0,0 +1,33 @@
+package main
+
+import (
+ "context"
+ "log"
+ "os"
+
+ "tildegit.org/tjp/gus"
+ "tildegit.org/tjp/gus/contrib/cgi"
+ "tildegit.org/tjp/gus/contrib/fs"
+ "tildegit.org/tjp/gus/gopher"
+ "tildegit.org/tjp/gus/logging"
+)
+
+func main() {
+ fileSystem := os.DirFS(".")
+
+ handler := gus.FallthroughHandler(
+ fs.GopherDirectoryDefault(fileSystem, "index.gophermap"),
+ fs.GopherDirectoryListing(fileSystem, nil),
+ cgi.GopherCGIDirectory("/cgi-bin", "./cgi-bin"),
+ fs.GopherFileHandler(fileSystem),
+ )
+
+ _, infoLog, _, errLog := logging.DefaultLoggers()
+ handler = logging.LogRequests(infoLog)(handler)
+
+ server, err := gopher.NewServer(context.Background(), "localhost", "tcp4", ":70", handler, errLog)
+ if err != nil {
+ log.Fatal(err)
+ }
+ server.Serve()
+}