Advertisement
A_GUES

Go AdBlocker

May 30th, 2023
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.81 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "strings"
  6. )
  7.  
  8. // List of ad domains to block
  9. var blockedDomains = []string{
  10.     "adserver.com",
  11.     "adservice.net",
  12.     "exampleads.com",
  13. }
  14.  
  15. func main() {
  16.     // Simulating network requests
  17.     requests := []string{
  18.         "https://example.com",
  19.         "https://adserver.com/ad1",
  20.         "https://exampleads.com/banner",
  21.     }
  22.  
  23.     numRequests := len(requests)
  24.     numDomains := len(blockedDomains)
  25.  
  26.     // Check each request
  27.     for i := 0; i < numRequests; i++ {
  28.         blocked := false
  29.  
  30.         // Check against each blocked domain
  31.         for j := 0; j < numDomains; j++ {
  32.             if strings.Contains(requests[i], blockedDomains[j]) {
  33.                 blocked = true
  34.                 break
  35.             }
  36.         }
  37.  
  38.         // Print the result
  39.         if blocked {
  40.             fmt.Printf("%s: Blocked\n", requests[i])
  41.         } else {
  42.             fmt.Printf("%s: Allowed\n", requests[i])
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement