This repository has been archived on 2023-05-01. You can view files and clone it, but cannot push or open issues or pull requests.
gus/examples/gopher_fileserver/main.go

34 lines
742 B
Go

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()
}