| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | 
							- /*
 
-  * Public Domain Software
 
-  *
 
-  * I (Matthias Ladkau) am the author of the source code in this file.
 
-  * I have placed the source code in this file in the public domain.
 
-  *
 
-  * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
 
-  */
 
- /*
 
- Package user contains user session management for webservers. Sessions are
 
- identified via session cookies and stored in memory on the server side.
 
- */
 
- package user
 
- import "fmt"
 
- /*
 
- Session models a user session object.
 
- */
 
- type Session interface {
 
- 	/*
 
- 		Id returns the session id.
 
- 	*/
 
- 	ID() string
 
- 	/*
 
- 	   User returns the user of the session.
 
- 	*/
 
- 	User() string
 
- 	/*
 
- 		GetAll returns all known session values.
 
- 	*/
 
- 	GetAll() map[string]interface{}
 
- 	/*
 
- 		Get returns a session.
 
- 	*/
 
- 	Get(key string) (interface{}, bool)
 
- 	/*
 
- 		Set sets a session value. A nil value deletes a value
 
- 		from the session.
 
- 	*/
 
- 	Set(key string, value interface{})
 
- 	/*
 
- 		String returns a string representation of the session.
 
- 	*/
 
- 	String() string
 
- }
 
- /*
 
- NewDefaultSession creates a new default session object.
 
- */
 
- func NewDefaultSession(id string, user string) Session {
 
- 	return &DefaultSession{id, user, make(map[string]interface{})}
 
- }
 
- /*
 
- DefaultSession is the default manager for web sessions.
 
- */
 
- type DefaultSession struct {
 
- 	id     string
 
- 	user   string
 
- 	values map[string]interface{}
 
- }
 
- /*
 
- ID returns the session id.
 
- */
 
- func (ds *DefaultSession) ID() string {
 
- 	return ds.id
 
- }
 
- /*
 
- User returns the user of the session.
 
- */
 
- func (ds *DefaultSession) User() string {
 
- 	return ds.user
 
- }
 
- /*
 
- GetAll returns all known session values.
 
- */
 
- func (ds *DefaultSession) GetAll() map[string]interface{} {
 
- 	return ds.values
 
- }
 
- /*
 
- Get returns a session.
 
- */
 
- func (ds *DefaultSession) Get(key string) (interface{}, bool) {
 
- 	ret, ok := ds.values[key]
 
- 	return ret, ok
 
- }
 
- /*
 
- Set sets a session value. A nil value deletes a value
 
- from the session.
 
- */
 
- func (ds *DefaultSession) Set(key string, value interface{}) {
 
- 	ds.values[key] = value
 
- }
 
- /*
 
- 	String returns a string representation of the session.
 
- */
 
- func (ds *DefaultSession) String() string {
 
- 	return fmt.Sprint("Session: ", ds.id, " (User:", ds.user, " Values:", ds.values, ")")
 
- }
 
 
  |