docs(triple): complete Triple Header/Error comments and unit test coverage (#3649)

* docs(triple): add doc comments for header, trailer and error exported APIs

Several exported APIs in the triple protocol lacked doc comments or had
incomplete ones. Add a doc comment for ExtractFromOutgoingContext
describing what it returns and how the framework uses it internally:
on the client side to populate request headers, and on the server side
to merge handler-set headers into response trailers. Augment the
SetHeader, SetTrailer and SendHeader comments to state that they return
a CodeInternal error when called outside a Triple handler context. Add
a doc comment for Error.Error describing its format.

Signed-off-by: lizining <lizining1231@outlook.com>

* test(triple): add boundary tests for header, trailer and error APIs

Add 13 tests covering previously untested branches and edge cases:

header_test.go (8 tests):
- DecodeBinaryHeader: empty, unpadded, padded and naturally-aligned inputs
- ExtractFromOutgoingContext: nil return when no headers set, correct
  return when headers exist
- NewOutgoingContext: second call replaces existing headers instead of
  merging
- AppendToOutgoingContext: panics on odd number of kv arguments
- SetHeader/SetTrailer: normal path merges headers into the response
  buffer
- SetHeader/SetTrailer outside a handler context: returns CodeInternal

error_test.go (5 tests):
- NewWireError + IsWireError: wire, plain, non-triple and wrapped cases
- NewErrorDetail with *anypb.Any: skips double wrapping
- ErrorDetail.Bytes: returns a copy, mutation does not affect internal
  state
- wrapIfContextError: Canceled, DeadlineExceeded, already-coded, plain
  error and nil
- wrapIfUncoded: nil, already-coded, context.Canceled and plain error

Signed-off-by: lizining <lizining1231@outlook.com>

* style(triple): silence staticcheck SA5012 in the odd-kv panic test

The test deliberately passes a single kv argument to
AppendToOutgoingContext to verify it panics on an odd number of
arguments. staticcheck SA5012 flags the variadic call as having an odd
element count, which fails the CI lint. Annotate the call with
//nolint:staticcheck, following the existing convention in
handler_compat.go and handler_stream_compat.go.

Signed-off-by: lizining <lizining1231@outlook.com>

---------

Signed-off-by: lizining <lizining1231@outlook.com>
4 files changed
tree: 06a20fe9244a3eeba9a2495880ae3209e387dc4d
  1. .github/
  2. client/
  3. cluster/
  4. common/
  5. config_center/
  6. doc/
  7. filter/
  8. global/
  9. graceful_shutdown/
  10. imports/
  11. internal/
  12. logger/
  13. metadata/
  14. metrics/
  15. otel/
  16. protocol/
  17. proxy/
  18. registry/
  19. remoting/
  20. server/
  21. tls/
  22. tools/
  23. .asf.yaml
  24. .gitignore
  25. .gitmodules
  26. .golangci.yml
  27. .licenserc.yaml
  28. CHANGELOG.md
  29. CONTRIBUTING.md
  30. doc.go
  31. dubbo.go
  32. dubbo_test.go
  33. go.mod
  34. go.sum
  35. instance_options_init.go
  36. integrate_test.sh
  37. LICENSE
  38. loader.go
  39. loader_test.go
  40. Makefile
  41. NOTICE
  42. options.go
  43. README.md
  44. README_CN.md
README.md

Apache Dubbo for Golang

CI go.dev reference Go Report Card license


English | 中文

Apache Dubbo-go is a high-performance RPC and microservice framework compatible with other Dubbo language implementations. It leverages Golang's concurrency features to provide efficient service governance, including service discovery, load balancing, and traffic management. Dubbo-go supports multiple protocols, such as Dubbo, JSONRPC, Triple(gRPC-compatible), gRPC, HTTP, HTTP2, and HTTP/3 (experimental), ensuring seamless integration in heterogeneous environments.

You can visit the official website for more information.

Recent Updates

For detailed changes, refer to CHANGELOG.md.

  • 3.3.2:

    BREAKING CHANGE: config package has been removed, please use modern global package, check dubbo-go-samples for usage instructions.

    Apache Dubbo-go 3.3.2 is a production-readiness release focused on API consolidation, Triple protocol capabilities, application-level metadata, service governance, concurrency safety, and release tooling. It completes the removal of the legacy config package, expands generic invocation and HTTP-facing Triple features, refreshes generated-project workflows, and fixes multiple races, stale-snapshot issues, and resource leaks.

  • 3.3.1: Optimized configuration hot-reloading with content-based caching to prevent redundant notifications. Added experimental HTTP/3 support, Apollo integration, and Triple protocol OpenAPI generation. Fixed critical race conditions in service discovery under high-concurrency.

  • 3.3.0: Introduced script routing, multi-destination conditional routing, Triple protocol keepalive and connection pooling, Nacos multi-category subscriptions, and enhancements for observability and interoperability.

Getting started

Prerequisites

  • Go 1.24 or later (recommended for compatibility with recent updates).

Installation

To install Dubbo-go, use the following command:

go get dubbo.apache.org/dubbo-go/v3@latest

Quick Example

You can learn how to develop a dubbo-go RPC application step by step in 5 minutes by following our Quick Start demo.

It's as simple as the code shown below, you define a service with Protobuf, provide your own service implementation, register it to a server, and start the server.

func (srv *GreetTripleServer) Greet(ctx context.Context, req *greet.GreetRequest) (*greet.GreetResponse, error) {
	resp := &greet.GreetResponse{Greeting: req.Name}
	return resp, nil
}

func main() {
	srv, _ := server.NewServer(
		server.WithServerProtocol(
			protocol.WithPort(20000),
			protocol.WithTriple(),
		),
	)

	_ := greet.RegisterGreetServiceHandler(srv, &GreetTripleServer{})

	if err := srv.Serve(); err != nil {
		logger.Error(err)
	}
}

After the server is up and running, call your service via cURL:

curl \
    --header "Content-Type: application/json" \
    --data '{"name": "Dubbo"}' \
    http://localhost:20000/greet.GreetService/Greet

Or, you can start a standard dubbo-go client to call the service:

func main() {
	cli, _ := client.NewClient(
		client.WithClientURL("127.0.0.1:20000"),
	)

	svc, _ := greet.NewGreetService(cli)

	resp, _ := svc.Greet(context.Background(), &greet.GreetRequest{Name: "hello world"})
	
	logger.Infof("Greet response: %s", resp.Greeting)
}

See the samples for detailed information on usage. Next, learn how to deploy, monitor and manage the traffic of your dubbo-go application by visiting the official website.

Features

dubbo-go-architecture

Dubbo-go provides robust service governance capabilities:

  • RPC Protocols: Triple, gRPC compatible and HTTP-friendly
  • Service Discovery: Nacos, Zookeeper, Etcd, Polaris-mesh.
  • Load Balance: Adaptive, Random, RoundRobin, LeastActive, ConsistentHash
  • Traffic Management: traffic split, timeout, rate limiting, canary release
  • Configuration: yaml file, dynamic configuration(Nacos, Apollo, Zookeeper, etc.).
  • Observability: Metrics (Prometheus), tracing (OpenTelemetry v1.21.0+ with insecure options and standardized span names), logging (with service registration lifecycle events).
  • HA Strategy: Failover, Failfast, Failsafe/Failback, Available, Broadcast, Forking.
  • Interoperability: Full compatibility with Apache Dubbo (Java) via Triple protocol generic calls, group/version wildcard matching, and TLS API redesign.

Tools

Common development tools live in tools/.

ToolPurpose
dubbogo-cliScaffold demos/apps, install companion tools, inspect metadata, and debug services.
protoc-gen-go-tripleGenerate dubbo-go Triple bindings from protobuf service definitions.
protoc-gen-triple-openapiGenerate OpenAPI v3 documents from Triple protobuf services.
imports-formatterFormat Go import blocks using dubbo-go grouping rules.
dubbo-go-schemaProvide JSON Schema completion and validation for dubbo-go YAML config.
benchmarkPerformance benchmark suite for comparing Dubbo-Go, Dubbo-Java, and gRPC frameworks.

Ecosystem

Documentation

Community

Contributions, issues, and discussions are welcome. Please visit CONTRIBUTING for details on submitting patches and the contribution workflow.

Contact

Join our discussion group through Ding talk or WeChat.

invite.png

User List

If you are using apache/dubbo-go and think that it helps you or want to contribute code for Dubbo-go, please add your company to the user list to let us know your needs.

See more user cases

License

Apache Dubbo-go software is licensed under the Apache License Version 2.0. See the LICENSE file for details.