context

package
v1.4.0-rc Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2018 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package context is used to create a context that can be passed to the execution of templates. And helps with conveying information like the signed in user to the user interface.

A new context can be created using the New() function.

c := context.New()

To add information to a context use the With() function. It can be easily chained with the New() method.

c := context.New().With("key", "value").With("number", 9)

The package also provides a method with which user information is added to the context automatically. To be able to use this the packages need to get a session handler via its Init() function.

context.Init(mySessionHandler)
c := context.New().WithUserInformation(myRequest)

Index

Examples

Constants

View Source
const (
	Version = "version"

	// TODOs
	TodoList = "TodoList"

	// Dashboard
	Dashboard          = "Dashboard"
	DashboardSequences = "DashboardSequences"

	// Explore
	Projects = "Projects"
	Groups   = "Groups"
	Users    = "Users"

	// Project
	Project = "Project"

	TestCases     = "TestCases"
	TestSequences = "TestSequences"

	// Dashboard
	Variants = "Variants"
	Versions = "Versions"
	// TestCase
	TestCase        = "TestCase"
	TestCaseVersion = "TestCaseVersion"
	DurationHours   = "DurationHours"
	DurationMin     = "DurationMin"
	DurationSec     = "DurationSec"

	// TestSequence
	TestSequence        = "TestSequence"
	TestSequenceVersion = "TestSequenceVersion"
	SequenceInfo        = "SequenceInfo"

	// Protocols
	SelectedTestCase     = "SelectedTestCase"
	SelectedTestSequence = "SelectedTestSequence"
	SelectedType         = "SelectedType"
	Protocol             = "Protocol"
	CaseProtocols        = "CaseProtocols" // The case protocols of a sequence

	// Comments
	Comments = "Comments"

	//Various
	Filtered = "Filtered"

	//Members
	Member    = "Members"
	NonMember = "NonMembers"
	Owner     = "Owner"

	//Labels
	LabelColors = "LabelColors"

	//Delete Modals
	DeleteLabels       = "DeleteLabels"
	DeleteTestCase     = "DeleteTestCase"
	DeleteTestSequence = "DeleteTestSequence"
	DeleteProject      = "DeleteProject"

	//Settings
	Roles = "Roles"
)

The keys for the context

View Source
const (
	SignedInKey           = "SignedIn"
	UserKey               = "User"
	MemberKey             = "Member"
	ProjectPermissionsKey = "ProjectPermissions"
)

Reserved keys for user information

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context map[string]interface{}

Context contains information useful for the execution of templates

func New

func New() Context

New creates a new *empty* context.

func (Context) With

func (c Context) With(key string, data interface{}) Context

With is a convince method used to chain-add content to the context. Values can only be added once. If a value with given key already exists this function will panic. If 'nil' is passed as data it will not be stored. This means this method can't be used to delete values.

Example

ExampleContext_With is an example for the usage of the context.Context.With() method.

c := New().With("key", "value").With("int", 5)
c.With("struct", struct {
	a int
	b string
}{9, "bla"})
fmt.Println(c["key"], c["int"], c["struct"])
Output:

value 5 {9 bla}

func (Context) WithUserInformation

func (c Context) WithUserInformation(r *http.Request) Context

WithUserInformation fills the context with information about the currently signed in user. This call can be chained. Be careful not to set values with the keys used by this method for the user information. (See the SignedInKey and UserKey constants of this package) If With() was used before to add values with said key this method will panic.

type SessionHandler

type SessionHandler interface {
	// GetCurrent gets the user that hold the session. If there is no
	// user session the returned user will be nil.
	GetCurrent(r *http.Request) (*user.User, error)
}

SessionHandler is used to get the user that corresponds to a request.

Jump to

Keyboard shortcuts

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