-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcf.go
90 lines (80 loc) · 2.14 KB
/
gcf.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package gcf
// nolint
import (
"context"
"fmt"
"log"
"net/http"
"os"
"cloud.google.com/go/pubsub"
"github.com/gcp-kit/line-bot-boilerplate-go-example/function"
"github.com/gcp-kit/line-bot-boilerplate-go-example/pkg/utils"
"github.com/gcp-kit/line-bot-boilerplate-go/core"
"github.com/gcp-kit/line-bot-boilerplate-go/util"
"github.com/line/line-bot-sdk-go/linebot"
)
// example
var count int
// nolint
func init() {
if utils.GetProjectID() != "" {
entryPoint = os.Getenv("FUNCTION_NAME")
setting("parent-test", "child-test")
}
}
// setFunction add a function to use in `ChildFunctions`
// editing required
func setFunction() {
tracer.Function = map[core.TracerName]func(context.Context, *core.Operation, *linebot.Event) *core.TracerResp{
core.TracerFollowEvent: function.FollowEvent,
core.TracerUnfollowEvent: function.UnfollowEvent,
core.TracerTextMessage: function.TextEvent,
core.TracerLocationMessage: function.LocationEvent,
}
/*
** the processing to put in the Global variable is here
*/
count++ // example
}
// WebHook CloudFunctions(Trigger: HTTP)
// no edit
// nolint
func WebHook(w http.ResponseWriter, r *http.Request) {
ctx := util.SetGinContext(w, r)
core.WebHook(ctx, secret, parentTopic)
}
// ParentFunctions CloudFunctions(Trigger: Pub/Sub)
// no edit
// nolint
func Forking(ctx context.Context, m *pubsub.Message) error {
log.Println("EntryPoint:", entryPoint)
switch entryPoint {
case RouteParentFunctions:
return core.ParentFunctions(ctx, m, childTopic)
case RouteChildFunctions:
return core.ChildFunctions(ctx, m, operation)
default:
return fmt.Errorf("invalid function name")
}
}
// LiffFull CloudFunctions(Trigger: HTTP)
// no edit
// nolint
func LiffFull(w http.ResponseWriter, r *http.Request) {
ctx := util.SetGinContext(w, r)
function.Liff(ctx)
}
// LiffTall CloudFunctions(Trigger: HTTP)
// no edit
// nolint
func LiffTall(w http.ResponseWriter, r *http.Request) {
ctx := util.SetGinContext(w, r)
function.Liff(ctx)
}
// LiffCompact CloudFunctions(Trigger: HTTP)
// no edit
// nolint
func LiffCompact(w http.ResponseWriter, r *http.Request) {
ctx := util.SetGinContext(w, r)
function.Liff(ctx)
}