diff --git a/.gitignore b/.gitignore index 948d5a8..8ec57c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,27 @@ gen/ .idea/ .vscode/ -.DS_Store \ No newline at end of file +.DS_Store + +# Go generated files +gen/go/ +go.sum + +# Go build artifacts +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.test +*.out + +# Go workspace +go.work +go.work.sum + +# IDE +.vscode/ +.idea/ +*.swp +*.swo \ No newline at end of file diff --git a/buf.gen.yaml b/buf.gen.yaml index a929d89..49860fd 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -2,6 +2,10 @@ version: v2 clean: true # remove generated files before re-generating managed: enabled: true + override: + - file_option: go_package_prefix + value: github.com/xai-org/xai-proto/gen/go + plugins: # protoc v30 - remote: buf.build/protocolbuffers/python:v30.0 @@ -26,4 +30,19 @@ plugins: opt: - target=ts - json_types=true - \ No newline at end of file + + # Go plugins (new) + - remote: buf.build/protocolbuffers/go:v1.35.2 + out: gen/go + opt: + - paths=source_relative + - Mgoogle/rpc/status.proto=google.golang.org/genproto/googleapis/rpc/status + - Mgoogle/api/annotations.proto=google.golang.org/genproto/googleapis/api/annotations + - Mgoogle/api/http.proto=google.golang.org/genproto/googleapis/api/annotations + - remote: buf.build/grpc/go:v1.5.1 + out: gen/go + opt: + - paths=source_relative + - Mgoogle/rpc/status.proto=google.golang.org/genproto/googleapis/rpc/status + - Mgoogle/api/annotations.proto=google.golang.org/genproto/googleapis/api/annotations + - Mgoogle/api/http.proto=google.golang.org/genproto/googleapis/api/annotations diff --git a/examples/go/simple_client/go.mod b/examples/go/simple_client/go.mod new file mode 100644 index 0000000..b124882 --- /dev/null +++ b/examples/go/simple_client/go.mod @@ -0,0 +1,18 @@ +module github.com/xai-org/xai-proto/examples/go/simple_client + +go 1.26 + +replace github.com/xai-org/xai-proto => ../../.. + +require ( + github.com/xai-org/xai-proto v0.0.0-00010101000000-000000000000 + google.golang.org/grpc v1.71.0 +) + +require ( + golang.org/x/net v0.34.0 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/text v0.21.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect + google.golang.org/protobuf v1.36.5 // indirect +) diff --git a/examples/go/simple_client/main.go b/examples/go/simple_client/main.go new file mode 100644 index 0000000..87b4be6 --- /dev/null +++ b/examples/go/simple_client/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "context" + "fmt" + "log" + "os" + "time" + + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/metadata" +) + +func main() { + // Get API key from environment + apiKey := os.Getenv("XAI_API_KEY") + if apiKey == "" { + log.Println("⚠️ XAI_API_KEY not set. Using placeholder.") + apiKey = "your-api-key-here" + } + + // Connect to xAI API + conn, err := grpc.NewClient( + "api.x.ai:443", + grpc.WithTransportCredentials(insecure.NewCredentials()), + ) + if err != nil { + log.Fatalf("Failed to connect: %v", err) + } + defer conn.Close() + + fmt.Println("✅ Successfully created gRPC client") + fmt.Println("📦 Generated Go code location: gen/go/xai/api/v1/") + fmt.Println("") + fmt.Println("Example usage:") + fmt.Println(" import xaiv1 \"github.com/xai-org/xai-proto/gen/go/xai/api/v1\"") + fmt.Println(" client := xaiv1.NewLanguageServiceClient(conn)") + fmt.Println(" // Make API calls with the client") + fmt.Println("") + fmt.Println("For full API documentation, visit: https://docs.x.ai/") + + // Create context with API key + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + _ = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+apiKey) + + fmt.Println("") + fmt.Println("🚀 Go SDK is ready to use!") + fmt.Println("💡 To use the generated services, import:") + fmt.Println(" xaiv1 \"github.com/xai-org/xai-proto/gen/go/xai/api/v1\"") +} \ No newline at end of file diff --git a/examples/go/simple_client/simple_client b/examples/go/simple_client/simple_client new file mode 100755 index 0000000..ba48405 Binary files /dev/null and b/examples/go/simple_client/simple_client differ diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..2201638 --- /dev/null +++ b/go.mod @@ -0,0 +1,15 @@ +module github.com/xai-org/xai-proto + +go 1.26 + +require ( + google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f + google.golang.org/grpc v1.71.0 + google.golang.org/protobuf v1.36.5 +) + +require ( + golang.org/x/net v0.34.0 // indirect + golang.org/x/sys v0.29.0 // indirect + golang.org/x/text v0.21.0 // indirect +)