Skip to content

Commit

Permalink
Implement GSP-41 (#681)
Browse files Browse the repository at this point in the history
* Implement GSP-41

* Modify test file
  • Loading branch information
aeinrw committed Jul 20, 2021
1 parent 3d8d457 commit df6a96a
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 39 deletions.
72 changes: 36 additions & 36 deletions cmd/definitions/bindata/bindata.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion cmd/definitions/tests/connstr_test.go
Expand Up @@ -3,6 +3,7 @@ package tests
import (
"errors"
"testing"
"time"

"github.com/beyondstorage/go-storage/v4/pairs"
"github.com/beyondstorage/go-storage/v4/services"
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestFromString(t *testing.T) {
pairs.WithName("abc"),
pairs.WithWorkDir("/tmp/tmp1"),
pairs.WithSize(200),
pairs.WithExpire(100),
pairs.WithExpire(time.Duration(100)),
WithStorageClass("sc"),
},
nil,
Expand Down
1 change: 1 addition & 0 deletions cmd/definitions/tmpl/pair.tmpl
Expand Up @@ -3,6 +3,7 @@ package pairs

import (
"context"
"time"

"github.com/beyondstorage/go-storage/v4/pkg/httpclient"
. "github.com/beyondstorage/go-storage/v4/types"
Expand Down
2 changes: 2 additions & 0 deletions cmd/definitions/tmpl/service.tmpl
Expand Up @@ -4,6 +4,7 @@ package {{ .Name }}
import (
"context"
"io"
"time"

"github.com/beyondstorage/go-storage/v4/pkg/httpclient"
"github.com/beyondstorage/go-storage/v4/services"
Expand All @@ -13,6 +14,7 @@ import (
var _ Storager
var _ services.ServiceError
var _ httpclient.Options
var _ time.Duration

// Type is the type for {{ .Name }}
const Type = "{{ .Name }}"
Expand Down
2 changes: 1 addition & 1 deletion definitions/pairs.toml
Expand Up @@ -17,7 +17,7 @@ type = "string"
description = "specify how to provide endpoint for service or storage"

[expire]
type = "int"
type = "time.Duration"
description = "specify when the url returned by reach will expire"

[interceptor]
Expand Down
3 changes: 2 additions & 1 deletion pairs/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions services/new.go
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"sync"
"time"

"github.com/beyondstorage/go-storage/v4/pairs"
"github.com/beyondstorage/go-storage/v4/types"
Expand Down Expand Up @@ -204,6 +205,10 @@ func parse(m map[string]string, k string, v string) (pair types.Pair, err error)
pair.Value, err = strconv.ParseUint(v, 0, 64)
case "[]byte":
pair.Value, err = base64.RawStdEncoding.DecodeString(v)
case "time.Duration":
var i int64
i, err = strconv.ParseInt(v, 0, 64)
pair.Value = time.Duration(i)
default:
return types.Pair{}, fmt.Errorf("type not parseable: %v, %v", k, vType)
}
Expand Down

0 comments on commit df6a96a

Please sign in to comment.