Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
gen/
.idea/
.vscode/
.DS_Store
.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
21 changes: 20 additions & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,4 +30,19 @@ plugins:
opt:
- target=ts
- json_types=true


# 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
18 changes: 18 additions & 0 deletions examples/go/simple_client/go.mod
Original file line number Diff line number Diff line change
@@ -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
)
53 changes: 53 additions & 0 deletions examples/go/simple_client/main.go
Original file line number Diff line number Diff line change
@@ -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\"")
}
Binary file added examples/go/simple_client/simple_client
Binary file not shown.
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
)