sessionfilter.go 559 B

1234567891011121314151617181920212223242526
  1. package filter
  2. import (
  3. "net/http"
  4. "strings"
  5. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  6. )
  7. // 登录限制
  8. type sessionfilter struct {
  9. App *xweb.App
  10. }
  11. // 继承过滤器方法
  12. func (l *sessionfilter) Do(w http.ResponseWriter, req *http.Request) bool {
  13. session := l.App.SessionManager.Session(req, w)
  14. if req.RequestURI == "/jyActivity/getConfig/info" || strings.Contains(req.RequestURI, "/sse/") {
  15. return true
  16. }
  17. if session.Get("userId") == nil {
  18. w.Write([]byte(`{"error_code":-1,"error_msg":"需要登录!"}`))
  19. return false
  20. }
  21. return true
  22. }