-
Notifications
You must be signed in to change notification settings - Fork 11
Transport Service
Adam Hanna edited this page May 4, 2017
·
2 revisions
The standard transport service uses cookies to read / write sessions. The available options that can be set when creating a new transport service are:
// Options defines the behavior of the transport service
type Options struct {
CookieName string
CookiePath string
HTTPOnly bool
Secure bool
}
A transport service can be created by calling the New function: seshTransport := transport.New(transport.Options{})
If you'd like to define your own transport service, it's as easy as implementing the methods of the transport interface. Say that you'd like to transport hashed sessionID's in the header X-Session-Token
, for example:
type HeaderTransport struct {
}
func (h *HeaderTransport) SetSessionOnResponse(session string, userSession *user.Session, w http.ResponseWriter) error {
w.Header().Set("X-Session-Token", session)
return nil
}
func (h *HeaderTransport) DeleteSessionFromResponse(w http.ResponseWriter) error {
w.Header().Del("X-Session-Token")
return nil
}
func (h *HeaderTransport) FetchSessionIDFromRequest(r *http.Request) (string, error) {
return r.Header.Get("X-Session-Token"), nil
}
...
// Then use your custom defined struct and methods when defining the sessions service
seshTransport := &HeaderTransport{}
sesh = sessions.New(seshStore, seshAuth, seshTransport, sessions.Options{})