diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-02-21 01:38:47 +0300 |
---|---|---|
committer | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-02-21 01:38:47 +0300 |
commit | 757b2766cd4491ceb7eed5075c1477ba91880fbf (patch) | |
tree | fd7a44b2ba65810c5a837d9bc293f7b5a0d87525 /example |
first commit
Diffstat (limited to 'example')
-rw-r--r-- | example/main.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/example/main.go b/example/main.go new file mode 100644 index 0000000..404c970 --- /dev/null +++ b/example/main.go @@ -0,0 +1,37 @@ +// +build example + +package main + +import ( + "context" + "log" + "net/http" + + "github.com/neonxp/marusia" +) + +func main() { + m := marusia.NewMarusia(messageHandler) + server := http.Server{ + Addr: ":8080", + Handler: m.Handler(), + } + if err := server.ListenAndServe(); err != http.ErrServerClosed { + log.Fatal(err) + } +} + +func messageHandler(ctx context.Context, req *marusia.Request) (*marusia.Response, error) { + log.Printf( + "Session id: %s\nUser id: %s\nMessage id: %s\nIncomming message: %s\nButton payload: %+v", + ctx.Value(marusia.CtxSessionID), + ctx.Value(marusia.CtxUserID), + ctx.Value(marusia.CtxMessageID), + req.Command, + req.Payload, + ) + resp := marusia.NewResponse("Это ответ на запрос!"). + AddButton("Адрес библиотеки", nil, "https://github.com/neonxp/marusia"). + AddButton("Произвольный payload", map[string]interface{}{"Hello": "world"}, "") + return resp, nil +} |