aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/main.go37
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
+}