mirror of
https://github.com/kataras/iris.git
synced 2026-01-26 21:35:56 +00:00
add accesslog slack example to the examples folder
This commit is contained in:
@@ -1,5 +1,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() {
|
||||
println("Navigate to: https://github.com/kataras/iris/issues/1808#issuecomment-1013757925")
|
||||
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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user