-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pubsublite): Move internal implementation details to internal/wi…
…re subpackage (#3123) This makes it possible for the bulk of the Lite library internal implementation to be used from different packages. Some cleanups so that the wire package compiles. pubsublite.Message was deleted and the file was renamed to message_router.go.
- Loading branch information
Showing
13 changed files
with
182 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,17 @@ | |||
# Wire | |||
|
|||
This directory contains internal implementation details for Cloud Pub/Sub Lite. | |||
Its exported interface can change at any time. | |||
|
|||
## Conventions | |||
|
|||
The following are general conventions used in this package: | |||
|
|||
* Capitalized methods and fields of a struct denotes its public interface. They | |||
are safe to call from outside the struct (e.g. accesses immutable fields or | |||
guarded by a mutex). All other methods are considered internal implementation | |||
details that should not be called from outside the struct. | |||
* unsafeFoo() methods indicate that the caller is expected to have already | |||
acquired the struct's mutex. Since Go does not support re-entrant locks, they | |||
do not acquire the mutex. These are typically common util methods that need | |||
to be atomic with other operations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
// Copyright 2020 Google LLC | |||
// | |||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
// | |||
// https://www.apache.org/licenses/LICENSE-2.0 | |||
// | |||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
|
|||
package wire | |||
|
|||
import ( | |||
"fmt" | |||
"strings" | |||
) | |||
|
|||
// ValidateZone verifies that the `input` string has the format of a valid | |||
// Google Cloud zone. An example zone is "europe-west1-b". | |||
// See https://cloud.google.com/compute/docs/regions-zones for more information. | |||
func ValidateZone(input string) error { | |||
parts := strings.Split(input, "-") | |||
if len(parts) != 3 { | |||
return fmt.Errorf("pubsublite: invalid zone %q", input) | |||
} | |||
return nil | |||
} | |||
|
|||
// ValidateRegion verifies that the `input` string has the format of a valid | |||
// Google Cloud region. An example region is "europe-west1". | |||
// See https://cloud.google.com/compute/docs/regions-zones for more information. | |||
func ValidateRegion(input string) error { | |||
parts := strings.Split(input, "-") | |||
if len(parts) != 2 { | |||
return fmt.Errorf("pubsublite: invalid region %q", input) | |||
} | |||
return nil | |||
} | |||
|
|||
type topicPartition struct { | |||
Path string | |||
Partition int | |||
} | |||
|
|||
type subscriptionPartition struct { | |||
Path string | |||
Partition int | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,78 @@ | |||
// Copyright 2020 Google LLC | |||
// | |||
// Licensed under the Apache License, Version 2.0 (the "License"); | |||
// you may not use this file except in compliance with the License. | |||
// You may obtain a copy of the License at | |||
// | |||
// https://www.apache.org/licenses/LICENSE-2.0 | |||
// | |||
// Unless required by applicable law or agreed to in writing, software | |||
// distributed under the License is distributed on an "AS IS" BASIS, | |||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
// See the License for the specific language governing permissions and | |||
|
|||
package wire | |||
|
|||
import "testing" | |||
|
|||
func TestValidateZone(t *testing.T) { | |||
for _, tc := range []struct { | |||
desc string | |||
input string | |||
wantErr bool | |||
}{ | |||
{ | |||
desc: "valid", | |||
input: "us-central1-a", | |||
wantErr: false, | |||
}, | |||
{ | |||
desc: "invalid: insufficient dashes", | |||
input: "us-central1", | |||
wantErr: true, | |||
}, | |||
{ | |||
desc: "invalid: excess dashes", | |||
input: "us-central1-a-b", | |||
wantErr: true, | |||
}, | |||
} { | |||
t.Run(tc.desc, func(t *testing.T) { | |||
err := ValidateZone(tc.input) | |||
if (err != nil) != tc.wantErr { | |||
t.Errorf("ValidateZone(%q) = %v, want err=%v", tc.input, err, tc.wantErr) | |||
} | |||
}) | |||
} | |||
} | |||
|
|||
func TestValidateRegion(t *testing.T) { | |||
for _, tc := range []struct { | |||
desc string | |||
input string | |||
wantErr bool | |||
}{ | |||
{ | |||
desc: "valid", | |||
input: "europe-west1", | |||
wantErr: false, | |||
}, | |||
{ | |||
desc: "invalid: insufficient dashes", | |||
input: "europewest1", | |||
wantErr: true, | |||
}, | |||
{ | |||
desc: "invalid: excess dashes", | |||
input: "europe-west1-b", | |||
wantErr: true, | |||
}, | |||
} { | |||
t.Run(tc.desc, func(t *testing.T) { | |||
err := ValidateRegion(tc.input) | |||
if (err != nil) != tc.wantErr { | |||
t.Errorf("ValidateRegion(%q) = %v, want err=%v", tc.input, err, tc.wantErr) | |||
} | |||
}) | |||
} | |||
} |
Oops, something went wrong.