|
| 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 | +// ``` |
1 | 60 | package jrpc |
2 | 61 |
|
3 | 62 | import ( |
|
0 commit comments