gotsrpc

package module
v2.9.2 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 28 Imported by: 10

README

Build Status Go Report Card Coverage Status GoDoc

gotsrpc

Go / TypeScript and Go / Go RPC

Documentation

Please refer to the documentation:

https://www.foomo.org/docs/projects/gotsrpc

Installation

Follow the docs:

https://www.foomo.org/docs/projects/gotsrpc/cli#installation

From source to /usr/local/bin/gotsrpc:

go get github.com/foomo/gotsrpc/v2
cd $GOPATH/src/github.com/foomo/gotsrpc
make install

Release downloads:

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

How to Contribute

Please refer to the CONTRIBUTING details and follow the CODE_OF_CONDUCT and SECURITY guidelines.

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:stylecheck
)
View Source
const (
	HeaderServiceToService = "X-Foomo-S2s"
)

Variables

View Source
var ReaderTrace = false

Functions

func Build

func Build(conf *config.Config, goPath 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 GetCalledFunc

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

func InstrumentedService

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

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 despite the fact, that 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
}

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     interface{} `json:"d,omitempty"`
	ErrCause *Error      `json:"c,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:stylecheck

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"
	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 TimeExt

type TimeExt struct{}

func (*TimeExt) ConvertExt

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

func (*TimeExt) UpdateExt

func (x *TimeExt) UpdateExt(dest interface{}, src interface{})

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"`
}

Jump to

Keyboard shortcuts

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