-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
41 lines (34 loc) · 784 Bytes
/
handler.go
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
package main
import (
"net/http"
"time"
"github.com/dghubble/go-twitter/twitter"
"github.com/gin-gonic/gin"
)
var (
clientError = gin.H{
"error": "Bad Request",
"message": "Error processing your request, see logs for details",
}
)
func defaultHandler(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"release": AppVersion,
"request_on": time.Now(),
"request_from": c.Request.RemoteAddr,
})
}
func tweetHandler(c *gin.Context) {
var t twitter.Tweet
if err := c.ShouldBindJSON(&t); err != nil {
logger.Printf("error binding tweet: %v", err)
c.JSON(http.StatusBadRequest, clientError)
return
}
logger.Printf("tweet: %v", t)
c.JSON(http.StatusOK, gin.H{
"request": time.Now(),
"release": AppVersion,
"status": c.Request.RemoteAddr,
})
}