Skip to content

Commit b4a2ba6

Browse files
[ADD] package documentation for jrpc
1 parent 9f7301a commit b4a2ba6

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

web/jrpc/jrpc.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
// Package jrpc provides a JSON-RPC over HTTP and WebSocket implementation with
2+
// Protocol Buffer support. It enables automatic method dispatch, streaming
3+
// capabilities, and context enrichment for service implementations.
4+
//
5+
// This package requires server definitions to be generated from Protocol Buffer
6+
// service definitions using the protoc-gen-jrpc plugin:
7+
// https://github.com/valentin-kaiser/protoc-gen-jrpc
8+
//
9+
// The plugin generates the correct struct implementations that satisfy the
10+
// Server interface, ensuring proper integration with the jRPC service framework.
11+
//
12+
// Features:
13+
// - HTTP and WebSocket endpoint support
14+
// - Automatic method resolution and dispatch
15+
// - Protocol Buffer JSON marshaling/unmarshaling
16+
// - Multiple streaming patterns (unary, server, client, bidirectional)
17+
// - Context enrichment with HTTP and WebSocket components
18+
// - Comprehensive error handling and connection management
19+
//
20+
// Usage:
21+
// 1. Define your service in a .proto file
22+
// 2. Generate Go code using protoc with the protoc-gen-jrpc plugin
23+
// 3. Implement the generated Server interface
24+
// 4. Create a new jRPC service with jrpc.New(yourServer)
25+
// 5. Register the HandlerFunc with the web package function WithJRPC
26+
//
27+
// Example:
28+
//
29+
// ```go
30+
// package main
31+
//
32+
// import (
33+
// "context"
34+
// "log"
35+
// "net/http"
36+
// "github.com/valentin-kaiser/go-core/web"
37+
// "github.com/valentin-kaiser/go-core/web/jrpc"
38+
// )
39+
//
40+
// type MyService struct {
41+
// jrpc.UnimplementedMyServiceServer
42+
// }
43+
//
44+
// func (s *MyService) MyMethod(ctx context.Context, req *MyRequest) (*MyResponse, error) {
45+
// // Implement your method logic here
46+
// return &MyResponse{}, nil
47+
// }
48+
//
49+
// func main() {
50+
// err := web.Instance().
51+
// WithHost("localhost").
52+
// WithPort(8080).
53+
// WithJRPC(jrpc.New(&MyService{})).
54+
// Start().Error
55+
// if err != nil {
56+
// log.Fatal().Err(err).Msg("server exited")
57+
// }
58+
// }
59+
// ```
160
package jrpc
261

362
import (

0 commit comments

Comments
 (0)