-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (38 loc) · 968 Bytes
/
main.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
42
43
44
45
46
47
48
49
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"time"
"github.com/gin-gonic/gin"
)
// Event stores information about a hackathon event
type Event struct {
Title string `json:"title"`
Description string `json:"description"`
Start time.Time `json:"start"`
End time.Time `json:"end"`
URL string `json:"url"`
}
// Response formats for AMP expected response
type Response struct {
Items []Event `json:"items"`
}
func main() {
jsonFile, err := os.Open("all_hackathons.json")
if err != nil {
log.Fatal(err)
}
defer jsonFile.Close()
byteValue, _ := ioutil.ReadAll(jsonFile)
var result Response
json.Unmarshal([]byte(byteValue), &result.Items)
log.Println("hola ke ase")
r := gin.Default()
r.GET("/all", func(c *gin.Context) {
c.Writer.Header().Set("Access-Control-Allow-Origin", "*")
c.JSON(200, result)
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}