You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"lu-example/controller""lu-example/lib""github.com/lugolang/static""github.com/vincentLiuxiang/lu"
)
funcmain() {
app:=lu.New()
// get a redis connredis:=lib.NewRedis("tcp", "localhost:6379", 60*60)
// get a session middleware instance// sid is the key-value pair's key stored in cookiesessionMw:=controller.NewSessionMiddleware("sid")
// get a login middleware instanceloginMw:=controller.NewLoginMiddleware("sid")
// init a static file middlewarefs:=static.DefaultFSStatic:=static.New(fs)
// login page /static/login/index.htmlapp.Get("/static/login", Static)
// Post, pass password, username to the server, check the truth and sign cookie / session, this is a restful apiapp.Post("/login", loginMw.Check(redis))
/** * app.Get("/getName", ...) * app.Post("/register", ...) */// sign session to any request via ctx.UserValue["session"]app.Use("/", sessionMw.Middleware(redis))
// judge if a request really has session info via cookie// if ctx.UserValue["session"] == nil, redirect to /static/login/app.Use("/", loginMw.Middleware())
// if ctx.UserValue["session"] != nil, visi home pageapp.Get("/static/home", Static)
app.Listen(":8080")
}
go get -u github.com/valyala/fasthttp
go get -u github.com/lugolang/static
go get -u github.com/vincentLiuxiang/lu
go run ./server.go