Rearrange the well-known types package layout and API: - Rename `types` to `ptypes`. - Rename `DurationFromProto` to `Duration`. - Unexport `ValidateDuration`. Sorry for the breakage. This should be the final location of everything.
diff --git a/Makefile b/Makefile index 19551a9..80b6a17 100644 --- a/Makefile +++ b/Makefile
@@ -33,11 +33,11 @@ all: install install: - go install ./proto ./jsonpb ./types + go install ./proto ./jsonpb ./ptypes go install ./protoc-gen-go test: - go test ./proto ./jsonpb ./types + go test ./proto ./jsonpb ./ptypes make -C protoc-gen-go/testdata test clean:
diff --git a/types/any/any.pb.go b/ptypes/any/any.pb.go similarity index 100% rename from types/any/any.pb.go rename to ptypes/any/any.pb.go
diff --git a/types/any/any.proto b/ptypes/any/any.proto similarity index 100% rename from types/any/any.proto rename to ptypes/any/any.proto
diff --git a/types/doc.go b/ptypes/doc.go similarity index 95% rename from types/doc.go rename to ptypes/doc.go index ff2810a..c0d595d 100644 --- a/types/doc.go +++ b/ptypes/doc.go
@@ -30,6 +30,6 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. /* -Package types contains code for interacting with well-known types. +Package ptypes contains code for interacting with well-known types. */ -package types +package ptypes
diff --git a/types/duration.go b/ptypes/duration.go similarity index 89% rename from types/duration.go rename to ptypes/duration.go index 40f84f0..65cb0f8 100644 --- a/types/duration.go +++ b/ptypes/duration.go
@@ -29,7 +29,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package ptypes // This file implements conversions between google.protobuf.Duration // and time.Duration. @@ -39,7 +39,7 @@ "fmt" "time" - durpb "github.com/golang/protobuf/types/duration" + durpb "github.com/golang/protobuf/ptypes/duration" ) const ( @@ -49,11 +49,11 @@ minSeconds = -maxSeconds ) -// ValidateDuration determines whether the durpb.Duration is valid according to the +// validateDuration determines whether the durpb.Duration is valid according to the // definition in google/protobuf/duration.proto. A valid durpb.Duration // may still be too large to fit into a time.Duration (the range of durpb.Duration // is about 10,000 years, and the range of time.Duration is about 290). -func ValidateDuration(d *durpb.Duration) error { +func validateDuration(d *durpb.Duration) error { if d == nil { return errors.New("duration: nil Duration") } @@ -70,11 +70,11 @@ return nil } -// DurationFromProto attempts to convert a durpb.Duration to a time.Duration. DurationFromProto +// Duration converts a durpb.Duration to a time.Duration. Duration // returns an error if the durpb.Duration is invalid or is too large to be // represented in a time.Duration. -func DurationFromProto(p *durpb.Duration) (time.Duration, error) { - if err := ValidateDuration(p); err != nil { +func Duration(p *durpb.Duration) (time.Duration, error) { + if err := validateDuration(p); err != nil { return 0, err } d := time.Duration(p.Seconds) * time.Second
diff --git a/types/duration/duration.pb.go b/ptypes/duration/duration.pb.go similarity index 100% rename from types/duration/duration.pb.go rename to ptypes/duration/duration.pb.go
diff --git a/types/duration/duration.proto b/ptypes/duration/duration.proto similarity index 100% rename from types/duration/duration.proto rename to ptypes/duration/duration.proto
diff --git a/types/duration_test.go b/ptypes/duration_test.go similarity index 91% rename from types/duration_test.go rename to ptypes/duration_test.go index 02462ae..e761289 100644 --- a/types/duration_test.go +++ b/ptypes/duration_test.go
@@ -29,7 +29,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package types +package ptypes import ( "math" @@ -37,7 +37,7 @@ "time" "github.com/golang/protobuf/proto" - durpb "github.com/golang/protobuf/types/duration" + durpb "github.com/golang/protobuf/ptypes/duration" ) const ( @@ -87,24 +87,24 @@ func TestValidateDuration(t *testing.T) { for _, test := range durationTests { - err := ValidateDuration(test.proto) + err := validateDuration(test.proto) gotValid := (err == nil) if gotValid != test.isValid { - t.Errorf("ValidateDuration(%v) = %t, want %t", test.proto, gotValid, test.isValid) + t.Errorf("validateDuration(%v) = %t, want %t", test.proto, gotValid, test.isValid) } } } -func TestDurationFromProto(t *testing.T) { +func TestDuration(t *testing.T) { for _, test := range durationTests { - got, err := DurationFromProto(test.proto) + got, err := Duration(test.proto) gotOK := (err == nil) wantOK := test.isValid && test.inRange if gotOK != wantOK { - t.Errorf("DurationFromProto(%v) ok = %t, want %t", test.proto, gotOK, wantOK) + t.Errorf("Duration(%v) ok = %t, want %t", test.proto, gotOK, wantOK) } if err == nil && got != test.dur { - t.Errorf("DurationFromProto(%v) = %v, want %v", test.proto, got, test.dur) + t.Errorf("Duration(%v) = %v, want %v", test.proto, got, test.dur) } } }
diff --git a/types/empty/empty.pb.go b/ptypes/empty/empty.pb.go similarity index 100% rename from types/empty/empty.pb.go rename to ptypes/empty/empty.pb.go
diff --git a/types/empty/empty.proto b/ptypes/empty/empty.proto similarity index 100% rename from types/empty/empty.proto rename to ptypes/empty/empty.proto
diff --git a/types/regen.sh b/ptypes/regen.sh similarity index 100% rename from types/regen.sh rename to ptypes/regen.sh
diff --git a/types/struct/struct.pb.go b/ptypes/struct/struct.pb.go similarity index 100% rename from types/struct/struct.pb.go rename to ptypes/struct/struct.pb.go
diff --git a/types/struct/struct.proto b/ptypes/struct/struct.proto similarity index 100% rename from types/struct/struct.proto rename to ptypes/struct/struct.proto
diff --git a/types/timestamp/timestamp.pb.go b/ptypes/timestamp/timestamp.pb.go similarity index 100% rename from types/timestamp/timestamp.pb.go rename to ptypes/timestamp/timestamp.pb.go
diff --git a/types/timestamp/timestamp.proto b/ptypes/timestamp/timestamp.proto similarity index 100% rename from types/timestamp/timestamp.proto rename to ptypes/timestamp/timestamp.proto
diff --git a/types/wrappers/wrappers.pb.go b/ptypes/wrappers/wrappers.pb.go similarity index 100% rename from types/wrappers/wrappers.pb.go rename to ptypes/wrappers/wrappers.pb.go
diff --git a/types/wrappers/wrappers.proto b/ptypes/wrappers/wrappers.proto similarity index 100% rename from types/wrappers/wrappers.proto rename to ptypes/wrappers/wrappers.proto