gotsrpc

package module
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 29 Imported by: 13

README

Build Status Go Report Card GoDoc

gotsrpc

Go / TypeScript and Go / Go RPC

Documentation

Please refer to the documentation.

$ gotsrpc
gotsrpc

Usage:
  gotsrpc [options] <config-file>

Options:
  -version   Display version information
  -debug     Print debug information

Examples:
  $ gotsrpc path/to/gotsrpc.yaml

Installation

Please follow the documentation.

Download binary

Download a binary release

Build from source
go install github.com/foomo/gotsrpc@latest
Homebrew (Linux/macOS)

If you use Homebrew, you can install like this:

brew install foomo/tap/gotsrpc
Mise

If you use mise, you can install like this:

mise use github.com:foomo/gotsrpc

Release downloads:

https://github.com/foomo/gotsrpc/releases

How to Contribute

Contributions are welcome! Please read the contributing guide.

Contributors

License

Distributed under MIT License, please see license file within the code for more details.

Made with ♥ foomo by bestbytes

Documentation

Index

Constants

View Source
const (
	EncodingMsgpack = ClientEncoding(0)
	EncodingJson    = ClientEncoding(1) //nolint:staticcheck
)
View Source
const (
	HeaderServiceToService = "X-Foomo-S2s"
)

Variables

View Source
var ReaderTrace = false

Functions

func Build

func Build(conf *config.Config, goPath, goRoot string)

func ClearStats

func ClearStats(r *http.Request)

func ErrorCouldNotLoadArgs

func ErrorCouldNotLoadArgs(w http.ResponseWriter)

func ErrorCouldNotReply

func ErrorCouldNotReply(w http.ResponseWriter)

func ErrorFuncNotFound

func ErrorFuncNotFound(w http.ResponseWriter)

func ErrorMethodNotAllowed

func ErrorMethodNotAllowed(w http.ResponseWriter)

func ErrorReply added in v2.14.0

func ErrorReply(err error) any

ErrorReply wraps an error return value so Reply can detect it at runtime. Used by generated proxy code for methods whose last return type is the error interface.

func GetCalledFunc

func GetCalledFunc(r *http.Request, endPoint string) string

func InstrumentedService deprecated

func InstrumentedService(middleware http.HandlerFunc, handleStats GoRPCCallStatsHandlerFun) http.HandlerFunc

Deprecated: will be removed

func LoadArgs

func LoadArgs(args interface{}, callStats *CallStats, r *http.Request) error

func MustRegisterUnionExt

func MustRegisterUnionExt(v ...interface{})

func NewMSGPackDecoderBytes

func NewMSGPackDecoderBytes(b []byte) *codec.Decoder

func NewMSGPackEncoderBytes

func NewMSGPackEncoderBytes(b *[]byte) *codec.Encoder

func NoopMonitor

func NoopMonitor(w http.ResponseWriter, r *http.Request, args, rets []interface{}, stats *CallStats)

func RegisterUnionExt

func RegisterUnionExt(v ...interface{}) error

func RenderGoRPCClients

func RenderGoRPCClients(services ServiceList, longPackageName, packageName string, config *config.Target) (gocode string, err error)

func RenderGoRPCProxies

func RenderGoRPCProxies(services ServiceList, longPackageName, packageName string, config *config.Target) (gocode string, err error)

func RenderGoTSRPCClients

func RenderGoTSRPCClients(services ServiceList, longPackageName, packageName string, config *config.Target) (gocode string, err error)

func RenderGoTSRPCProxies

func RenderGoTSRPCProxies(services ServiceList, longPackageName, packageName string, config *config.Target, unions map[string][]string) (gocode string, err error)

func RenderTypeScriptServices

func RenderTypeScriptServices(services ServiceList, mappings config.TypeScriptMappings, scalars map[string]*Scalar, structs map[string]*Struct, target *config.Target) (typeScript string, err error)

func Reply

func Reply(response []interface{}, stats *CallStats, r *http.Request, w http.ResponseWriter) error

Reply although this is a public method - do not call it, it will be called by generated code

func RequestWithStatsContext

func RequestWithStatsContext(r *http.Request) *http.Request

func SetDefaultHttpClientFactory

func SetDefaultHttpClientFactory(factory HttpClientFactory)

func SetJSONExt

func SetJSONExt(rt interface{}, tag uint64, ext codec.InterfaceExt) error

func SetMSGPackExt

func SetMSGPackExt(rt interface{}, tag uint64, ext codec.BytesExt) error

Types

type Array

type Array struct {
	Value *Value
	Len   int // 0 = slice, >0 = fixed-size array
}

type CallStats

type CallStats struct {
	Package       string
	Service       string
	Func          string
	Execution     time.Duration
	Marshalling   time.Duration
	Unmarshalling time.Duration
	RequestSize   int
	ResponseSize  int
	ErrorCode     int
	ErrorType     string
	ErrorMessage  string
}

func GetStatsForRequest

func GetStatsForRequest(r *http.Request) (*CallStats, bool)

type Client

type Client interface {
	Call(ctx context.Context, url string, endpoint string, method string, args []interface{}, reply []interface{}) (err error)
	SetClientEncoding(encoding ClientEncoding)
	SetTransportHttpClient(client *http.Client)
	SetDefaultHeaders(headers http.Header)
}

func NewClient

func NewClient() Client

func NewClientWithHttpClient

func NewClientWithHttpClient(client *http.Client) Client

type ClientEncoding

type ClientEncoding int

type ClientError

type ClientError struct {
	// contains filtered or unexported fields
}

func NewClientError

func NewClientError(err error) *ClientError

func (*ClientError) Unwrap added in v2.9.2

func (e *ClientError) Unwrap() error

Unwrap interface

type Error

type Error struct {
	Msg       string   `json:"m"`
	Pkg       string   `json:"p"`
	Type      string   `json:"t"`
	Data      any      `json:"d,omitempty"`
	ErrCause  *Error   `json:"c,omitempty"`
	ErrCauses []*Error `json:"cs,omitempty"`
}

func NewError

func NewError(err error) *Error

NewError returns a new instance

func (*Error) As

func (e *Error) As(err interface{}) bool

As interface

func (*Error) Cause

func (e *Error) Cause() error

Cause interface

func (*Error) Error

func (e *Error) Error() string

Error interface

func (*Error) Format

func (e *Error) Format(s fmt.State, verb rune)

Format interface

func (*Error) Is

func (e *Error) Is(err error) bool

Is interface

func (*Error) Unwrap

func (e *Error) Unwrap() []error

Unwrap interface

type Field

type Field struct {
	Value    *Value
	Name     string    `json:",omitempty"`
	JSONInfo *JSONInfo `json:",omitempty"`
}

type GoRPCCallStatsHandlerFun

type GoRPCCallStatsHandlerFun func(stats *CallStats)

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
	// contains filtered or unexported fields
}

func NewHTTPError

func NewHTTPError(msg string, code int) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

type HttpClientFactory

type HttpClientFactory func() *http.Client //nolint:staticcheck

type JSONInfo

type JSONInfo struct {
	Name      string
	Type      string
	Union     bool
	Inline    bool
	OmitEmpty bool
	Ignore    bool
}

type Map

type Map struct {
	Key       *Value
	Value     *Value
	KeyType   string
	KeyGoType string
}

type Method

type Method struct {
	Name   string
	Args   []*Field
	Return []*Field
}

type MonitorFn

type MonitorFn func(w http.ResponseWriter, r *http.Request, args, rets []interface{}, stats *CallStats)
var Monitor MonitorFn = NoopMonitor

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ResponseWriter) Status

func (r *ResponseWriter) Status() int

func (*ResponseWriter) WriteHeader

func (r *ResponseWriter) WriteHeader(status int)

type Scalar

type Scalar struct {
	Name    string
	Package string
	Type    ScalarType
}

func (*Scalar) FullName

func (st *Scalar) FullName() string

type ScalarType

type ScalarType string
const (
	ScalarTypeString ScalarType = "string"
	ScalarTypeAny    ScalarType = "any"
	ScalarTypeByte   ScalarType = "byte"
	ScalarTypeError  ScalarType = "error"
	ScalarTypeNumber ScalarType = "number"
	ScalarTypeBool   ScalarType = "bool"
	ScalarTypeNone   ScalarType = ""
)

type Service

type Service struct {
	Name        string
	Methods     ServiceMethods
	Endpoint    string
	IsInterface bool
}

type ServiceList

type ServiceList []*Service

func Read

func Read(
	goPaths []string,
	gomod config.Namespace,
	packageName string,
	serviceMap map[string]string,
	missingTypes map[string]bool,
	missingConstants map[string]bool,
) (
	pkgName string,
	services ServiceList,
	structs map[string]*Struct,
	scalars map[string]*Scalar,
	constantTypes map[string]map[string]interface{},
	err error,
)

func (ServiceList) Len

func (sl ServiceList) Len() int

func (ServiceList) Less

func (sl ServiceList) Less(i, j int) bool

func (ServiceList) Swap

func (sl ServiceList) Swap(i, j int)

type ServiceMethods

type ServiceMethods []*Method

func (ServiceMethods) Len

func (sm ServiceMethods) Len() int

func (ServiceMethods) Less

func (sm ServiceMethods) Less(i, j int) bool

func (ServiceMethods) Swap

func (sm ServiceMethods) Swap(i, j int)

type Struct

type Struct struct {
	IsError      bool
	Package      string
	Name         string
	Fields       []*Field
	UnionFields  []*Field
	InlineFields []*Field
	Map          *Map
	Array        *Array
}

func (*Struct) DepsSatisfied

func (s *Struct) DepsSatisfied(missingTypes map[string]bool, structs map[string]*Struct, scalars map[string]*Scalar) bool

func (*Struct) FullName

func (s *Struct) FullName() string

type StructType

type StructType struct {
	Name    string
	Package string
}

func (*StructType) FullName

func (st *StructType) FullName() string

type UnionExt

type UnionExt struct{}

func (*UnionExt) ConvertExt

func (x *UnionExt) ConvertExt(v interface{}) interface{}

func (*UnionExt) UpdateExt

func (x *UnionExt) UpdateExt(dst interface{}, src interface{})

type Value

type Value struct {
	JSONInfo     *JSONInfo   `json:",omitempty"`
	IsError      bool        `json:",omitempty"`
	IsInterface  bool        `json:",omitempty"`
	Scalar       *Scalar     `json:",omitempty"`
	ScalarType   ScalarType  `json:",omitempty"`
	GoScalarType string      `json:",omitempty"`
	StructType   *StructType `json:",omitempty"`
	Struct       *Struct     `json:",omitempty"`
	Map          *Map        `json:",omitempty"`
	Array        *Array      `json:",omitempty"`
	IsPtr        bool        `json:",omitempty"`
}

Directories

Path Synopsis
cmd
gotsrpc command
tests
aliases command
context command
errors command
nullable command
time command
types command
union command

Jump to

Keyboard shortcuts

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