-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpCheck.go
More file actions
59 lines (47 loc) · 1.25 KB
/
Copy pathHttpCheck.go
File metadata and controls
59 lines (47 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
func hello(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello " + (r.URL.Path)[1:]))
}
func usage() {
fmt.Println("The usage of this command is =)... ")
}
func main() {
var urlParsed bytes.Buffer
url := flag.String("url", "http://www.google.es", "This is the URL to check.")
rcode := flag.Int("code", 200, "This is the expected HTTP response code.")
content := flag.String("content", "aaa", "This is the expected content.")
flag.Parse()
test := *url
fmt.Println(!strings.Contains(test[:7], "https://"))
fmt.Println(!strings.Contains(test[:6], "http://"))
if !strings.Contains(test[0:6], "http://") && !strings.Contains(test[0:7], "https://") {
urlParsed.WriteString("http://")
urlParsed.WriteString(*url)
} else {
urlParsed.WriteString(*url)
}
fmt.Println(urlParsed.String())
r, e := http.Get(urlParsed.String())
if e != nil {
log.Panic(e)
}
if r.StatusCode != *rcode {
fmt.Printf("Unexpected response status %d, expected %d", r.StatusCode, *rcode)
} else {
fmt.Printf("OK")
}
b, _ := ioutil.ReadAll(r.Body)
if strings.Contains(string(b[:]), *content) {
fmt.Printf("The URL %s contains the string %s", *url, *content)
}
return
}