Follow redisstor docs, I'd like to modify this code to use redis to store sessions. Here is what I came up with:
package session
import (
"net/http"
"github.com/gorilla/sessions"
redisStore "gopkg.in/boj/redistore.v1"
)
var store *redisStore.RediStore
var Name string
var err error
store, err = redisStore.NewRediStore(10, "tcp", ":6379", "", []byte("secret-key"))
if err != nil {
log.Fatal("error getting redis store : ", err)
}
defer store.Close()
// Session stores session level information
type Session struct {
Options sessions.Options `json:"Options"`
Name string `json:"Name"`
SecretKey string `json:"SecretKey"`
}
// Configure the session cookie store
func Configure(s Session) {
Store := store
Store.Options = &s.Options
Name = s.Name
}
// Instance returns a new session, never returns an error
func Instance(r *http.Request) *sessions.Session {
session, _ := Store.Get(r, Name)
return session
}
But I get this error:
vendor/app/shared/session/session.go:19:1: syntax error: non-declaration statement outside function body
I'm wondering what is wrong here and how can I fix it?