Permalink
Browse files

Update

  • Loading branch information...
peter-edge committed Dec 3, 2017
1 parent 4e9a6df commit 1c8ff6409bd6a9f4daf2e48770ec098a9d5b9540
Showing with 9 additions and 8 deletions.
  1. +2 −2 http/protohttp.go
  2. +1 −1 server/protoserver.go
  3. +6 −5 time/prototime.go
@@ -38,14 +38,14 @@ func (c *BasicAuth) GetAuthorization() string {

// NewContext returns a new context.Context with the basic auth attached.
func (c *BasicAuth) NewContext(ctx context.Context) context.Context {
return metadata.NewContext(ctx, metadata.Pairs("Authorization", c.GetAuthorization()))
return metadata.NewOutgoingContext(ctx, metadata.Pairs("Authorization", c.GetAuthorization()))
}

// BasicAuthFromContext gets the basic auth from the specified context.Context.
//
// If no basic auth is present, BasicAuthFromContext returns nil.
func BasicAuthFromContext(ctx context.Context) (*BasicAuth, error) {
md, ok := metadata.FromContext(ctx)
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
return nil, nil
}
@@ -245,7 +245,7 @@ func logServerFinished(start time.Time, err error) {
}

func durationToProto(d time.Duration) *duration.Duration {
return &durationpb.Duration{
return &duration.Duration{
Seconds: int64(d) / int64(time.Second),
Nanos: int32(int64(d) % int64(time.Second)),
}
@@ -5,6 +5,7 @@ package prototime // import "go.pedge.io/proto/time"
import (
"time"

"github.com/golang/protobuf/ptypes/duration"
"github.com/golang/protobuf/ptypes/timestamp"
)

@@ -50,17 +51,17 @@ func Now() *timestamp.Timestamp {
}

// DurationToProto converts a go Duration to a protobuf Duration.
func DurationToProto(d time.Duration) *timestamp.Duration {
return &timestamp.Duration{
func DurationToProto(d time.Duration) *duration.Duration {
return &duration.Duration{
Seconds: int64(d) / int64(time.Second),
Nanos: int32(int64(d) % int64(time.Second)),
}
}

// DurationFromProto converts a protobuf Duration to a go Duration.
func DurationFromProto(duration *timestamp.Duration) time.Duration {
if duration == nil {
func DurationFromProto(d *duration.Duration) time.Duration {
if d == nil {
return 0
}
return time.Duration((duration.Seconds * int64(time.Second)) + int64(duration.Nanos))
return time.Duration((d.Seconds * int64(time.Second)) + int64(d.Nanos))
}

0 comments on commit 1c8ff64

Please sign in to comment.