tsgen

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 21 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tsgen generates a typed TypeScript client for Go services bound with golet.Bind and events declared with golet.NewEvent.

Types are derived with reflection following the encoding/json/v2 rules used on the wire. Parameter names, documentation and enum values are read from the Go sources when they are available.

Index

Constants

View Source
const RuntimePackage = "golet-runtime"

RuntimePackage is the npm package of the page runtime, which generated clients import.

Variables

This section is empty.

Functions

func Generate

func Generate(m Model) ([]byte, error)

Generate renders the TypeScript client.

func IsIdentifier

func IsIdentifier(s string) bool

IsIdentifier reports whether s is a valid JavaScript identifier made of ASCII letters, digits, '_' and '$'.

func Validate

func Validate(t reflect.Type) error

Validate reports an error if values of type t cannot cross the IPC boundary as JSON.

Types

type Event

type Event struct {
	Name string
	Type reflect.Type
	// PC, File and Line locate the declaration, used to find its package
	// and documentation.
	PC   uintptr
	File string
	Line int
}

Event is a typed event sent from Go to pages.

type Method

type Method struct {
	Name   string
	Params []reflect.Type
	// Channels marks the parameters that are channels (golet.Channel),
	// whose Params are the type of their values.
	Channels []bool
	Variadic bool
	Result   reflect.Type
	HasCtx   bool
	// PC is the entry of the method's code, used to find its source.
	PC uintptr
}

Method is a bound method. Params excludes the receiver and an optional leading context.Context (HasCtx).

type Model

type Model struct {
	Services []Service
	Events   []Event
}

Model describes the API to generate a client for.

type Service

type Service struct {
	Name    string
	Type    reflect.Type
	Methods []Method
}

Service is a bound Go value whose methods are callable from the page.

Directories

Path Synopsis
internal
fixture
Package fixture declares types used to test the TypeScript generator.
Package fixture declares types used to test the TypeScript generator.

Jump to

Keyboard shortcuts

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