Merge pull request #418 from stevvooe/accept-chunksize-parameter
Allow configuration of chunksize parameter
This commit is contained in:
commit
0da2c631db
@ -20,6 +20,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -148,9 +149,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) {
|
|||||||
chunkSize := int64(defaultChunkSize)
|
chunkSize := int64(defaultChunkSize)
|
||||||
chunkSizeParam, ok := parameters["chunksize"]
|
chunkSizeParam, ok := parameters["chunksize"]
|
||||||
if ok {
|
if ok {
|
||||||
chunkSize, ok = chunkSizeParam.(int64)
|
switch v := chunkSizeParam.(type) {
|
||||||
if !ok || chunkSize < minChunkSize {
|
case string:
|
||||||
return nil, fmt.Errorf("The chunksize parameter should be a number that is larger than 5*1024*1024")
|
vv, err := strconv.ParseInt(v, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("chunksize parameter must be an integer, %v invalid", chunkSizeParam)
|
||||||
|
}
|
||||||
|
chunkSize = vv
|
||||||
|
case int64:
|
||||||
|
chunkSize = v
|
||||||
|
case int, uint, int32, uint32, uint64:
|
||||||
|
chunkSize = reflect.ValueOf(v).Convert(reflect.TypeOf(chunkSize)).Int()
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("invalid valud for chunksize: %#v", chunkSizeParam)
|
||||||
|
}
|
||||||
|
|
||||||
|
if chunkSize <= minChunkSize {
|
||||||
|
return nil, fmt.Errorf("The chunksize %#v parameter should be a number that is larger than or equal to %d", chunkSize, minChunkSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user