tron

package module
v0.26.0-rc1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 23 Imported by: 5

README

Tron

Installation
install tron:
curl -sSfL https://raw.githubusercontent.com/loghole/tron/main/install.sh | sh
tron version
install protoc:
  • linux
$ apt install -y protobuf-compiler
$ protoc --version
  • mac:
$ brew install protobuf
$ protoc --version

Documentation

Overview

Package tron contains base application object, some options and functions to create base app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddLogCaller

func AddLogCaller() app.Option

AddLogCaller configures the Logger to annotate each message with the filename and line number of zap's caller.

func AddLogStacktrace

func AddLogStacktrace(level string) app.Option

AddLogStacktrace configures the Logger to record a stack trace for all messages at or above a given level.

Example:

tron.New(tron.AddLogStacktrace("error"))

func SetName

func SetName(name string)

SetName overrides default the application name.

func WithAdminHTTP

func WithAdminHTTP(port uint16) app.Option

WithAdminHTTP returns a Option that sets admin http port. Cannot be changed by config or env.

Example:

tron.New(tron.WithAdminHTTP(8081))

func WithAtomicLoggerLevel added in v0.27.0

func WithAtomicLoggerLevel(level zap.AtomicLevel) app.Option

WithAtomicLoggerLevel sets atomic logger level.

Example:

level := zap.NewAtomicLevelAt(zapcore.InfoLevel)
tron.New(tron.WithLoggerLevel(level))

func WithConfigMap added in v0.7.0

func WithConfigMap(cfg map[string]interface{}) app.Option

WithConfigMap returns a Option that init app config from map and envs.

Example:

tron.New(tron.WithConfigMap(map[string]interface{}{
	"namespace":         "dev",
	"service_port_grpc": 35900,
	"cockroach_addr":    "db_addr",
	"cockroach_user":    "db_user",
	"cockroach_db":      "db_name",
}))

func WithExitSignals

func WithExitSignals(sig ...os.Signal) app.Option

WithExitSignals returns a Option that sets exit signals for application. Default signals is: syscall.SIGTERM, syscall.SIGINT.

Example:

tron.New(tron.WithExitSignals(syscall.SIGKILL))

func WithGRPCListener added in v0.7.0

func WithGRPCListener(listener net.Listener) app.Option

WithGRPCListener returns a Option that sets net listener for grpc public server. Can be used for create application tests with memory listener.

Example:

listener := bufconn.Listen(1024*1024)

tron.New(tron.WithGRPCListener(listener))

func WithHTTPListener added in v0.7.0

func WithHTTPListener(listener net.Listener) app.Option

WithHTTPListener returns a Option that sets net listener for http public server. Can be used for create application tests with memory listener.

Example:

listener = bufconn.Listen(1024*1024)

tron.New(tron.WithHTTPListener(listener))

func WithLogField

func WithLogField(key string, value interface{}) app.Option

WithLogField adds field to the Logger.

Example:

tron.New(tron.WithLogField("my_field_key", "my_field_value"))

func WithLoggerConfig added in v0.27.0

func WithLoggerConfig(config zap.Config) app.Option

WithLoggerConfig sets logger config.

func WithLoggerLevel added in v0.27.0

func WithLoggerLevel(s string) app.Option

WithLoggerLevel sets logger level.

Example:

tron.New(tron.WithLoggerLevel("info"))

func WithPublicGRPC added in v0.7.0

func WithPublicGRPC(port uint16) app.Option

WithPublicGRPC returns a Option that sets public grpc port. Cannot be changed by config or env.

Example:

tron.New(tron.WithPublicGRPC(8082))

func WithPublicHTTP

func WithPublicHTTP(port uint16) app.Option

WithPublicHTTP returns a Option that sets public http port. Cannot be changed by config or env.

Example:

tron.New(tron.WithPublicGRPC(8080))

func WithStreamInterceptor added in v0.13.0

func WithStreamInterceptor(interceptor grpc.StreamServerInterceptor) app.RunOption

WithStreamInterceptor returns a RunOption that specifies the chained interceptor for streaming RPCs. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All stream interceptors added by this method will be chained.

func WithTLSConfig

func WithTLSConfig(config *tls.Config) app.RunOption

WithTLSConfig returns a RunOption that set tls configuration for grpc and http servers.

func WithTLSKeyPair

func WithTLSKeyPair(certFile, keyFile string) app.RunOption

WithTLSKeyPair returns a RunOption that set tls configuration for grpc and http servers from files.

func WithTracerConfiguration added in v0.27.0

func WithTracerConfiguration(config *tracing.Configuration) app.Option

WithTracerConfiguration sets tracer config.

func WithUnaryInterceptor

func WithUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) app.RunOption

WithUnaryInterceptor returns a RunOption that specifies the chained interceptor for unary RPCs. The first interceptor will be the outer most, while the last interceptor will be the inner most wrapper around the real call. All unary interceptors added by this method will be chained.

Types

type App

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

App is base application object with grpc and http servers, logger and tracer.

func New

func New(options ...app.Option) (*App, error)

New init viper config, logger and tracer.

func (*App) Close added in v0.2.0

func (a *App) Close()

Close closes tracer and logger.

func (*App) Go added in v0.19.1

func (a *App) Go(f func() error)

Go calls the given function in a new goroutine.

The first call to return a non-nil error cancels the group; its error will be returned by Wait.

func (*App) Health added in v0.14.0

func (a *App) Health() healthcheck.Checker

Health returns application health checker.

func (*App) Info

func (a *App) Info() *Info

Info returns application info.

func (*App) Logger

func (a *App) Logger() *zap.SugaredLogger

Logger returns default zap logger.

func (*App) Router

func (a *App) Router() chi.Router

Router returns http router that runs on public port.

func (*App) Run

func (a *App) Run(impl ...transport.Service) error

Run apply run options if exists and starts servers.

func (*App) TraceLogger

func (a *App) TraceLogger() tracelog.Logger

TraceLogger returns wrapped zap logger with opentracing metadata injection to log records.

func (*App) Tracer

func (a *App) Tracer() *tracing.Tracer

Tracer returns wrapped jaeger tracer.

func (*App) Wait added in v0.19.1

func (a *App) Wait() error

Wait blocks until all function calls from the Go method have returned, then returns the first non-nil error (if any) from them.

func (*App) WithRunOptions

func (a *App) WithRunOptions(opts ...app.RunOption) *App

WithRunOptions appends some run options.

type Info

type Info = app.Info

Info contains service information.

func GetInfo added in v0.11.0

func GetInfo() *Info

GetInfo returns base service information.

type Option

type Option = app.Option

Option sets tron options such as ports, config, etc.

type RunOption

type RunOption = app.RunOption

RunOption sets tron run options such as grpc unary interceptors, tls config.

Directories

Path Synopsis
cmd
tron Module
example module
internal
app
Package app contains base application constants, flags and options.
Package app contains base application constants, flags and options.
errors
Package errors represents base tron error struct and parsing method.
Package errors represents base tron error struct and parsing method.
grpc
Package grpc implements an gRPC server.
Package grpc implements an gRPC server.
http
Package http implements an HTTP server.
Package http implements an HTTP server.
Package transport contains base service desc interfaces.
Package transport contains base service desc interfaces.

Jump to

Keyboard shortcuts

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