Go API Documentation

github.com/TykTechnologies/tyk/goplugin

No package summary is available.

Package

Files: 4. Third party imports: 0. Imports from organisation: 0. Tests: 0. Benchmarks: 0.

Constants

const (
	errNotImplemented = "goplugin.%s is disabled, use -tags=goplugin to enable"
)

Vars

var log = logger.Get()

Types

FileSystemStorage

FileSystemStorage implements storage interface, it uses the filesystem as store

type FileSystemStorage struct{}

storage

interface so we can test which plugin should be loaded

Field name Field type Comment
type

any

No comment on field.
type storage interface {
	fileExist(string) bool
}

Functions

func GetAnalyticsHandler

func GetAnalyticsHandler(path string, symbol string) (func(record *analytics.AnalyticsRecord), error) {
	return nil, fmt.Errorf("goplugin.GetAnalyticsHandler is disabled, please disable build flag 'nogoplugin'")

}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: fmt.Errorf.

func GetHandler

func GetHandler(path string, symbol string) (http.HandlerFunc, error) {
	return nil, fmt.Errorf(errNotImplemented, "GetHandler")
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: fmt.Errorf.

func GetPluginFileNameToLoad

GetPluginFileNameToLoad check which file to load based on name, tyk version, os and architecture but it also takes care of returning the name of the file that exists

func GetPluginFileNameToLoad(pluginStorage storage, pluginPath string) (string, error) {
	var (
		versionPrefixed	= getPrefixedVersion()
		version		= versionPrefixed[1:]
	)

	// 1. attempt to load a plugin that follow the new standard
	newNamingFormat := getPluginNameFromTykVersion(versionPrefixed, pluginPath)
	if pluginStorage.fileExist(newNamingFormat) {
		return newNamingFormat, nil
	}

	// 2. attempt to load a plugin that follows the new standard but gw version is not prefixed
	newNamingFormat = getPluginNameFromTykVersion(version, pluginPath)
	if pluginStorage.fileExist(newNamingFormat) {
		return newNamingFormat, nil
	}

	// 3. attempt to load the exact name provided
	if !pluginStorage.fileExist(pluginPath) {
		return "", errors.New("plugin file not found")
	}

	return pluginPath, nil
}

Cognitive complexity: 6, Cyclomatic complexity: 4

Uses: errors.New.

func GetResponseHandler

func GetResponseHandler(path string, symbol string) (func(rw http.ResponseWriter, res *http.Response, req *http.Request), error) {
	return nil, fmt.Errorf(errNotImplemented, "GetResponseHandler")
}

Cognitive complexity: 0, Cyclomatic complexity: 1

Uses: fmt.Errorf.

func GetSymbol

func GetSymbol(modulePath string, symbol string) (interface{}, error) {
	return nil, fmt.Errorf(errNotImplemented, "GetSymbol")
}

Cognitive complexity: 1, Cyclomatic complexity: 1

Uses: fmt.Errorf.

Private functions

func getPluginNameFromTykVersion

getPluginNameFromTykVersion builds a name of plugin based on tyk version, GOOS, and GOARCH of the build. The structure of the plugin name looks like: {plugin-dir}/{plugin-name}{GW-version}{OS}_{arch}.so

getPluginNameFromTykVersion (version string, pluginPath string) string
References: filepath.Base, filepath.Dir, runtime.GOARCH, runtime.GOOS, strings.Join, strings.TrimSuffix.

func getPrefixedVersion

getPrefixedVersion takes the injected build.Version and ensures it's returned containing a v prefix. It cleans up any rc tags that are delimited with a -.

getPrefixedVersion () string
References: build.Version, strings.Contains, strings.HasPrefix, strings.SplitN.

func fileExist

fileExist (path string) bool
References: errors.Is, os.ErrNotExist, os.Stat.


Tests

Files: 2. Third party imports: 1. Imports from organisation: 0. Tests: 2. Benchmarks: 0.

Types

MockStorage

MockStorage implements storage to simulate which file to load. its just a mock

Field name Field type Comment
files

[]string

No comment on field.
type MockStorage struct {
	files []string
}

Test functions

TestFileExist

References: assert.Equal, os.CreateTemp, os.Remove, testing.T.

TestGetPluginFileNameToLoad

References: assert.Equal, assert.NoError, runtime.GOARCH, runtime.GOOS, testing.T.