maxConcurrentRequests*int// the maximum number of allowed in flight HTTP requests. Only used with testing mode.
)
// Redirect is an instance of a single row in the csv file. It contains a value from each of the columns of the input csv file
typeRedirectstruct{
sourceURLstring// the source URL we are redirecting from
destinationURLstring// the target URL we are redirecting to
statusCodeint// 301 or 302
}
funcmain(){
// Parse flags and determine actions
action:=flag.String("action","config","action can be either 'config' or 'test'. 'config' will read the input csv file and generate FortiOS compliant configuration to create redirection policies. 'test' will read the input csv file and validate that the redirects are actually working by making requests at the source URL and validating a redirect to the destination URL actually occurs.")
csvFilePath:=flag.String("csvfile","redirects.csv","path to an input csv file. The first column of the file should be the source URL, the second column of the file should be the destination URL, and the third column should be the status code (for example 301 or 302).")
maxConcurrentRequests=flag.Int("concurrentReq",8,"only used with the action 'test'. Determines the maximum number concurrent HTTP GET requests which can be in flight at any given time.")
flag.Parse()
// Open and parse the CSV file and set up decoding
csvFile,err:=os.Open(*csvFilePath)
iferr!=nil{
log.Fatalf("failed to open input csvFile '%s': %v",*csvFilePath,err)
}
rows:=csv.NewReader(csvFile)
// Loop through each row until we reach the end and populate a slice of type Redirect
varredirects[]Redirect
for{
row,err:=rows.Read()
iferr==io.EOF{
break// We've hit the end of the file
}
iferr!=nil{
log.Printf("failed to read row in CSV file: %v",err)
}
// Create a new instance of type Redirect and populate with data from CSV file