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

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. "net/http"
  6. "strings"
  7. )
  8. func ipFilter(r *http.Request) error {
  9. var err error
  10. fmt.Println(r.RemoteAddr)
  11. reqIP := strings.Split(r.RemoteAddr, ":")[0]
  12. for _, ip := range config.BlockedIPs {
  13. if reqIP == ip {
  14. err = errors.New("ip not allowed to post images")
  15. }
  16. }
  17. for _, ip := range config.AllowedIPs {
  18. if reqIP != ip {
  19. err = errors.New("ip not allowed to post images")
  20. }
  21. }
  22. return err
  23. }