tron

package module
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 21 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 SetName

func SetName(name string)

SetName overrides default the application name.

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) Info

func (a *App) Info() *Info

Info returns application info.

func (*App) Logger

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

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) 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.

func AddLogCaller

func AddLogCaller() 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) 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 WithAdminHTTP

func WithAdminHTTP(port uint16) Option

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

Example:

tron.New(tron.WithAdminHTTP(8081))

func WithCORSAllowedAuthentication added in v0.2.1

func WithCORSAllowedAuthentication(allow bool) Option

WithCORSAllowedAuthentication sets if HTTP client allows authentication like cookies, SSL certs and HTTP basic auth.

func WithCORSAllowedHeaders added in v0.2.1

func WithCORSAllowedHeaders(headers []string) Option

WithCORSAllowedHeaders sets a list of non simple headers the HTTP client is allowed to use with cross-domain requests. If the special "*" value is present in the list, all headers will be allowed. Default value is [] but "Origin" is always appended to the list.

func WithCORSAllowedOrigins added in v0.2.1

func WithCORSAllowedOrigins(origins []string) Option

WithCORSAllowedOrigins sets allowed origin domains for cross-domain requests. If the special "*" value is present in the list, all origins will be allowed. An origin may contain a wildcard (*) to replace 0 or more characters (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penality. Only one wildcard can be used per origin. Default option enable CORS for requests on admin port.

func WithConfigMap added in v0.7.0

func WithConfigMap(cfg map[string]interface{}) 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) 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) 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) 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{}) Option

WithLogField adds field to the Logger.

Example:

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

func WithPublicGRPC added in v0.7.0

func WithPublicGRPC(port uint16) 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) Option

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

Example:

tron.New(tron.WithPublicGRPC(8080))

func WithRealtimeConfig added in v0.8.0

func WithRealtimeConfig() Option

WithRealtimeConfig returns a Option that activate realtime config. Realtime config watch only values file for current namespace.

Example:

tron.New(tron.WithRealtimeConfig())

type RunOption

type RunOption = app.RunOption

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

func WithTLSConfig

func WithTLSConfig(config *tls.Config) RunOption

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

func WithTLSKeyPair

func WithTLSKeyPair(certFile, keyFile string) RunOption

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

func WithUnaryInterceptor

func WithUnaryInterceptor(interceptor grpc.UnaryServerInterceptor) 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.

Directories

Path Synopsis
cmd
tron Module
example module
internal
admin
Code generated for package admin by go-bindata DO NOT EDIT.
Code generated for package admin by go-bindata DO NOT EDIT.
app
Package app contains base application constants, flags and options.
Package app contains base application constants, flags and options.
config
Package config contains viper config initialisation method.
Package config contains viper config initialisation method.
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