Passed
Push — master ( fcc4d9...d0843d )
by Emre
02:21
created

main.init   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
package main
2
3
import (
4
	"flag"
5
	"fmt"
6
	"net/http"
7
	"os"
8
)
9
10
var (
11
	URI            string
0 ignored issues
show
introduced by
exported var URI should have comment or be unexported
Loading history...
12
	IsIndex        bool
13
	OutputFileName string
14
    Verbose        bool
15
)
16
17
func init() {
18
	flag.StringVar(&URI, "uri", "", "Sitemap uri full path")
19
	flag.BoolVar(&IsIndex, "index", false, "Is this uri sitemap index file?")
20
	flag.StringVar(&OutputFileName, "out", "sitemap.xml", "Output file name for valid sitemap file")
21
    flag.BoolVar(&Verbose,"verbose",false,"Verbose mode")
22
}
23
func main() {
24
    flag.Parse()
25
    if (URI == "" && OutputFileName == "" && IsIndex == false) || (URI == "" && IsIndex == false) {
26
        help()
27
    }
28
    if(Verbose){
29
        fmt.Println(IsIndex)
30
    }
31
    if IsIndex {
32
        if(Verbose){
33
            fmt.Println("Batch process started for index file")
34
        }
35
        batchProcess(URI)
36
    } else {
37
        singleProcess(URI, OutputFileName)
38
    }
39
40
    fmt.Println("Completed")
41
}
42
43
func readXMLFromResponse(resp *http.Response) []byte {
44
	var rawXMLData []byte
45
	for {
46
		content := make([]byte, 1024)
47
		n, _ := resp.Body.Read(content)
48
		for _, d := range content {
49
			rawXMLData = append(rawXMLData, d)
50
		}
51
		if n == 0 {
52
			break
53
		}
54
	}
55
	return rawXMLData
56
}
57
58
func help() {
59
	fmt.Printf(
60
		`You have to type sitemap url and output file name
61
Usage: checker -uri=http://sitename.com/sitemap.xml -out=sitemap.xml
62
Parameters:
63
		-out: (string) output file name for valid xml
64
		-uri: (string) sitemap or sitemapindex uri
65
		-index: (bool) uri is sitemapindex or not
66
`,
67
	)
68
	os.Exit(1)
69
}
70