forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
44 lines (35 loc) · 891 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
package main
import (
"os"
"time"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/middleware/accesslog"
)
var (
// https://api.slack.com/apps/your_app_id/oauth
token = os.Getenv("SLACK_BOT_TOKEN")
// on slack app: right click on the channel -> view channel details -> on bottom, copy the channel id.
channelID = os.Getenv("SLACK_CHANNEL_ID")
)
// $ go run .
func main() {
app := iris.New()
ac := accesslog.New(os.Stdout) // or app.Logger().Printer
ac.LatencyRound = time.Second
ac.SetFormatter(&Slack{
Token: token,
ChannelIDs: []string{channelID},
HandleMessage: true,
})
app.UseRouter(ac.Handler)
app.Get("/", index)
app.Listen(":8080")
}
func index(ctx iris.Context) {
if sleepDur := ctx.URLParam("sleep"); sleepDur != "" {
if d, err := time.ParseDuration(sleepDur); err == nil {
time.Sleep(d)
}
}
ctx.WriteString("Index")
}