discovery

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2025 License: MIT Imports: 5 Imported by: 0

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

func MustFromFile(app *tygor.App, path string) *Service

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

func NewFromBytes(app *tygor.App, jsonBytes []byte) *Service

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

func NewFromFile(app *tygor.App, path string) (*Service, error)

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.

func (*Service) Register

func (s *Service) Register()

Register adds the discovery service to the app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL