Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

implements an event system for Buffalo #1305

Merged
merged 5 commits into from
Sep 18, 2018
Merged

implements an event system for Buffalo #1305

merged 5 commits into from
Sep 18, 2018

Conversation

markbates
Copy link
Member

@markbates markbates commented Sep 18, 2018

A note about plugin via CLI support:

Because plugins receive their payload via their CLI they get a limited payload of only the items that can be Marshaled.

I wrote a simple “echo” buffalo plugin and here’s one of the payloads it received, it’s the event that is emitted after a RouteInfo#ServeHTTP is run.

Notice, in the below payload, that certiain items from buffalo.App, for example, aren't marshaled. What is left, however, I feel is more than ample to do whatever you want with a plugin.

[{
  "kind": "route:finished",
  "message": "",
  "payload": {
    "context": {
      "app": {
        "name": "/widgets",
        "addr": "127.0.0.1:3000",
        "host": "http://127.0.0.1:3000",
        "env": "development",
        "log_level": "debug",
        "session_name": "_coke_session",
        "worker_off": false,
        "prefix": "/widgets/{widget_id}"
      },
      "authenticity_token": "r/QL2iNbC1RfmS11GDWpbaAMGnO07FJ4Y2HHFHhRj7/vPW52qBnZTTb5e8QCEOC7I4iRu7Fkjke7DaXapOD9Eg==",
      "contentType": "text/html",
      "current_path": "/widgets/8d01df00-2418-4517-b844-ffb066935ebd/",
      "current_route": {
        "method": "GET",
        "path": "/widgets/{widget_id}/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.Show",
        "pathName": "widgetPath",
        "aliases": []
      },
      "current_template": "widgets/show.html",
      "env": "development",
      "flash": {
        "success": ["Widget was created successfully"]
      },
      "languages": ["en-us", "en-US"],
      "method": "GET",
      "params": {
        "widget_id": "8d01df00-2418-4517-b844-ffb066935ebd"
      },
      "request_id": "GYZRkusKEG-rBWpwwPLpn",
      "routes": [{
        "method": "GET",
        "path": "/",
        "handler": "github.com/markbates/coke/actions.HomeHandler",
        "pathName": "rootPath",
        "aliases": []
      }, {
        "method": "GET",
        "path": "/widgets/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.List",
        "pathName": "widgetsPath",
        "aliases": []
      }, {
        "method": "POST",
        "path": "/widgets/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.Create",
        "pathName": "widgetsPath",
        "aliases": []
      }, {
        "method": "GET",
        "path": "/widgets/new/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.New",
        "pathName": "newWidgetsPath",
        "aliases": []
      }, {
        "method": "GET",
        "path": "/widgets/{widget_id}/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.Show",
        "pathName": "widgetPath",
        "aliases": []
      }, {
        "method": "PUT",
        "path": "/widgets/{widget_id}/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.Update",
        "pathName": "widgetPath",
        "aliases": []
      }, {
        "method": "DELETE",
        "path": "/widgets/{widget_id}/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.Destroy",
        "pathName": "widgetPath",
        "aliases": []
      }, {
        "method": "GET",
        "path": "/widgets/{widget_id}/edit/",
        "handler": "github.com/markbates/coke/actions.WidgetsResource.Edit",
        "pathName": "editWidgetPath",
        "aliases": []
      }],
      "status": 200,
      "tx": {
        "ID": "KeMJhyeTrXKSOBMepLUOMrHHmwmxsY",
        "Store": {
          "ID": 7735342683481052555,
          "Mapper": {}
        },
        "Dialect": {
          "ConnectionDetails": {
            "Dialect": "postgres",
            "Database": "coke_development",
            "Host": "127.0.0.1",
            "Port": "5432",
            "User": "postgres",
            "Password": "postgres",
            "Encoding": "",
            "URL": "",
            "Pool": 5,
            "IdlePool": 0,
            "Options": null
          }
        },
        "Elapsed": 2596492,
        "TX": {
          "ID": 7735342683481052555,
          "Mapper": {}
        }
      },
      "widget": {
        "id": "8d01df00-2418-4517-b844-ffb066935ebd",
        "created_at": "2018-09-18T11:55:44.0506Z",
        "updated_at": "2018-09-18T11:55:44.0506Z",
        "name": "asdfasdfas"
      },
      "yield": "\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1\"\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003eBuffalo - Coke\u003c/title\u003e\n    \u003clink href=\"/assets/application.005bed303082ff86c711.css\" media=\"screen\" rel=\"stylesheet\" /\u003e\n    \u003cmeta name=\"csrf-param\" content=\"authenticity_token\" /\u003e\n    \u003cmeta name=\"csrf-token\" content=\"r/QL2iNbC1RfmS11GDWpbaAMGnO07FJ4Y2HHFHhRj7/vPW52qBnZTTb5e8QCEOC7I4iRu7Fkjke7DaXapOD9Eg==\" /\u003e\n    \u003clink rel=\"icon\" href=\"/assets/images/favicon.ico\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n\n    \u003cdiv class=\"container\"\u003e\n      \u003cdiv class=\"row\"\u003e\n  \u003cdiv class=\"col-md-12\"\u003e\n    \n      \n        \u003cdiv class=\"alert alert-success\" role=\"alert\"\u003e\n          Widget was created successfully\n          \u003cbutton type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\"\u003e\n            \u003cspan aria-hidden=\"true\"\u003e\u0026times;\u003c/span\u003e\n          \u003c/button\u003e\n        \u003c/div\u003e\n      \n    \n  \u003c/div\u003e\n\u003c/div\u003e\n\n      \u003cdiv class=\"page-header\"\u003e\n  \u003ch1\u003eWidget#Show\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cul class=\"list-unstyled list-inline\"\u003e\n  \u003cli class=\"list-inline-item\"\u003e\u003ca href=\"/widgets/\" class=\"btn btn-info\"\u003eBack to all Widgets\u003c/a\u003e\u003c/li\u003e\n  \u003cli class=\"list-inline-item\"\u003e\u003ca href=\"/widgets/8d01df00-2418-4517-b844-ffb066935ebd/edit/\" class=\"btn btn-warning\"\u003eEdit\u003c/a\u003e\u003c/li\u003e\n  \u003cli class=\"list-inline-item\"\u003e\u003ca href=\"/widgets/8d01df00-2418-4517-b844-ffb066935ebd/\" data-method=\"DELETE\" data-confirm=\"Are you sure?\" class=\"btn btn-danger\"\u003eDestroy\u003c/a\u003e\n\u003c/ul\u003e\n\n\u003cp\u003e\n  \u003cstrong\u003eName\u003c/strong\u003e: asdfasdfas\n\u003c/p\u003e\n\n    \u003c/div\u003e\n\n    \u003cscript src=\"/assets/application.9596ed2de568d4d3641c.js\" type=\"text/javascript\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n"
    },
    "route": {
      "method": "GET",
      "path": "/widgets/{widget_id}/",
      "handler": "github.com/markbates/coke/actions.WidgetsResource.Show",
      "pathName": "widgetPath",
      "aliases": []
    }
  }
}]

@markbates markbates requested a review from a team September 18, 2018 16:01
@paganotoni
Copy link
Member

Wooot!

@markbates markbates merged commit 197ef54 into development Sep 18, 2018
@markbates markbates added this to the v0.13.0 milestone Sep 18, 2018
@markbates markbates deleted the events branch September 18, 2018 18:38
@markbates markbates modified the milestone: v0.13.0 Sep 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants