helpers.go 708 B

123456789101112131415161718192021222324252627282930
  1. package helpers
  2. import (
  3. "errors"
  4. "log"
  5. "net/http"
  6. "os"
  7. "regexp"
  8. "github.com/vladimirok5959/golang-server-sessions/session"
  9. )
  10. var mHtml = regexp.MustCompile(`>[\n\t\r\s]+<`)
  11. var mHtmlLeft = regexp.MustCompile(`>[\n\t\r\s]+`)
  12. var mHtmlRight = regexp.MustCompile(`[\n\t\r\s]+<`)
  13. func MinifyHtmlCode(str string) string {
  14. str = mHtml.ReplaceAllString(str, "><")
  15. str = mHtmlLeft.ReplaceAllString(str, ">")
  16. str = mHtmlRight.ReplaceAllString(str, "<")
  17. return str
  18. }
  19. func SessionStart(w http.ResponseWriter, r *http.Request) (*session.Session, error) {
  20. sess, err := session.New(w, r, "/tmp")
  21. if err != nil && !errors.Is(err, os.ErrNotExist) {
  22. log.Printf("%s\n", err.Error())
  23. }
  24. return sess, err
  25. }