changeset 8:8a7a15dc3b9d

use io.Writer
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Tue, 31 Mar 2020 15:28:25 +0900
parents 514dc6c6a683
children 2348344480da
files cmd_donwload.go syllabus/getSyllabus.go
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/cmd_donwload.go	Tue Mar 31 15:18:24 2020 +0900
+++ b/cmd_donwload.go	Tue Mar 31 15:28:25 2020 +0900
@@ -27,7 +27,7 @@
 	}
 	arr3 := []string{"601495001", "600625001"}
 
-	lwps, err := dh.LecIDStoDonwlodSyllabus(ctx, arr3)
+	lwps, err := dh.LecIDStoDonwlodSyllabus(ctx, arr3, outStream)
 	fmt.Println(lwps)
 	for _, lwp := range *lwps {
 		lec, err := dh.LecIDwFilePath2LectureStruct(&lwp)
--- a/syllabus/getSyllabus.go	Tue Mar 31 15:18:24 2020 +0900
+++ b/syllabus/getSyllabus.go	Tue Mar 31 15:28:25 2020 +0900
@@ -82,14 +82,14 @@
 	return true, nil
 }
 
-func (g *GetSyllabus) LecIDStoDonwlodSyllabus(ctx context.Context, lectureIDs []string) (*[]LectureWPath, error) {
+func (g *GetSyllabus) LecIDStoDonwlodSyllabus(ctx context.Context, lectureIDs []string, outStream io.Writer) (*[]LectureWPath, error) {
 	//var wg sync.WaitGroup
 	ch := make(chan LectureWPath, len(lectureIDs))
 	for _, id := range lectureIDs {
 		//wg.Add(1)
 		go func(id string) {
 			//defer wg.Done()
-			outputPath, _ := g.LecIDtoDownloadSyllabus(id)
+			outputPath, _ := g.LecIDtoDownloadSyllabus(id, outStream)
 			ch <- LectureWPath{
 				ID:   id,
 				Path: outputPath,
@@ -106,7 +106,7 @@
 }
 
 //LecIDtoDownloadSyllabus is download from lecture ID
-func (g *GetSyllabus) LecIDtoDownloadSyllabus(lectureID string) (string, error) {
+func (g *GetSyllabus) LecIDtoDownloadSyllabus(lectureID string, outStream io.Writer) (string, error) {
 	var strBuilder strings.Builder
 	strBuilder.WriteString(lectureID)
 	strBuilder.WriteString(".html")
@@ -114,7 +114,7 @@
 	outputPath := filepath.Join(g.outputdir, strBuilder.String())
 
 	if _, err := os.Stat(outputPath); err == nil {
-		fmt.Printf("already download %s.html\n", lectureID)
+		fmt.Fprintf(outStream, "already download %s.html\n", lectureID)
 		return outputPath, nil
 	}