You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
446 B

package main
import (
"errors"
"fmt"
"net/http"
"strings"
)
func ipFilter(r *http.Request) error {
var err error
fmt.Println(r.RemoteAddr)
reqIP := strings.Split(r.RemoteAddr, ":")[0]
for _, ip := range config.BlockedIPs {
if reqIP == ip {
err = errors.New("ip not allowed to post images")
}
}
for _, ip := range config.AllowedIPs {
if reqIP != ip {
err = errors.New("ip not allowed to post images")
}
}
return err
}