modulepackage
0.0.0-20220805062111-f52026a1231a
Repository: https://github.com/tiket-oss/phpsessgo.git
Documentation: pkg.go.dev
# README
PHPSESSGO (Experimental)
The project aimed to imitating PHP Session Management in as much aspect as possible. This library may useful to porting PHP to Go without changing the request contracts. Any session parameter that created/modified should be accessible from PHP Server with same session source.
Usage Example
Create new session manager
import (
"github.com/tiket-oss/phpsessgo"
)
sessionManager := phpsessgo.NewSessionManager(
phpsessgo.DefaultSessionName,
&phpsessgo.UUIDCreator{},
&phpsessgo.PHPSessionEncoder{},
phpsessgo.SessionManagerConfig{
Expiration: time.Hour * 24,
CookiePath: "/",
CookieHttpOnly: true,
CookieDomain: "localhost",
CookieSecure: true,
},
)
Example of HTTP Handler function
func handleFunc(w http.ResponseWriter, r *http.Request) {
// PHP: session_start();
session, err := sessionManager.Start(w, r)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
defer sessionManager.Save(session)
// PHP: $_SESSION["hello"] = "world";
session.Value["hello"] = "world"
// PHP: session_id();
w.Write([]byte(session.SessionID))
}
Examples
Build and run the examples
# example using golang standard http library
make standard-http-example
# example using echo web framework
make echo-middleware-example
# Packages
No description provided by the author
Package mock is a generated GoMock package.
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
NewMockSessionManager creates a new mock instance.
NewSession create new instance of Session.
NewSessionManager create new instance of SessionManager.
No description provided by the author
No description provided by the author
No description provided by the author
# Constants
No description provided by the author
# Structs
MockSessionManager is a mock of SessionManager interface.
MockSessionManagerMockRecorder is the mock recorder for MockSessionManager.
No description provided by the author
Session handle creation/modification of session parametr.
No description provided by the author
UUIDCreator generate session ID using UUID V4.
# Interfaces
No description provided by the author
SessionIDCreator is adoptation of PHP SessionIDInterface Reference at https://www.php.net/manual/en/class.sessionidinterface.php.
No description provided by the author