engine.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package engine
  2. import (
  3. "fmt"
  4. "net/http"
  5. "golang-fave/engine/wrapper"
  6. "golang-fave/logger"
  7. "github.com/vladimirok5959/golang-server-sessions/session"
  8. )
  9. type Engine struct {
  10. Wrap *wrapper.Wrapper
  11. // Database
  12. // Actions
  13. // Front-end or Back-end
  14. }
  15. func Response(l *logger.Logger, w http.ResponseWriter, r *http.Request, s *session.Session, host, port, dirConfig, dirHtdocs, dirLogs, dirTemplate, dirTmp string) bool {
  16. wrap := wrapper.New(l, w, r, s, host, port, dirConfig, dirHtdocs, dirLogs, dirTemplate, dirTmp)
  17. eng := &Engine{Wrap: wrap}
  18. return eng.Process()
  19. }
  20. func (this *Engine) Process() bool {
  21. if this.Wrap.R.URL.Path == "/" {
  22. this.Wrap.W.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
  23. this.Wrap.W.Header().Set("Content-Type", "text/html")
  24. counter := this.Wrap.S.GetInt("counter", 0)
  25. // this.Wrap.LogAccess(fmt.Sprintf("Counter value was: %d", counter))
  26. this.Wrap.W.Write([]byte(`Logic -> (` + fmt.Sprintf("%d", counter) + `)`))
  27. counter++
  28. this.Wrap.S.SetInt("counter", counter)
  29. // this.Wrap.LogAccess(fmt.Sprintf("Counter value now: %d", counter))
  30. return true
  31. }
  32. return false
  33. }