// call against the Wikipedia API and assemble results
call against the Wikipedia API and assemble results
// call against the Wikipedia API and assemble results
func requestWiki(name string, continued string, response []string) []string {
	requestTemplate := []string{
		"https://en.wikipedia.org/w/api.php?",
	}
	requestTemplate = utils.MakeParams(requestTemplate, wikiParams)
	if continued == "null" {
		return response
	}
	requestTemplate = append(requestTemplate, "&titles="+url.QueryEscape(name))
	if continued != "initial" {
		requestTemplate = append(requestTemplate, "&plcontinue="+continued)
	}
	resp, err := http.Get(strings.Join(requestTemplate, ""))
	if err != nil {
		log.Fatal(err)
	}
	jsonResponse, err := ioutil.ReadAll(resp.Body)
	defer resp.Body.Close()
	if err != nil {
		log.Fatal(err)
	}
	raw := parseWiki(string(jsonResponse))
	for _, entry := range raw.Array() {
		if !isMetaLink(string(entry.Get("title").String())) {
			response = append(response, string(entry.Get("title").String()))
		}
	}
	nextContinued := "null"
	if gjson.Get(string(jsonResponse), "continue.plcontinue").Exists() {
		nextContinued = gjson.Get(string(jsonResponse), "continue.plcontinue").String()
	}
	return requestWiki(name, nextContinued, response)
}
func requestWiki ( name string , continued string , response [ ] string ) [ ] string { requestTemplate := [ ] string { " " , } requestTemplate = utils . MakeParams ( requestTemplate , wikiParams ) if continued == " " { return response } requestTemplate = append ( requestTemplate , " " + url . QueryEscape ( name ) ) if continued != " " { requestTemplate = append ( requestTemplate , " " + continued ) } resp , err := http . Get ( strings . Join ( requestTemplate , " " ) ) if err != nil { log . Fatal ( err ) } jsonResponse , err := ioutil . ReadAll ( resp . Body ) defer resp . Body . Close ( ) if err != nil { log . Fatal ( err ) } raw := parseWiki ( string ( jsonResponse ) ) for _ , entry := range raw . Array ( ) { if ! isMetaLink ( string ( entry . Get ( " " ) . String ( ) ) ) { response = append ( response , string ( entry . Get ( " " ) . String ( ) ) ) } } nextContinued := " " if gjson . Get ( string ( jsonResponse ) , " " ) . Exists ( ) { nextContinued = gjson . Get ( string ( jsonResponse ) , " " ) . String ( ) } return requestWiki ( name , nextContinued , response ) }
call against the Wikipedia API and assemble results
call against the Wikipedia API and assemble results
// not sure why we need this. Cannot just append another array, even though it is of the correct type // learnnote: check out what is preventing it working (some kind of type inconsistency?) // for the time being, we can use this to cast the slice type to string // recurse through the continue results from Wikipedia