gernest / utron

A lightweight MVC framework for Go(Golang)
MIT License
2.22k stars 149 forks source link

Session store #82

Closed nicola-spb closed 7 years ago

nicola-spb commented 7 years ago

I`m start learning golang. I want to change sessionStore to redis and I found this code. Is it right? May be should be "return ctx.SessionStore.Get" ?

//GetSession retrieves session with a given name.
func (ctx *Context) GetSession(name string) (*sessions.Session, error) {
    if ctx.SessionStore != nil {
        return ctx.SessionStore.New(ctx.Request(), name)
    }
    return nil, errNoStore
}
nicola-spb commented 7 years ago

Is this parameter SessionSecure (in config) used in somewhere?

gernest commented 7 years ago

I`m start learning golang. I want to change sessionStore to redis and I found this code. Is it right? May be should be "return ctx.SessionStore.Get" ?

@nicola-spb That code is okay, but regarding redis session, you can just override App.SessionStore with the redis session implementation

Is this parameter SessionSecure (in config) used in somewhere?

Yes , it is passed to gorilla.Session.Options check here https://github.com/gernest/utron/blob/1f157f3b25f8ea71b1705f0d699cd1cffde65779/app/app.go#L153

nicola-spb commented 7 years ago

Sorry I made mistake. I wanted to say about cfg.SessionStore in config. P.S. Now I replaced method getSesionStore for using Redis session

gernest commented 7 years ago

Sorry I made mistake. I wanted to say about cfg.SessionStore in config. P.S. Now I replaced method getSesionStore for using Redis session

@nicola-spb what do you mean? Can I see your code if possible? getSesionStore looks like a private function so replacing it from where?

nicola-spb commented 7 years ago

I forked it for myself. I want to replace gorm to sqlx too and maybe replace html/template.

func getSesionStore(cfg *config.Config) (sessions.Store, error) {
    store, err := redistore.NewRediStore(10, "tcp", ":6379", "", keyPairs(cfg.SessionKeyPair)...)
    if err != nil {
        panic(err)
    }
    store.SetMaxAge(cfg.SessionMaxAge)
    return store, nil
}
gernest commented 7 years ago

I see, that looks okay to me.

nicola-spb commented 7 years ago

Maybe you should make it more flexible. I saw some frameworks but I think they so big and I prefer your.

gernest commented 7 years ago

@nicola-spb thanks. It is already flexible. You can replace view i.e html/template and it is possible to replace gorm too( albeit with some effort)

There is a lot of areas for improvement. You can help by opening issues for feature request, so we can make utron more awesome.

nicola-spb commented 7 years ago

Ok. Thank you.

gernest commented 7 years ago

@nicola-spb

Check this example app https://github.com/utronframework/upload It does not use gorm at all. You can also poke around it to implement custom view that doesnt use the one shipped.

Honestly you don't need to modify utron source to use different ORM or template rendering logic.

nicola-spb commented 7 years ago

Ok. I started learning golang (after java, php) and I don`t get used to interface.