-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (50 loc) · 1.34 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// package main
package hello
import (
"context"
"io"
"net/http"
"time"
"cloud.google.com/go/storage"
"github.com/gin-gonic/gin"
"google.golang.org/appengine"
"google.golang.org/appengine/log"
)
type demo struct {
client *storage.Client
bucketName string
bucket *storage.BucketHandle
w io.Writer
ctx context.Context
// cleanUp is a list of filenames that need cleaning up at the end of the demo.
cleanUp []string
// failed indicates that one or more of the demo steps failed.
failed bool
}
// 本番用
func init() {
// Todo: AtCoderを最初に1度呼ぶ
r := gin.New()
r.GET("/update", Update)
r.GET("/contests", Json)
http.Handle("/", r)
}
func Json(context *gin.Context) {
// var r *http.Request = context.Request
// ctx := appengine.NewContext(r)
atcoder := &AtCoder{}
atcoder.Context = context // 強制的に設定してる。よくない
// atcoder.LoadGob("contests")
// ファイルから読み込む
atcoder.FileIO("read")
context.JSON(http.StatusOK, atcoder.Contests)
}
func Update(context *gin.Context) {
var r *http.Request = context.Request
ctx := appengine.NewContext(r)
log.Infof(ctx, "GET!! (nomikura)") // アクセスログ
atcoder := &AtCoder{}
atcoder.SetContestData(context)
context.String(http.StatusOK, "Finish update!!"+time.Now().String())
// responseContests = atcoder.Contests
}