MCPcopy
hub / github.com/writefreely/writefreely / handleGopherCollectionPost

Function handleGopherCollectionPost

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

Source from the content-addressed store, hash-verified

129}
130
131func handleGopherCollectionPost(app *App, w gopher.ResponseWriter, r *gopher.Request) error {
132 var collAlias, slug string
133 var c *Collection
134 var err error
135
136 parts := strings.Split(r.Selector, "/")
137 if app.cfg.App.SingleUser {
138 slug = parts[1]
139 c, err = app.db.GetCollectionByID(1)
140 if err != nil {
141 return err
142 }
143 } else {
144 collAlias = parts[1]
145 slug = parts[2]
146 c, err = app.db.GetCollection(collAlias)
147 if err != nil {
148 return err
149 }
150 }
151 c.hostName = app.cfg.App.Host
152
153 p, err := app.db.GetPost(slug, c.ID)
154 if err != nil {
155 return err
156 }
157
158 b := bytes.Buffer{}
159 if p.Title.String != "" {
160 b.WriteString(p.Title.String + "\n")
161 }
162 b.WriteString(p.DisplayDate + "\n\n")
163 b.WriteString(p.Content)
164 io.Copy(w, &b)
165
166 return w.End()
167}

Callers 2

handleGopherFunction · 0.85
handleGopherCollectionFunction · 0.85

Calls 3

GetCollectionByIDMethod · 0.65
GetCollectionMethod · 0.65
GetPostMethod · 0.65

Tested by

no test coverage detected