-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
69 lines (63 loc) · 1.46 KB
/
main.go
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
60
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"fmt"
"net/http"
"os"
)
var (
URI string
IsIndex bool
OutputFileName string
Verbose bool
)
func init() {
flag.StringVar(&URI, "uri", "", "Sitemap uri full path")
flag.BoolVar(&IsIndex, "index", false, "Is this uri sitemap index file?")
flag.StringVar(&OutputFileName, "out", "sitemap.xml", "Output file name for valid sitemap file")
flag.BoolVar(&Verbose,"verbose",false,"Verbose mode")
}
func main() {
flag.Parse()
if (URI == "" && OutputFileName == "" && IsIndex == false) || (URI == "" && IsIndex == false) {
help()
}
if(Verbose){
fmt.Println(IsIndex)
}
if IsIndex {
if(Verbose){
fmt.Println("Batch process started for index file")
}
batchProcess(URI)
} else {
singleProcess(URI, OutputFileName)
}
fmt.Println("Completed")
}
func readXMLFromResponse(resp *http.Response) []byte {
var rawXMLData []byte
for {
content := make([]byte, 1024)
n, _ := resp.Body.Read(content)
for _, d := range content {
rawXMLData = append(rawXMLData, d)
}
if n == 0 {
break
}
}
return rawXMLData
}
func help() {
fmt.Printf(
`You have to type sitemap url and output file name
Usage: checker -uri=http://sitename.com/sitemap.xml -out=sitemap.xml
Parameters:
-out: (string) output file name for valid xml
-uri: (string) sitemap or sitemapindex uri
-index: (bool) uri is sitemapindex or not
`,
)
os.Exit(1)
}