scssession

package
v0.0.0-...-ecdd364 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 License: MIT Imports: 7 Imported by: 1

README

scssession

Package scssession is an Ambient plugin that provides session management using SCS.

Import: github.com/ambientkit/plugin/sessionmanager/scssession

Version: 1.0.0

Plugin Type

The plugin can be used as the following core types:

  • Logger: false
  • Storage System: false
  • Router: false
  • Template Engine: false
  • Session Manager: true

Grants

The plugin request the following grants (1):

  • Name: router.middleware:write
    • Description: Access to read and write session data for the user.

Settings

The plugin has the follow settings (1):

  • Name: Session Key
    • Type: password
    • Hidden: true
    • Has Default: true

Routes

The plugin does not have any routes.

Middleware

The plugin has middleware (1).

FuncMap

The plugin does not have a FuncMap.

Assets

The plugin does not inject any assets.

Embedded Files

The plugin does not have any embedded files.

Example Usage

package main

import (
	"log"

	"github.com/ambientkit/ambient"
	"github.com/ambientkit/ambient/pkg/ambientapp"
	"github.com/ambientkit/plugin/logger/zaplogger"
	"github.com/ambientkit/plugin/pkg/uuid"
	"github.com/ambientkit/plugin/sessionmanager/scssession"
	"github.com/ambientkit/plugin/storage/memorystorage"
)

func main() {
	sessionManager := scssession.New(uuid.EncodedString(32))

	plugins := &ambient.PluginLoader{
		// Core plugins are implicitly trusted.
		Router:         nil,
		TemplateEngine: nil,
		SessionManager: sessionManager,
		// Trusted plugins are those that are typically needed to boot so they
		// will be enabled and given full access.
		TrustedPlugins: map[string]bool{},
		Plugins:        []ambient.Plugin{},
		Middleware: []ambient.MiddlewarePlugin{
			// Middleware - executes top to bottom.
			sessionManager,
		},
	}
	_, _, err := ambientapp.NewApp("myapp", "1.0",
		zaplogger.New(),
		ambient.StoragePluginGroup{
			Storage: memorystorage.New(),
		},
		plugins)
	if err != nil {
		log.Fatalln(err.Error())
	}
}

Docgen by Ambient

Documentation

Overview

Package scssession is an Ambient plugin that provides session management using SCS.

Index

Examples

Constants

View Source
const (
	// SessionKey allows user to set the session key.
	SessionKey = "Session Key"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Plugin

type Plugin struct {
	*ambient.PluginBase
	// contains filtered or unexported fields
}

Plugin represents an Ambient plugin.

func New

func New(sessionKey string) *Plugin

New returns an Ambient plugin that provides session management using SCS.

Example
package main

import (
	"log"

	"github.com/ambientkit/ambient"
	"github.com/ambientkit/ambient/pkg/ambientapp"
	"github.com/ambientkit/plugin/logger/zaplogger"
	"github.com/ambientkit/plugin/pkg/uuid"
	"github.com/ambientkit/plugin/sessionmanager/scssession"
	"github.com/ambientkit/plugin/storage/memorystorage"
)

func main() {
	sessionManager := scssession.New(uuid.EncodedString(32))

	plugins := &ambient.PluginLoader{
		// Core plugins are implicitly trusted.
		Router:         nil,
		TemplateEngine: nil,
		SessionManager: sessionManager,
		// Trusted plugins are those that are typically needed to boot so they
		// will be enabled and given full access.
		TrustedPlugins: map[string]bool{},
		Plugins:        []ambient.Plugin{},
		Middleware: []ambient.MiddlewarePlugin{
			// Middleware - executes top to bottom.
			sessionManager,
		},
	}
	_, _, err := ambientapp.NewApp("myapp", "1.0",
		zaplogger.New(),
		ambient.StoragePluginGroup{
			Storage: memorystorage.New(),
		},
		plugins)
	if err != nil {
		log.Fatalln(err.Error())
	}
}
Output:

func (*Plugin) GrantRequests

func (p *Plugin) GrantRequests() []ambient.GrantRequest

GrantRequests returns a list of grants requested by the plugin.

func (*Plugin) Middleware

func (p *Plugin) Middleware() []func(next http.Handler) http.Handler

Middleware returns router middleware.

func (*Plugin) PluginName

func (p *Plugin) PluginName() string

PluginName returns the plugin name.

func (*Plugin) PluginVersion

func (p *Plugin) PluginVersion() string

PluginVersion returns the plugin version.

func (*Plugin) SessionManager

func (p *Plugin) SessionManager(logger ambient.Logger, ss ambient.SessionStorer) (ambient.AppSession, error)

SessionManager returns the session manager.

func (*Plugin) Settings

func (p *Plugin) Settings() []ambient.Setting

Settings returns a list of user settable fields.

Directories

Path Synopsis
Package websession provides session management.
Package websession provides session management.

Jump to

Keyboard shortcuts

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