MCPcopy
hub / github.com/writefreely/writefreely / handleGopher

Function handleGopher

gopher.go:43–74  ·  view source on GitHub ↗
(app *App, w gopher.ResponseWriter, r *gopher.Request)

Source from the content-addressed store, hash-verified

41}
42
43func handleGopher(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
44 parts := strings.Split(r.Selector, "/")
45 if app.cfg.App.SingleUser {
46 if parts[1] != "" {
47 return handleGopherCollectionPost(app, w, r)
48 }
49 return handleGopherCollection(app, w, r)
50 }
51
52 // Show all public collections (a gopher Reader view, essentially)
53 if len(parts) == 3 {
54 return handleGopherCollection(app, w, r)
55 }
56
57 w.WriteInfo(fmt.Sprintf("Welcome to %s", app.cfg.App.SiteName))
58
59 colls, err := app.db.GetPublicCollections(app.cfg.App.Host)
60 if err != nil {
61 return err
62 }
63
64 for _, c := range *colls {
65 w.WriteItem(&gopher.Item{
66 Host: stripHostProtocol(app),
67 Port: app.cfg.Server.GopherPort,
68 Type: gopher.DIRECTORY,
69 Description: c.DisplayTitle(),
70 Selector: "/" + c.Alias + "/",
71 })
72 }
73 return w.End()
74}
75
76func handleGopherCollection(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
77 var collAlias, slug string

Callers

nothing calls this directly

Calls 5

handleGopherCollectionFunction · 0.85
stripHostProtocolFunction · 0.85
GetPublicCollectionsMethod · 0.80
DisplayTitleMethod · 0.45

Tested by

no test coverage detected