summaryrefslogtreecommitdiff
path: root/examples
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
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')
-rw-r--r--examples/cgi/main.go4
-rw-r--r--examples/cowsay/main.go2
-rw-r--r--examples/fileserver/main.go8
-rw-r--r--examples/gopher_fileserver/main.go33
-rw-r--r--examples/inspectls/main.go2
5 files changed, 41 insertions, 8 deletions
diff --git a/examples/cgi/main.go b/examples/cgi/main.go
index 6036454..5c1b9a2 100644
--- a/examples/cgi/main.go
+++ b/examples/cgi/main.go
@@ -23,7 +23,7 @@ func main() {
}
// make use of a CGI request handler
- cgiHandler := cgi.CGIDirectory("/cgi-bin", "./cgi-bin")
+ cgiHandler := cgi.GeminiCGIDirectory("/cgi-bin", "./cgi-bin")
_, infoLog, _, errLog := logging.DefaultLoggers()
@@ -35,7 +35,7 @@ func main() {
defer stop()
// run the server
- server, err := gemini.NewServer(ctx, errLog, tlsconf, "tcp4", ":1965", handler)
+ server, err := gemini.NewServer(ctx, "localhost", "tcp4", ":1965", handler, errLog, tlsconf)
if err != nil {
log.Fatal(err)
}
diff --git a/examples/cowsay/main.go b/examples/cowsay/main.go
index b239019..4a3f980 100644
--- a/examples/cowsay/main.go
+++ b/examples/cowsay/main.go
@@ -29,7 +29,7 @@ func main() {
handler := logging.LogRequests(infoLog)(cowsayHandler)
// run the server
- server, err := gemini.NewServer(context.Background(), errLog, tlsconf, "tcp4", ":1965", handler)
+ server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, errLog, tlsconf)
if err != nil {
log.Fatal(err)
}
diff --git a/examples/fileserver/main.go b/examples/fileserver/main.go
index e70974f..be427a1 100644
--- a/examples/fileserver/main.go
+++ b/examples/fileserver/main.go
@@ -26,11 +26,11 @@ func main() {
// Fallthrough tries each handler in succession until it gets something other than "51 Not Found"
handler := gus.FallthroughHandler(
// first see if they're fetching a directory and we have <dir>/index.gmi
- fs.DirectoryDefault(fileSystem, "index.gmi"),
+ fs.GeminiDirectoryDefault(fileSystem, "index.gmi"),
// next (still if they requested a directory) build a directory listing response
- fs.DirectoryListing(fileSystem, nil),
+ fs.GeminiDirectoryListing(fileSystem, nil),
// finally, try to find a file at the request path and respond with that
- fs.FileHandler(fileSystem),
+ fs.GeminiFileHandler(fileSystem),
)
_, infoLog, _, errLog := logging.DefaultLoggers()
@@ -39,7 +39,7 @@ func main() {
handler = logging.LogRequests(infoLog)(handler)
// run the server
- server, err := gemini.NewServer(context.Background(), errLog, tlsconf, "tcp4", ":1965", handler)
+ server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, errLog, tlsconf)
if err != nil {
log.Fatal(err)
}
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()
+}
diff --git a/examples/inspectls/main.go b/examples/inspectls/main.go
index 5022888..ce82f43 100644
--- a/examples/inspectls/main.go
+++ b/examples/inspectls/main.go
@@ -33,7 +33,7 @@ func main() {
handler := logging.LogRequests(infoLog)(inspectHandler)
// run the server
- server, err := gemini.NewServer(context.Background(), errLog, tlsconf, "tcp4", ":1965", handler)
+ server, err := gemini.NewServer(context.Background(), "localhost", "tcp4", ":1965", handler, errLog, tlsconf)
if err != nil {
log.Fatal(err)
}