Skip to content

Commit

Permalink
time.Time fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Apr 9, 2019
1 parent 3e0ad1d commit 6e731e7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 4 additions & 3 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"time"

"github.com/gochain-io/gochain/v3/common"
cid "github.com/ipfs/go-cid"
Expand All @@ -26,12 +27,12 @@ type API interface {
}

type AddResponse struct {
CID string `json:"cid"`
Expiration int64 `json:"expiration"` // Unix timestamp.
CID string `json:"cid"`
Expiration time.Time `json:"expiration"` // Unix timestamp.
}

type StatusResponse struct {
Expiration int64 `json:"expiration,omitempty"` // Unix timestamp.
Expiration time.Time `json:"expiration,omitempty"` // Unix timestamp.
}

func NewClient(url string) API {
Expand Down
11 changes: 5 additions & 6 deletions cmd/gofs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func Add(ctx context.Context, url, path string) error {
return fmt.Errorf("failed to add file %q: %v", path, err)
}
fmt.Println("File uploaded and pinned.")
fmt.Println("Pinned until:", time.Unix(ar.Expiration, 0))
fmt.Println("Pinned until:", ar.Expiration)
return nil
}

Expand Down Expand Up @@ -262,15 +262,14 @@ func Status(ctx context.Context, url, ci string) error {
if err != nil {
return err
}
if st.Expiration == 0 {
if st.Expiration == (time.Time{}) {
fmt.Println("Never been pinned.")
return nil
}
exp := time.Unix(st.Expiration, 0)
if until := time.Until(exp); until > 0 {
fmt.Printf("Expires in %s at %s.\n", until, exp)
if until := time.Until(st.Expiration); until > 0 {
fmt.Printf("Expires in %s at %s.\n", until, st.Expiration)
} else {
fmt.Printf("Expired %s ago at %s.\n", -until, exp)
fmt.Printf("Expired %s ago at %s.\n", -until, st.Expiration)
}

return nil
Expand Down

0 comments on commit 6e731e7

Please sign in to comment.