context

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2019 License: GPL-3.0 Imports: 10 Imported by: 7

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

Constants

View Source
const (
	Version = "version"

	// Tasks
	TaskList             = "TaskList"
	TaskViewOpenedIssues = "ViewOpened"
	UserTaskCountList    = "UserTaskCountList"

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

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

	// Project
	Project = "Project"

	TestCases     = "TestCases"
	TestSequences = "TestSequences"

	// Dashboard
	Variants = "Variants"
	Versions = "Versions"

	// Activity
	Activities = "Activities"

	// TestCase
	TestCase        = "TestCase"
	TestCaseVersion = "TestCaseVersion"
	DurationHours   = "DurationHours"
	DurationMin     = "DurationMin"
	DurationSec     = "DurationSec"

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

	Tasks = "Tasks"

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

	// Comments
	Comments = "Comments"
	Comment  = "Comment"

	// Various
	Filtered = "Filtered"

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

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

	// Settings
	SettingsIdentifier = "SettingsIdentifier"
	Roles              = "Roles"
	SystemSettings     = "SystemSettings"
	Language           = "Language"

	//Profile
	Profile = "Profile"
	Edit    = "Edit"
)

The keys for the context

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

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.

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