Created
February 1, 2020 14:47
-
-
Save yusukebe/fd71574a13de79aac850d1828d3c2818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"encoding/csv" | |
"fmt" | |
"log" | |
"os" | |
"strings" | |
"time" | |
"sync" | |
) | |
func main() { | |
file, err := os.Open("caribbean.csv") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer file.Close() | |
scanner := bufio.NewScanner(file) | |
wg := &sync.WaitGroup{} | |
for scanner.Scan() { | |
line := scanner.Text() | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
parseCSV(line) | |
}() | |
} | |
wg.Wait() | |
if err := scanner.Err(); err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println("---------------------------DONE------------------------------") | |
} | |
func parseCSV(s string) { | |
r := csv.NewReader(strings.NewReader(s)) | |
record, err := r.Read() | |
if err != nil { | |
log.Fatal("Read error: ", err) | |
} | |
time.Sleep(time.Millisecond * 10) // 10msの処理をさせる | |
fmt.Println(record[3]) // タイトルを表示 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment