GithubHelp home page GithubHelp logo

Comments (4)

SilverCory avatar SilverCory commented on June 28, 2024

A look at the clear function gives light on this!
#52

s.Session().Values appears to be a list of all keys!

from sessions.

TJM avatar TJM commented on June 28, 2024

my session does not have .Session()? I assume that is what you meant by "s" ? Maybe?

	r.GET("/", func(c *gin.Context) {
	session := sessions.Default(c)
// the rest

... session is an interface

sessions/sessions.go

Lines 24 to 47 in 19716a2

type Session interface {
// ID of the session, generated by stores. It should not be used for user data.
ID() string
// Get returns the session value associated to the given key.
Get(key interface{}) interface{}
// Set sets the session value associated to the given key.
Set(key interface{}, val interface{})
// Delete removes the session value associated to the given key.
Delete(key interface{})
// Clear deletes all values in the session.
Clear()
// AddFlash adds a flash message to the session.
// A single variadic argument is accepted, and it is optional: it defines the flash key.
// If not defined "_flash" is used by default.
AddFlash(value interface{}, vars ...string)
// Flashes returns a slice of flash messages from the session.
// A single variadic argument is accepted, and it is optional: it defines the flash key.
// If not defined "_flash" is used by default.
Flashes(vars ...string) []interface{}
// Options sets configuration for a session.
Options(Options)
// Save saves all sessions used during the current request.
Save() error
}

from sessions.

SilverCory avatar SilverCory commented on June 28, 2024

@TJM I'm not sure that was 2 years ago, context could have been better on my behalf.

Reevaluating this, if you cast it to the actual implementation of the Session interface then there is an object in there.

For example the cookie implementation is:
https://github.com/gorilla/sessions/blob/master/sessions.go#L31

from sessions.

TJM avatar TJM commented on June 28, 2024

Sorry, I realized I had responded to a zombie issue after I already hit submit :)

Thanks, I will try that "cast" idea. Displaying all keys in the session is really sortof a debugging operation anyhow, but I can see how it might be useful enough to add a session.GetValues() method. What do you think?

Also, the "example" code for session/cookie does not encrypt the cookies, so I was able to just use "Inspect" -> application -> cookie... and base64 decode (it was two different layers), and see what I was trying to see at the client level.

I was going to try to just "output" (c.JSON) everything in the session, but then I realized it was a waste of time/effort as that would not be something anyone would likely want to do.

Thanks,
Tommy

from sessions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.