Skip to content

Commit afac708

Browse files
committed
fix: change type: concurrency is uint
1 parent d932f91 commit afac708

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

kadai3/imura81gt/rget/cmd/rget/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func main() {
12-
concurrency := flag.Int("c", 2, "concurrency")
12+
concurrency := flag.Uint("c", 2, "concurrency")
1313
outputDir := flag.String("o", "./", "output directory")
1414

1515
flag.Parse()

kadai3/imura81gt/rget/rget.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
)
1515

1616
type Option struct {
17-
Concurrency int
17+
Concurrency uint
1818
URL string
1919
OutputDir string
2020
ContentLength int64
@@ -86,10 +86,17 @@ func (o *Option) contentLength() error {
8686
func (o *Option) divide() {
8787
var units []Unit
8888

89-
//TODO: if o.ContentLength < int64(o.Concurrency)
89+
if o.Concurrency == 0 {
90+
o.Concurrency = 1
91+
}
92+
93+
if o.ContentLength < int64(o.Concurrency) {
94+
o.Concurrency = uint(o.ContentLength)
95+
}
96+
9097
sbyte := o.ContentLength / int64(o.Concurrency)
9198

92-
for i := 0; i < o.Concurrency; i++ {
99+
for i := 0; i < int(o.Concurrency); i++ {
93100
units = append(units, Unit{
94101
RangeStart: int64(i) * sbyte,
95102
RangeEnd: int64((i+1))*sbyte - 1,

0 commit comments

Comments
 (0)