gotsrpc

package module
v2.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 16 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)
)
View Source
const (
	HeaderServiceToService = "X-Foomo-S2s"
)

Variables

This section is empty.

Functions

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 any, callStats *CallStats, r *http.Request) error

func MustRegisterUnionExt

func MustRegisterUnionExt(v ...any)

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 []any, stats *CallStats)

func RegisterUnionExt

func RegisterUnionExt(v ...any) error

func Reply

func Reply(response []any, 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 any, tag uint64, ext codec.InterfaceExt) error

func SetMSGPackExt

func SetMSGPackExt(rt any, tag uint64, ext codec.BytesExt) error

Types

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 []any, reply []any) (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 any) 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 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

type MonitorFn

type MonitorFn func(w http.ResponseWriter, r *http.Request, args, rets []any, 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 UnionExt

type UnionExt struct{}

func (*UnionExt) ConvertExt

func (x *UnionExt) ConvertExt(v any) any

func (*UnionExt) UpdateExt

func (x *UnionExt) UpdateExt(dst any, src any)

Directories

Path Synopsis
cmd
gotsrpc command
internal
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