Repository navigation
Flags
Caleb Hiebert edited this page Nov 16, 2018
·
2 revisions
Flags are small bits of data that are stored on the Context object. Flags only live for a single request at a time, and are discarded once the request has finished processing.
Let's say we have a handler as follows, how do we set a flag?
Setting a flag that already exists will overwrite it's value
gobblr.Use(func(c *gbl.Context) {
// That's it!
// This request will now have this flag until it's finished or removed
c.Flag("example-flag", "example-data")
})Let's say we have a handler as follows, how do we clear a flag?
Setting a flag that already exists will overwrite it's value
gobblr.Use(func(c *gbl.Context) {
// That's it!
// This request will no longer have the flag "example-flag"
c.ClearFlag("example-flag")
})We have set all these lovely flags, how do we retrieve them? There are a couple handy functions for this.
-
HasFlag()Will return true if the flag exists, false if it does not -
GetFlag()Will return the flag value as aninterface{}
Some flag prefixes are reserved by different integrations
-
fb:*- Reserved by the messenger integration to save information about the request -
sess:*- Reserved for setting variables on the session