module
Version:
v1.0.5
Opens a new window with list of versions in this module.
Published: Mar 20, 2025
License: MIT
Opens a new window with license information.
README
ΒΆ
cli


code generation CLI tool for catalystgo projects
Installation π
Using Go πΉ
go install github.com/catalystgo/cli/cmd/catalystgo@latest
Using Docker π³
docker pull catalystgo/cli:latest
Usage π
Commands π
| Command |
Short |
Description |
init |
i |
Initialize the project files |
implement |
impl |
Generate the gRPC code for the project |
version |
ver |
Print the version of the tool |
help |
|
Print the help message |
Example
Prerequisites
Steps
-
Initialize the project
catalystgo init github.com/username/repo
-
Create proto file
mkdir -p api/user
touch api/user/user.proto
-
Insert proto file content
syntax = "proto3";
package user_pb;
import "google/api/annotations.proto";
import "google/api/http.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
import "protoc-gen-openapiv2/options/openapiv2.proto";
option go_package = "github.com/username/repo/pkg/example";
service UserService {
rpc Authenticate(AuthenticateRequest) returns (AuthenticateResponse) {
option (google.api.http) = {
post: "/user/authenticate"
body: "*"
};
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
description: "Authenticate a user"
};
}
}
message AuthenticateRequest {
string username = 1;
string password = 2;
}
message AuthenticateResponse {
string token = 1;
}
-
Generate the gRPC code
task generate
-
Modify the content of internal/api/user/authenticate.go to
import (
"context"
desc "github.com/escalopa/awesome-app/pkg/example"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (i *Implementation) Authenticate(ctx context.Context, req *desc.AuthenticateRequest) (*desc.AuthenticateResponse, error) {
if req.GetUsername() == "admin" && req.GetPassword() == "admin" {
return &desc.AuthenticateResponse{Token: "admin-token"}, nil
}
return nil, status.Error(codes.Unauthenticated, "invalid credentials")
}
-
Modify the content of cmd/awesome-app/main.go to be
func main() {
app, err := catalystgo.New()
...
srv := example.NewUserService()
...
err := app.Run(srv)
}
-
Run the app
task run
-
Test the app
# using http
curl -X POST -d '{"username": "admin", "password": "admin"}' http://localhost:8080/user/authenticate
# using grpc
grpcurl -plaintext -d '{"username": "admin", "password": "admin"}' localhost:8080 user_pb.UserService/Authenticate
Features π―
- Write tests for service.Service methods in generated code
Directories
ΒΆ
cmd
|
|
|
|
|
|
|
|
internal
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Click to show internal directories.
Click to hide internal directories.