Skip to content

Commit c3a3876

Browse files
feat(go): introduce standalone sample (#101)
> [!TIP] > Better reviewed commit-by-commit. # Description Implements a standalone `go` sample. - [x] Follow the [`CONTRIBUTING` Guide](https://github.com/google-agentic-commerce/AP2?tab=contributing-ov-file#how-to-contribute). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - [x] Ensure the tests and linter pass - [x] Appropriate docs were updated (if necessary) Closes #71 🦕
1 parent f404a8d commit c3a3876

File tree

35 files changed

+3166
-2
lines changed

35 files changed

+3166
-2
lines changed

.cspell.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
".cspell/**",
99
".gemini/**",
1010
".vscode/**",
11-
".cspell.json"
11+
".cspell.json",
12+
"**/go.sum"
1213
],
1314
"dictionaryDefinitions": [
1415
{

.cspell/custom-words.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,25 @@ androidx
1111
Applebot
1212
appname
1313
ASGI
14+
bazel
1415
Blackhawk
1516
Boku
1617
BVNK
18+
celerybeat
1719
classpath
1820
CLASSPATH
1921
CMSPI
2022
cmwallet
2123
Cobo
2224
contentnegotiation
25+
Connor
2326
credman
2427
Crossmint
2528
cryptographical
2629
CYGPATTERN
2730
Dafiti
2831
dcql
32+
dmypy
2933
Dcql
3034
DCQL
3135
deviceauth
@@ -47,15 +51,20 @@ Garena
4751
gemini
4852
genai
4953
generativeai
54+
gofmt
5055
gradlew
56+
gradletasknamecache
5157
Gravitee
5258
gson
59+
hprof
60+
htmlcov
5361
Hashkey
5462
icns
5563
imei
5664
Imtp
5765
inlinehilite
5866
inmemory
67+
ipynb
5968
issuerauth
6069
JAVACMD
6170
jetbrains
@@ -72,6 +81,7 @@ ktor
7281
Ktor
7382
KXMYBJWNQ
7483
Lazada
84+
libpeerconnection
7585
Lightspark
7686
linenums
7787
llms
@@ -86,6 +96,7 @@ MSYS
8696
multistep
8797
Mysten
8898
Nuvei
99+
nosetests
89100
octicons
90101
okhttp
91102
Otherville
@@ -100,6 +111,9 @@ pids
100111
proguard
101112
Proguard
102113
pymdownx
114+
pyflow
115+
pypa
116+
pypackages
103117
reemademo
104118
refundability
105119
renamesourcefileattribute
@@ -108,6 +122,7 @@ repudiable
108122
Revolut
109123
Riskified
110124
ROOTDIRS
125+
ropeproject
111126
ROOTDIRSRAW
112127
Rulebook
113128
screenreaders
@@ -119,6 +134,9 @@ sideloaded
119134
Signifyd
120135
skus
121136
Splitit
137+
Spyder
138+
spyderproject
139+
spyproject
122140
stablecoins
123141
superfences
124142
Truelayer
@@ -127,6 +145,7 @@ viewmodel
127145
vulnz
128146
Wallex
129147
Wayfair
148+
webassets
130149
Worldline
131150
Worldpay
132151
Xdock
@@ -135,3 +154,28 @@ XVCJ
135154
Yapily
136155
Zalopay
137156
Zalora
157+
cncf
158+
davecgh
159+
envoyproxy
160+
felixge
161+
genproto
162+
glog
163+
gopkg
164+
groupcache
165+
honnef
166+
httpsnoop
167+
logr
168+
longrunning
169+
objx
170+
opentelemetry
171+
otelgrpc
172+
otelhttp
173+
pmezard
174+
prometheus
175+
protoc
176+
RPCURL
177+
stdr
178+
stretchr
179+
udpa
180+
unmarshal
181+
xerrors

.github/workflows/linter.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,5 @@ jobs:
4141
VALIDATE_GITHUB_ACTIONS_ZIZMOR: false
4242
VALIDATE_JSCPD: false
4343
VALIDATE_SHELL_SHFMT: false
44+
VALIDATE_GO: false
45+
VALIDATE_GO_MODULES: false

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ __pycache__/
88
/out-tsc
99
/bazel-out
1010

11+
# Go binaries
12+
bin/
13+
1114
# C extensions
1215
*.so
1316

@@ -193,7 +196,7 @@ gradle-app.setting
193196
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
194197
!gradle-wrapper.jar
195198

196-
# Avoid ignore Gradle wrappper properties
199+
# Avoid ignore Gradle wrapper properties
197200
!gradle-wrapper.properties
198201

199202
# Cache of project

samples/go/.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Binaries
2+
bin/
3+
*.exe
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Test binary, built with `go test -c`
9+
*.test
10+
11+
# Output of the go coverage tool
12+
*.out
13+
14+
# Go workspace file
15+
go.work
16+
17+
# IDE
18+
.idea/
19+
.vscode/
20+
*.swp
21+
*.swo
22+
*~
23+
24+
# OS
25+
.DS_Store
26+
Thumbs.db

samples/go/Makefile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
.PHONY: all build clean test run-merchant run-credentials run-processor run-all help fmt lint
16+
17+
all: fmt lint build
18+
19+
build:
20+
@echo "Building all agents..."
21+
@mkdir -p bin
22+
@go build -o bin/merchant_agent ./cmd/merchant_agent
23+
@go build -o bin/credentials_provider_agent ./cmd/credentials_provider_agent
24+
@go build -o bin/merchant_payment_processor_agent ./cmd/merchant_payment_processor_agent
25+
@echo "Build complete!"
26+
27+
clean:
28+
@echo "Cleaning build artifacts..."
29+
@rm -rf bin
30+
@echo "Clean complete!"
31+
32+
test:
33+
@echo "Running tests..."
34+
@go test ./...
35+
36+
fmt:
37+
@echo "Formatting code..."
38+
@go fmt ./...
39+
40+
lint:
41+
@echo "Running linter..."
42+
@go vet ./...
43+
44+
run-merchant:
45+
@echo "Starting Merchant Agent on port 8001..."
46+
@go run ./cmd/merchant_agent
47+
48+
run-credentials:
49+
@echo "Starting Credentials Provider Agent on port 8002..."
50+
@go run ./cmd/credentials_provider_agent
51+
52+
run-processor:
53+
@echo "Starting Merchant Payment Processor Agent on port 8003..."
54+
@go run ./cmd/merchant_payment_processor_agent
55+
56+
run-all:
57+
@echo "Starting all agents..."
58+
@bash scenarios/a2a/human-present/cards/run.sh
59+
60+
deps:
61+
@echo "Downloading dependencies..."
62+
@go mod download
63+
@go mod tidy
64+
65+
help:
66+
@echo "Available targets:"
67+
@echo " make build - Build all agent binaries"
68+
@echo " make clean - Remove build artifacts"
69+
@echo " make test - Run tests"
70+
@echo " make fmt - Format code"
71+
@echo " make lint - Run linter"
72+
@echo " make deps - Download and tidy dependencies"
73+
@echo " make run-merchant - Run merchant agent"
74+
@echo " make run-credentials - Run credentials provider agent"
75+
@echo " make run-processor - Run payment processor agent"
76+
@echo " make run-all - Run all agents (background)"

samples/go/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Go Samples for the Agent Payments Protocol AP2
2+
3+
This directory contains Go samples demonstrating how to build AP2
4+
agents.
5+
6+
## Available Scenarios
7+
8+
Currently, one scenario is available:
9+
10+
- **[Human-Present Card Payment](./scenarios/a2a/human-present/cards/README.md)**
11+
- Complete card payment flow with Go agents and Python Shopping
12+
Agent
13+
14+
See the [scenario README](./scenarios/a2a/human-present/cards/README.md) for
15+
detailed setup and usage instructions.
16+
17+
## Why Go for Backend Agents?
18+
19+
Go can be exceptionally well-suited for building AP2 backend services:
20+
21+
- **Type Safety**: Compile-time validation of protocol structures
22+
- **Performance**: Fast response times and low resource usage
23+
- **Concurrency**: Efficient handling of concurrent requests
24+
- **Deployment**: Single binary with no runtime dependencies
25+
26+
## Project Structure
27+
28+
```text
29+
samples/go/
30+
├── cmd/ # Agent entry points
31+
├── pkg/
32+
│ ├── ap2/types/ # AP2 protocol types
33+
│ ├── common/ # Shared infrastructure
34+
│ └── roles/ # Agent implementations
35+
└── scenarios/ # Runnable examples
36+
└── a2a/
37+
└── human-present/
38+
└── cards/ # Card payment scenario
39+
```
40+
41+
## Development
42+
43+
```sh
44+
# Run tests
45+
make test
46+
47+
# Format code
48+
make fmt
49+
50+
# Build all agents
51+
make build
52+
```
53+
54+
## License
55+
56+
Copyright 2025 Google LLC. Licensed under the Apache License, Version 2.0.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"log"
19+
20+
"github.com/google-agentic-commerce/ap2/samples/go/pkg/common"
21+
"github.com/google-agentic-commerce/ap2/samples/go/pkg/roles/credentials_provider_agent"
22+
)
23+
24+
const (
25+
AgentPort = 8002
26+
RPCURL = "/a2a/credentials_provider"
27+
)
28+
29+
func main() {
30+
agentCard, err := common.LoadAgentCard("pkg/roles/credentials_provider_agent")
31+
if err != nil {
32+
log.Fatalf("Failed to load agent card: %v", err)
33+
}
34+
35+
executor := credentials_provider_agent.NewCredentialsProviderExecutor(agentCard.Capabilities.Extensions)
36+
37+
server := common.NewAgentServer(AgentPort, agentCard, executor, RPCURL)
38+
39+
if err := server.Start(); err != nil {
40+
log.Fatalf("Server error: %v", err)
41+
}
42+
}

0 commit comments

Comments
 (0)