engine.go 945 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package engine
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/vladimirok5959/golang-server-sessions/session"
  6. )
  7. type Engine struct {
  8. w http.ResponseWriter
  9. r *http.Request
  10. s *session.Session
  11. host string
  12. port string
  13. dConfig string
  14. dHtdocs string
  15. dLogs string
  16. dTemplate string
  17. dTmp string
  18. }
  19. func New(w http.ResponseWriter, r *http.Request, s *session.Session, host, port, dirConfig, dirHtdocs, dirLogs, dirTemplate, dirTmp string) *Engine {
  20. return &Engine{w, r, s, host, port, dirConfig, dirHtdocs, dirLogs, dirTemplate, dirTmp}
  21. }
  22. func (this *Engine) Response() bool {
  23. if this.r.URL.Path == "/" {
  24. this.w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  25. this.w.Header().Set("Content-Type", "text/html")
  26. counter := this.s.GetInt("counter", 0)
  27. this.w.Write([]byte(`Logic -> (` + fmt.Sprintf("%d", counter) + `)`))
  28. counter++
  29. this.s.SetInt("counter", counter)
  30. return true
  31. }
  32. return false
  33. }