cgisession

package module
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

go-cgi-session

Golang library for reading and writing sessions created with Perl CGI::Session

GoDoc

Motivation

I am working on a project that needs to maintain login sessions between a Perl CGI appliation and Beego API. I could not find any existing modules to handle this, so I made this.

It is NOT well documented at this time.

Features

Storage Drivers
  • Memcached
Serializers
  • Data::Dumper ( Default CGI )
ID Generation
  • MD5

Beego usage

import(
	_ "github.com/jeffdoubleyou/go-cgi-session/beegoSessionProvider"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/session"
)

func main() {
	beego.BConfig.WebConfig.Session.SessionProvider = "cgi"
	beego.BConfig.WebConfig.Session.SessionProviderConfig = `{"driverConfig":{"servers":["10.64.98.74:11212"],"timeout":2}}`
	beego.BConfig.WebConfig.Session.SessionName = "CGISESSID"

	var sessionConfig = &session.ManagerConfig{
		EnableSetCookie: true,
		Gclifetime:      3600,
		Maxlifetime:     3600,
		Secure:          false,
		CookieLifeTime:  3600,
	}

	beego.GlobalSessions, _ = session.NewManager("cgi", sessionConfig)
	
	beego.Run()
}

I can't for the life of me get a custom provider to work without using beego.BConfig to set the params. I think there must be some sort of bug there, where it initializes the custom, then the default session provider.

Notes

There is a limtation to the storage at the moment. No complex objects can be stored.

Since the project I'm working on uses only Memcached storage, this is all that I have built, but could easily add more.

License

Copyright 2020 Jeffrey Weitz

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const (
	VERSION = "0.1.1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CGISession

type CGISession struct {
	// contains filtered or unexported fields
}

func Session

func Session(config ...*CGISessionConfig) *CGISession

func (*CGISession) Driver

func (s *CGISession) Driver(sessionDriver ...driver)

func (*CGISession) Exists

func (s *CGISession) Exists(sessionId string) bool

func (*CGISession) Freeze

func (s *CGISession) Freeze(params interface{}) (data []byte, err error)

func (*CGISession) GenerateSessionId

func (s *CGISession) GenerateSessionId() string

func (*CGISession) Id

func (s *CGISession) Id(idgen ...id)

func (*CGISession) Load

func (s *CGISession) Load(sessionId string) (ss *SessionStore)

func (*CGISession) New

func (s *CGISession) New(sessionId ...string) (ss *SessionStore)

Beego seems to insist on choosing it's own session ID, so we must accept a session ID here, although I don't fine this secure, since you could change someone's login to be pointed at your session information if you knew their session ID

func (*CGISession) Serializer

func (s *CGISession) Serializer(sessionSerializer ...serializer)

func (*CGISession) Thaw

func (s *CGISession) Thaw(data []byte) (map[string]interface{}, error)

type CGISessionConfig

type CGISessionConfig struct {
	Driver           string
	DriverConfig     *drivers.DriverConfig
	Id               string
	IdConfig         interface{}
	Serializer       string
	SerializerConfig interface{}
	ExpireSeconds    int64
	IPMatch          bool
}

type SessionStore

type SessionStore struct {
	// contains filtered or unexported fields
}

func (*SessionStore) ClearParam

func (ss *SessionStore) ClearParam(name string)

func (*SessionStore) Flush

func (ss *SessionStore) Flush() (bool, error)

func (*SessionStore) GetParam

func (ss *SessionStore) GetParam(name interface{}) interface{}

func (*SessionStore) IPMatches

func (ss *SessionStore) IPMatches() bool

You must set REMOTE_ADDR environmental variable to make use of IP matching

func (*SessionStore) IsExpired

func (ss *SessionStore) IsExpired() bool

func (*SessionStore) ParamFloat64

func (ss *SessionStore) ParamFloat64(name string, value ...float64) float64

func (*SessionStore) ParamInt

func (ss *SessionStore) ParamInt(name string, value ...int) int

func (*SessionStore) ParamInt64

func (ss *SessionStore) ParamInt64(name string, value ...int64) int64

func (*SessionStore) ParamString

func (ss *SessionStore) ParamString(name string, value ...string) string

func (*SessionStore) SessionId

func (ss *SessionStore) SessionId() string

func (*SessionStore) SetParam

func (ss *SessionStore) SetParam(name, value interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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