ctx

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Current request context data.

`kong.ctx.shared`: A table that has the lifetime of the current request and is shared between all plugins. It can be used to share data between several plugins in a given request.

Values inserted in this table by a plugin will be visible by all other plugins. One must use caution when interacting with its values, as a naming conflict could result in the overwrite of data.

Usage: // Two plugins A and B, if plugin A has a higher priority than B's // (it executes before B), and plugin A is a Go plugin:

// plugin A PluginA.go

func (conf Config) Access(kong *pdk.PDK) {
	err := kong.Ctx.SetShared("hello world")
	if err != nil {
		kong.Log.Err(err)
		return
	}
}

// plugin B handler.lua function plugin_b_handler:access(conf)

kong.log(kong.ctx.shared.foo) // "hello world"

end

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ctx

type Ctx struct {
	bridge.PdkBridge
}

Holds this module's functions. Accessible as `kong.Ctx`

func (Ctx) GetSharedAny

func (c Ctx) GetSharedAny(k string) (interface{}, error)

kong.Ctx.GetSharedAny() returns a value from the `kong.ctx.shared` request context table.

func (Ctx) GetSharedFloat

func (c Ctx) GetSharedFloat(k string) (float64, error)

kong.Ctx.GetSharedFloat() returns a float value from the `kong.ctx.shared` request context table.

func (Ctx) GetSharedString

func (c Ctx) GetSharedString(k string) (string, error)

kong.Ctx.GetSharedString() returns a string value from the `kong.ctx.shared` request context table.

func (Ctx) SetShared

func (c Ctx) SetShared(k string, value interface{}) error

kong.Ctx.SetShared() sets a value in the `kong.ctx.shared` request context table.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL