Created
April 4, 2019 03:52
-
-
Save priesdelly/8bdd583ddb20e21a330aaed3f6be427d to your computer and use it in GitHub Desktop.
Check url http status from url.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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