session

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2017 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorRegistry is a map of error codes to errors.
	// It is usually used in gopherpit.com/gopherpit/pkg/client.Client.
	ErrorRegistry = apiClient.NewMapErrorRegistry(nil)
)
View Source
var (
	// SessionNotFound is error if session does not exist.
	SessionNotFound = NewError(1000, "session not found")
)

Functions

This section is empty.

Types

type Error

type Error struct {
	// Message is a text that describes an error.
	Message string `json:"message"`
	// Code is a number that identifies error.
	// It allows error identification when serialization is involved.
	Code int `json:"code"`
}

Error is a structure that holds error message and code.

func NewError

func NewError(code int, message string) (err *Error)

NewError creates an instance of Error and adds it to ErrorRegistry. If error code already exists in ErrorRegistry, it panics.

func (*Error) Error

func (e *Error) Error() string

Error returns error message.

type Options

type Options struct {
	Values *map[string]interface{} `json:"values,omitempty"`
	MaxAge *int                    `json:"max-age,omitempty"`
}

Options is a structure with parameters as pointers to set session data. If a parameter is nil, the corresponding Session parameter will not be changed.

type Service

type Service interface {
	// Session retrieves a Session instance.
	Session(id string) (*Session, error)
	// CreateSession creates a new Session instance.
	CreateSession(*Options) (*Session, error)
	// UpdateSession changes data of an existing Session.
	UpdateSession(id string, o *Options) (*Session, error)
	// DeleteSession deletes an existing Session.
	DeleteSession(id string) error
}

Service defines functions that Session provider must have.

type Session

type Session struct {
	// A unique Session ID.
	ID string `json:"id"`
	// A mapping of named arbitrary data that Session holds.
	Values map[string]interface{} `json:"values,omitempty"`
	// MaxAge is an integer that represents duration in seconds and
	// can be used in setting expiration of a HTTP cookie.
	MaxAge int `json:"max-age,omitempty"`
}

Session holds session ID and values associated.

Directories

Path Synopsis
Package boltSession provides a Service that is using local BoltDB database to store Session data.
Package boltSession provides a Service that is using local BoltDB database to store Session data.
Package httpSession provides a Service that is a HTTP client to an external session service that can respond to HTTP requests defined here.
Package httpSession provides a Service that is a HTTP client to an external session service that can respond to HTTP requests defined here.

Jump to

Keyboard shortcuts

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