Documentation
¶
Overview ¶
Package discovery provides utilities for serving API discovery documents.
The discovery document is generated at build time by tygorgen with WithDiscovery():
tygorgen.FromApp(app).WithDiscovery().ToDir("./client/src/rpc")
This produces discovery.json and discovery_schema.gen.go files.
Usage (simplest - loads from file at startup):
discovery.NewFromFile(app, "./client/src/rpc/discovery.json").Register()
Usage (single binary - uses generated Go file):
import "yourapp/client/src/rpc" discovery.NewFromBytes(app, rpc.DiscoverySchema).Register()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DescribeRequest ¶
type DescribeRequest struct{}
DescribeRequest is the request for Discovery.Describe.
type DescribeResponse ¶
type DescribeResponse struct {
// Schema is the raw JSON schema document.
// Parse this as the IR schema structure for full type introspection.
Schema any `json:"schema"`
}
DescribeResponse wraps the discovery document. The Schema field contains the full IR schema as generated by tygorgen.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service serves a pre-generated discovery document.
func MustFromFile ¶
MustFromFile is like NewFromFile but panics on error. Useful for simple setups where the file is expected to exist:
discovery.MustFromFile(app, "./client/src/rpc/discovery.json").Register()
func NewFromBytes ¶
NewFromBytes creates a discovery service from JSON bytes. Use with the generated discovery_schema.gen.go for single-binary deployment:
import "yourapp/client/src/rpc" discovery.NewFromBytes(app, rpc.DiscoverySchema).Register()
func NewFromFile ¶
NewFromFile creates a discovery service that loads the schema from a file. This is the simplest setup - just point to your generated discovery.json:
discovery.NewFromFile(app, "./client/src/rpc/discovery.json").Register()
The file is read once at startup. Returns an error if the file cannot be read.
func (*Service) Describe ¶
func (s *Service) Describe(ctx context.Context, req *DescribeRequest) (*DescribeResponse, error)
Describe returns the pre-generated discovery document.