-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost.go
More file actions
68 lines (52 loc) · 1.33 KB
/
post.go
File metadata and controls
68 lines (52 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import(
"github.com/labstack/echo/v4"
"net/http"
"time"
"fmt"
"strings"
)
// Edit post
func editThing(c echo.Context) error {
var p editP
err := c.Bind(&p)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
var r editResult
if strings.HasPrefix(p.Thing_id, kindPost) {
post, _, err := client.Post.Edit(c.Request().Context(), p.Thing_id, p.Selftext)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
r = editResult{post.Selftext_html}
} else if strings.HasPrefix(p.Thing_id, kindComment) {
comment, _, err := client.Comment.Edit(c.Request().Context(), p.Thing_id, p.Selftext)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
r = editResult{comment.Body_html}
}
return c.JSON(http.StatusOK, r)
}
// View post
func submission(c echo.Context) error {
pc, _, err := client.Post.Get(c.Request().Context(), c.Param("id"))
start := time.Now()
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
pw := PCWrapper{
PageTitle: pc.Post.Title,
Items: pc.Comments,
WP: pc.Post,
Thread: false,
}
err = tpls["post"].Execute(c.Response(), pw)
elapsed := time.Since(start)
fmt.Println("--------")
fmt.Printf("comments rendered in %s", elapsed)
fmt.Println()
fmt.Println("--------")
return err
}