Skip to content

Commit c114dca

Browse files
committed
chore(librariangen): introduce message package and add ReleaseInitRequest
The message packages hosts the data types that are common across the CLI and language container implementations. ReleaseInitRequest and ReleaseInitResponse are example data types that belong to the package. The request and response types are the argument and return type of the upcoming ReleaseInit function implementation. It was originally "request" package in google-cloud-go. However, because it also includes responses from the language container to the CLI, I'm renaming it to "messages".
1 parent 2f6c75d commit c114dca

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

internal/librariangen/generate/generator.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import (
2727

2828
"cloud.google.com/java/internal/librariangen/bazel"
2929
"cloud.google.com/java/internal/librariangen/execv"
30+
"cloud.google.com/java/internal/librariangen/message"
3031
"cloud.google.com/java/internal/librariangen/protoc"
31-
"cloud.google.com/java/internal/librariangen/request"
3232
)
3333

3434
// Test substitution vars.
3535
var (
3636
bazelParse = bazel.Parse
3737
execvRun = execv.Run
38-
requestParse = request.ParseLibrary
38+
requestParse = message.ParseLibrary
3939
protocBuild = protoc.Build
4040
)
4141

@@ -113,7 +113,7 @@ func Generate(ctx context.Context, cfg *Config) error {
113113
// invokeProtoc handles the protoc GAPIC generation logic for the 'generate' CLI command.
114114
// It reads a request file, and for each API specified, it invokes protoc
115115
// to generate the client library. It returns the module path and the path to the service YAML.
116-
func invokeProtoc(ctx context.Context, cfg *Config, generateReq *request.Library) error {
116+
func invokeProtoc(ctx context.Context, cfg *Config, generateReq *message.Library) error {
117117
for _, api := range generateReq.APIs {
118118
apiServiceDir := filepath.Join(cfg.SourceDir, api.Path)
119119
slog.Info("processing api", "service_dir", apiServiceDir)
@@ -135,7 +135,7 @@ func invokeProtoc(ctx context.Context, cfg *Config, generateReq *request.Library
135135
// readGenerateReq reads generate-request.json from the librarian-tool input directory.
136136
// The request file tells librariangen which library and APIs to generate.
137137
// It is prepared by the Librarian tool and mounted at /librarian.
138-
func readGenerateReq(librarianDir string) (*request.Library, error) {
138+
func readGenerateReq(librarianDir string) (*message.Library, error) {
139139
reqPath := filepath.Join(librarianDir, "generate-request.json")
140140
slog.Debug("librariangen: reading generate request", "path", reqPath)
141141

@@ -264,4 +264,4 @@ func unzip(src, dest string) error {
264264
}
265265
}
266266
return nil
267-
}
267+
}
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,30 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package request
15+
// Package message defines data types which the Librarian CLI and language
16+
// containers exchange.
17+
// There shouldn't be CLI-specific data type or language container-specific
18+
// data types in this package.
19+
// TODO(b/447404382): Move this package to the https://github.com/googleapis/librarian
20+
// GitHub repository once the interface is finalized.
21+
package message
1622

1723
import (
1824
"encoding/json"
1925
"fmt"
2026
"os"
2127
)
2228

29+
// Request is the structure of the release-init-request.json file.
30+
type ReleaseInitRequest struct {
31+
Libraries []*Library `json:"libraries"`
32+
}
33+
34+
// Response is the structure of the release-init-response.json file.
35+
type ReleaseInitResponse struct {
36+
Error string `json:"error,omitempty"`
37+
}
38+
2339
// Library is the combination of all the fields used by CLI requests and responses.
2440
// Each CLI command has its own request/response type, but they all use Library.
2541
type Library struct {
@@ -75,4 +91,4 @@ func ParseLibrary(path string) (*Library, error) {
7591
}
7692

7793
return &req, nil
78-
}
94+
}

internal/librariangen/request/request_test.go renamed to internal/librariangen/message/message_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package request
15+
package message
1616

1717
import (
1818
"os"
@@ -95,4 +95,4 @@ func TestParseLibrary_FileNotFound(t *testing.T) {
9595
if err == nil {
9696
t.Error("Parse() expected error for non-existent file, got nil")
9797
}
98-
}
98+
}

0 commit comments

Comments
 (0)