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
539 B

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