Giter VIP home page Giter VIP logo

Comments (9)

Fenny avatar Fenny commented on May 4, 2024 14

I'm adding support for memcache, mysql, postgres, redis and sqlite3 ๐Ÿ‘

from fiber.

Fenny avatar Fenny commented on May 4, 2024 4

Hi @sachinbhutani, github.com/gofiber/session is on our TODO list for v1.8.4+

from fiber.

Fenny avatar Fenny commented on May 4, 2024 4

@sachinbhutani, @koddr, @rezam90, @samuel-a-cooper I have been working on this for a while and I just released v0.0.1, just wanted to give an update and feedback is welcome!

https://github.com/gofiber/session

My apologizes it took so long, I was really busy with other things for the past 2 weeks.

package main

import (
  "fmt"

  "github.com/gofiber/fiber"
  "github.com/gofiber/session" // v0.0.1
)

func main() {
  app := fiber.New()
  
  // optional config
  config := session.Config{
    Key:    "dinosaurus",       // default: "sessionid"
    Lookup: "header",           // default: "cookie"
    Domain: "google.com",       // default: ""
    Expires: 30 * time.Minutes, // default: 2 * time.Hour
    Secure:  true,              // default: false
  }

  // create session handler
  sessions := session.New(config)

  app.Get("/", func(c *fiber.Ctx) {
    store := sessions.Start(c)   // get/create new session

    store.ID()                   // returns session id
    store.Empty()                // empty storage
    store.Destroy()              // delete storage + cookie
    store.Get("john")            // get from storage
    store.Regenerate()           // generate new session id
    store.Delete("john")         // delete from storage
    store.Set("john", "doe")     // save to storage
    store.Expires(2 * time.Hour) // set session expiration
  })
  
  app.Listen(3000)
}

from fiber.

sachinbhutani avatar sachinbhutani commented on May 4, 2024

awesome! is there's a way to extend the functionality to use a redis or other k/v stores ? or you recommend I write a new middleware module for it, like "session-redis" like yours ?

from fiber.

Fenny avatar Fenny commented on May 4, 2024

@thomasvvugt created a experimental storage provider
https://github.com/thomasvvugt/fiber-session

Not fully tested yet, feedback is welcome.

from fiber.

thomasvvugt avatar thomasvvugt commented on May 4, 2024

@Fenny and I are working a fresh version of the session middleware. Spoiler: We are providing the ability to implement multiple third party session providers! ๐ŸŽ‰

from fiber.

Shareed2k avatar Shareed2k commented on May 4, 2024

can it be easy to implement just storage interface, and we can implement storage methods and use it with other storages without make pr to the repo and hard code it...
like here

type Config struct {
...
	// Storage configs
	Memcache StorageMemcache
	MySQL StorageMySQL
	// TODO: Add SQLite3 (compilation error)
	Redis StorageRedis
	Postgres StoragePostgres
}

or some registry with storage interface, if you want to use multiply storage ...

we can use Provider interface...

// Provider interface implemented by providers
type Provider interface {
	Get(id []byte) ([]byte, error)
	Save(id, data []byte, expiration time.Duration) error
	Destroy(id []byte) error
	Regenerate(id, newID []byte, expiration time.Duration) error
	Count() int
	NeedGC() bool
	GC()
}

from fiber.

thomasvvugt avatar thomasvvugt commented on May 4, 2024

Hi @Shareed2k , thanks for your comment. We stuck with the interface option for now, we keep you all posted about our progress in the coming days!

from fiber.

Fenny avatar Fenny commented on May 4, 2024

@sachinbhutani @Shareed2k fiber/session supports multiple providers in v1.0.0:

  • memcache
  • mysql
  • postgres
  • redis
  • sqlite3

from fiber.

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.