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.
 
 
 
 

30 lines
537 B

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