Skip to content

Instantly share code, notes, and snippets.

@priesdelly
Created April 4, 2019 03:52
Show Gist options
  • Save priesdelly/8bdd583ddb20e21a330aaed3f6be427d to your computer and use it in GitHub Desktop.
Save priesdelly/8bdd583ddb20e21a330aaed3f6be427d to your computer and use it in GitHub Desktop.
Check url http status from url.txt
package main
import (
"bufio"
"fmt"
"log"
"net/http"
"os"
"strconv"
)
func main() {
file, err := os.Open("url.txt")
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
for scanner.Scan() {
var oldURL = scanner.Text()
resp, err := client.Get(oldURL)
if err != nil {
log.Fatal(err)
}
s := strconv.Itoa(resp.StatusCode)
fmt.Printf("Http Status : %v\n", s)
fmt.Printf("Url: %v\n", oldURL)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment