Code cleanup
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -19,12 +14,8 @@ var CooldownMutex sync.RWMutex
|
||||
|
||||
const POST_COOLDOWN = 15 * time.Second
|
||||
|
||||
// const POST_COOLDOWN = 0 * time.Second
|
||||
|
||||
const THREAD_COOLDOWN = 2 * time.Minute
|
||||
|
||||
// const THREAD_COOLDOWN = 0 * time.Minute
|
||||
|
||||
func GetRemainingCooldown(ip string, m map[string]time.Time, duration time.Duration) time.Duration {
|
||||
CooldownMutex.RLock()
|
||||
last, exists := m[ip]
|
||||
@@ -44,22 +35,3 @@ func BeginCooldown(ip string, m map[string]time.Time, duration time.Duration) {
|
||||
m[ip] = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
func GetIP(r *http.Request) string {
|
||||
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
|
||||
parts := strings.Split(xff, ",")
|
||||
return strings.TrimSpace(parts[0])
|
||||
}
|
||||
|
||||
// Fallback to RemoteAddr
|
||||
ip, _, err := net.SplitHostPort(r.RemoteAddr)
|
||||
if err != nil {
|
||||
return r.RemoteAddr
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
func HashIp(ip string) string {
|
||||
checksum := sha256.Sum256([]byte(ip))
|
||||
return hex.EncodeToString(checksum[:])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user