瀏覽代碼

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.
David Symonds 10 年之前
父節點
當前提交
127091107f

+ 2 - 2
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:

+ 0 - 0
types/any/any.pb.go → ptypes/any/any.pb.go


+ 0 - 0
types/any/any.proto → ptypes/any/any.proto


+ 2 - 2
types/doc.go → 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

+ 7 - 7
types/duration.go → 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 @@ import (
 	"fmt"
 	"time"
 
-	durpb "github.com/golang/protobuf/types/duration"
+	durpb "github.com/golang/protobuf/ptypes/duration"
 )
 
 const (
@@ -49,11 +49,11 @@ const (
 	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 @@ func ValidateDuration(d *durpb.Duration) error {
 	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

+ 0 - 0
types/duration/duration.pb.go → ptypes/duration/duration.pb.go


+ 0 - 0
types/duration/duration.proto → ptypes/duration/duration.proto


+ 8 - 8
types/duration_test.go → 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 @@ import (
 	"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 @@ var durationTests = []struct {
 
 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)
 		}
 	}
 }

+ 0 - 0
types/empty/empty.pb.go → ptypes/empty/empty.pb.go


+ 0 - 0
types/empty/empty.proto → ptypes/empty/empty.proto


+ 0 - 0
types/regen.sh → ptypes/regen.sh


+ 0 - 0
types/struct/struct.pb.go → ptypes/struct/struct.pb.go


+ 0 - 0
types/struct/struct.proto → ptypes/struct/struct.proto


+ 0 - 0
types/timestamp/timestamp.pb.go → ptypes/timestamp/timestamp.pb.go


+ 0 - 0
types/timestamp/timestamp.proto → ptypes/timestamp/timestamp.proto


+ 0 - 0
types/wrappers/wrappers.pb.go → ptypes/wrappers/wrappers.pb.go


+ 0 - 0
types/wrappers/wrappers.proto → ptypes/wrappers/wrappers.proto