-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (55 loc) · 1.3 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"image-watermark/utils"
"os"
"time"
)
const inputDirPath = "./input"
func main() {
start := time.Now()
watermark := utils.GetWatermark()
inputDir, err := os.ReadDir(inputDirPath)
if err != nil {
fmt.Println(err)
return
}
if len(inputDir) == 0 {
fmt.Println("Input directory is empty!")
fmt.Println("Exiting...")
return
}
doneChannels := make([]chan bool, len(inputDir))
errorChannels := make([]chan error, len(inputDir))
for i, entry := range inputDir {
doneChannels[i] = make(chan bool, 1)
errorChannels[i] = make(chan error, 1)
if !entry.IsDir() {
entryName := entry.Name()
go utils.ProcessImage(inputDirPath, entryName, watermark, doneChannels[i], errorChannels[i])
}
}
for i := range inputDir {
select {
case done := <-doneChannels[i]:
if done {
fmt.Println("File " + inputDir[i].Name() + " was processed successfully!")
}
case err := <-errorChannels[i]:
if err != nil {
fmt.Println("Image" + inputDir[i].Name() + " was processed with error!")
fmt.Println(err)
}
}
}
duration := time.Since(start)
fmt.Println()
fmt.Println("Done!")
fmt.Println("Total processing time: ", duration)
err = utils.GetUserInputForClearInputDir(inputDirPath)
if err != nil {
fmt.Println(err)
return
}
time.Sleep(time.Second)
}