2022-02-18 21:19:33 +01:00
|
|
|
package main
|
|
|
|
|
2022-10-17 21:45:47 +02:00
|
|
|
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 .
|
2022-02-18 21:19:33 +01:00
|
|
|
func main() {
|
2022-10-17 21:45:47 +02:00
|
|
|
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")
|
2022-02-18 21:19:33 +01:00
|
|
|
}
|