func main() { normals := getFiles(datasetPath + "NORMAL_5X5") rankedsolo := getFiles(datasetPath + "RANKED_SOLO") log.Printf("Normals:\n%v\n", normals) log.Printf("Ranked solo:\n%v\n", rankedsolo) db := db.New_dbconn() defer db.Conn.Close() // // // var wg sync.WaitGroup wg.Add(len(normals)) for _, fileinfo := range normals { go batch2db(fileinfo, &wg, db.Conn) } wg.Add(len(rankedsolo)) for _, fileinfo := range rankedsolo { go batch2db(fileinfo, &wg, db.Conn) } wg.Wait() }
func main() { db := db.New_dbconn() defer db.Conn.Close() log.Println("Connected to DB.") cli := http.DefaultClient req, err := http.NewRequest("GET", riotAPI_Challenge.Endpoints.Champions, nil) if err != nil { panic(err) } resp, err := cli.Do(req) if err != nil { panic(err) } defer resp.Body.Close() tmpbody, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } var Response response err = json.Unmarshal(tmpbody, &Response) if err != nil { panic(err) } var wg sync.WaitGroup log.Println(Response.Version) for _, champ := range Response.Data { tmpchamp := champ.(map[string]interface{}) tmp := champion{Name: tmpchamp["name"].(string), ChampId: tmpchamp["id"].(float64), Key: tmpchamp["key"].(string)} Champions = append(Champions, tmp) } wg.Add(len(Champions)) for _, champ := range Champions { go insert2db(champ, db.Conn, &wg) } wg.Wait() }
func main() { requests := make(chan bool, 250) db := db.New_dbconn() defer db.Conn.Close() var idBatch []idbatch rows, err := db.Conn.Query("select id, match_id, region from matchbatch order by id asc;") if err != nil { panic(err) } defer rows.Close() for rows.Next() { var tmpidbatch idbatch err := rows.Scan(&tmpidbatch.DbId, &tmpidbatch.Id, &tmpidbatch.Region) if err != nil { panic(err) } idBatch = append(idBatch, tmpidbatch) } err = rows.Err() if err != nil { panic(err) } for _, req := range idBatch { requests <- true go game2db(req, requests) } // Limit requests according to the 'requests' channel for i := 0; i < cap(requests); i++ { requests <- true } }