utils.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package statistic
  2. import (
  3. "fmt"
  4. "net"
  5. "time"
  6. )
  7. func isWebPageExtension(ext string) bool {
  8. webPageExts := []string{".html", ".htm", ".php", ".jsp", ".aspx", ".js", ".jsx"}
  9. for _, e := range webPageExts {
  10. if e == ext {
  11. return true
  12. }
  13. }
  14. return false
  15. }
  16. func IsBeforeToday(dateString string) bool {
  17. layout := "2006_01_02"
  18. date, err := time.Parse(layout, dateString)
  19. if err != nil {
  20. fmt.Println("Error parsing date:", err)
  21. return false
  22. }
  23. today := time.Now().UTC().Truncate(24 * time.Hour)
  24. return date.Before(today) || dateString == time.Now().Format(layout)
  25. }
  26. // Check if the IP string is a valid ip address
  27. func IsValidIPAddress(ip string) bool {
  28. // Check if the string is a valid IPv4 address
  29. if parsedIP := net.ParseIP(ip); parsedIP != nil && parsedIP.To4() != nil {
  30. return true
  31. }
  32. // Check if the string is a valid IPv6 address
  33. if parsedIP := net.ParseIP(ip); parsedIP != nil && parsedIP.To16() != nil {
  34. return true
  35. }
  36. // If the string is neither a valid IPv4 nor IPv6 address, return false
  37. return false
  38. }