From 757b2766cd4491ceb7eed5075c1477ba91880fbf Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 21 Feb 2020 01:38:47 +0300 Subject: first commit --- example/main.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 example/main.go (limited to 'example') 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 +} -- cgit v1.2.3