codegen

package
v0.0.0-...-1b732cf Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompileProto

func CompileProto(protoDir, protoFile string) (*pluginpb.CodeGeneratorRequest, error)

CompileProto parses a .proto file using protocompile and returns a CodeGeneratorRequest that can be piped to any protoc plugin.

func GeneratePreloadGo

func GeneratePreloadGo(routes []RoutePreload, packageName string) string

GeneratePreloadGo generates Go source code for the preload route config. It imports gapp's RouteSpec/RpcSpec types directly so the generated var is compatible with gapp.NewPreloadEngine.

func HashFile

func HashFile(path string) (string, error)

HashFile returns the hex-encoded SHA256 hash of a file's contents.

func ReadStoredHash

func ReadStoredHash(projectDir string) string

ReadStoredHash reads the stored codegen hash from .gapp/codegen.hash.

func RunGoPlugin

RunGoPlugin invokes protoc-gen-go via `go run` so no global install is needed.

func RunPlugin

func RunPlugin(req *pluginpb.CodeGeneratorRequest, pluginPath string, param string) (*pluginpb.CodeGeneratorResponse, error)

RunPlugin invokes a protoc plugin binary with the given CodeGeneratorRequest, passing the serialized request on stdin and reading the response from stdout.

func WriteHash

func WriteHash(projectDir, hash string) error

WriteHash writes the codegen hash to .gapp/codegen.hash.

func WriteResponse

func WriteResponse(resp *pluginpb.CodeGeneratorResponse, outDir string) ([]string, error)

WriteResponse writes all files from a CodeGeneratorResponse to the output directory.

Types

type RoutePreload

type RoutePreload struct {
	Path string
	Rpcs []RpcSpec
}

RoutePreload defines preload configuration for a route pattern.

func ParseRouteFile

func ParseRouteFile(filePath string) (*RoutePreload, error)

ParseRouteFile extracts the route path and RPC declarations from a TypeScript route file. It looks for the pattern:

export const xxxRoute = {
  path: "/...",
  factory: () => ({
    rpcs: [
      { method: "MethodName" },
      { method: "Other", params: { "id": "userId" } },
    ],
  }),
};

func ScanRoutes

func ScanRoutes(routesDir string) ([]RoutePreload, error)

ScanRoutes scans a directory for route files and extracts preload configs.

type RpcSpec

type RpcSpec struct {
	Method string
	Params map[string]string
}

RpcSpec defines an RPC to preload with optional parameter mappings.

Jump to

Keyboard shortcuts

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