diff --git a/README b/README index 405429a959..6af26af75d 100644 --- a/README +++ b/README @@ -29,11 +29,19 @@ To use this software, you must: https://golang.org/doc/install for details or, if you are using gccgo, follow the instructions at https://golang.org/doc/install/gccgo -- Grab the code from the repository and install the proto package. +- Grab the code from the repository and install the `proto` package. The simplest way is to run `go get -u github.com/golang/protobuf/protoc-gen-go`. - The compiler plugin, protoc-gen-go, will be installed in $GOBIN, - defaulting to $GOPATH/bin. It must be in your $PATH for the protocol - compiler, protoc, to find it. + The compiler plugin, `protoc-gen-go`, will be installed in `$GOPATH/bin` + unless `$GOBIN` is set. It must be in your `$PATH` for the protocol + compiler, `protoc`, to find it. +- If you need a particular version of `protoc-gen-go` (e.g., to match your + `proto` package version), one option is + ```shell + GIT_TAG="v1.2.0" # change as needed + go get -d -u github.com/golang/protobuf/protoc-gen-go + git -C "$(go env GOPATH)"/src/github.com/golang/protobuf checkout $GIT_TAG + go install github.com/golang/protobuf/protoc-gen-go + ``` This software has two parts: a 'protocol compiler plugin' that generates Go source files that, once compiled, can access and manage diff --git a/types/duration.go b/types/duration.go index 475d61f1db..979b8e78a4 100644 --- a/types/duration.go +++ b/types/duration.go @@ -80,7 +80,7 @@ func DurationFromProto(p *Duration) (time.Duration, error) { return 0, fmt.Errorf("duration: %#v is out of range for time.Duration", p) } if p.Nanos != 0 { - d += time.Duration(p.Nanos) + d += time.Duration(p.Nanos) * time.Nanosecond if (d < 0) != (p.Nanos < 0) { return 0, fmt.Errorf("duration: %#v is out of range for time.Duration", p) } diff --git a/types/timestamp.go b/types/timestamp.go index 7ae54d8b3f..232ada57ce 100644 --- a/types/timestamp.go +++ b/types/timestamp.go @@ -109,11 +109,9 @@ func TimestampNow() *Timestamp { // TimestampProto converts the time.Time to a google.protobuf.Timestamp proto. // It returns an error if the resulting Timestamp is invalid. func TimestampProto(t time.Time) (*Timestamp, error) { - seconds := t.Unix() - nanos := int32(t.Sub(time.Unix(seconds, 0))) ts := &Timestamp{ - Seconds: seconds, - Nanos: nanos, + Seconds: t.Unix(), + Nanos: int32(t.Nanosecond()), } if err := validateTimestamp(ts); err != nil { return nil, err