bean

package module
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const SentryHubContextKey = "sentry"

This key is inherited from `sentryecho` package as the package doesn't support the key for external use.

Variables

View Source
var BeanLogger echo.Logger

This is a global variable to hold the debug logger so that we can log data from service, repository or anywhere.

View Source
var NetHttpFastTransporter *http.Transport

Support a DNS cache version of the net/http Transport.

View Source
var TenantAlterDbHostParam string

If a command or service wants to use a different `host` parameter for tenant database connection then it's easy to do just by passing that parameter string name using `bean.TenantAlterDbHostParam`. Therfore, `bean` will overwrite all host string in `TenantConnections`.`Connections` JSON.

Functions

func Cleanup added in v1.1.34

func Cleanup()

To clean up any bean resources before the program terminates. Call this function using `defer` like `defer Cleanup()`

func ContextTimeout added in v1.1.45

func ContextTimeout(timeout time.Duration) echo.MiddlewareFunc

ContextTimeout return custom context timeout middleware

func DefaultBeforeBreadcrumb added in v1.1.18

func DefaultBeforeBreadcrumb(breadcrumb *sentry.Breadcrumb, hint *sentry.BreadcrumbHint) *sentry.Breadcrumb

Modify breadcrumbs through beforeBreadcrumb function.

func DefaultBeforeSend added in v1.1.18

func DefaultBeforeSend(event *sentry.Event, hint *sentry.EventHint) *sentry.Event

Modify event through beforeSend function.

func Logger added in v1.1.18

func Logger() echo.Logger

The bean Logger to have debug log from anywhere.

func NewEcho

func NewEcho() *echo.Echo

func SentryCaptureException added in v1.1.19

func SentryCaptureException(c echo.Context, err error)

This is a global function to send sentry exception if you configure the sentry through env.json. You cann pass a proper context or nil.

func SentryCaptureMessage added in v1.1.19

func SentryCaptureMessage(c echo.Context, msg string)

This is a global function to send sentry message if you configure the sentry through env.json. You cann pass a proper context or nil.

Types

type Bean

type Bean struct {
	DBConn      *DBDeps
	Echo        *echo.Echo
	BeforeServe func()

	Config Config
	// contains filtered or unexported fields
}

func New

func New() (b *Bean)

func (*Bean) DefaultHTTPErrorHandler

func (b *Bean) DefaultHTTPErrorHandler() echo.HTTPErrorHandler

func (*Bean) InitDB

func (b *Bean) InitDB()

InitDB initialize all the database dependencies and store it in global variable `global.DBConn`.

func (*Bean) ServeAt

func (b *Bean) ServeAt(host, port string)

func (*Bean) UseErrorHandlerFuncs

func (b *Bean) UseErrorHandlerFuncs(errHdlrFuncs ...berror.ErrorHandlerFunc)

func (*Bean) UseMiddlewares

func (b *Bean) UseMiddlewares(middlewares ...echo.MiddlewareFunc)

func (*Bean) UseValidation

func (b *Bean) UseValidation(validateFuncs ...validator.ValidatorFunc)

type Config

type Config struct {
	ProjectName  string
	Environment  string
	DebugLogPath string
	Secret       string
	AccessLog    struct {
		On                bool
		BodyDump          bool
		Path              string
		BodyDumpMaskParam []string
		ReqHeaderParam    []string
		SkipEndpoints     []string
	}
	Prometheus struct {
		On            bool
		SkipEndpoints []string
	}
	HTTP struct {
		Port            string
		Host            string
		BodyLimit       string
		IsHttpsRedirect bool
		Timeout         time.Duration
		ErrorMessage    struct {
			E404 struct {
				Json []struct {
					Key   string
					Value string
				}
				Html struct {
					File string
				}
			}
			E405 struct {
				Json []struct {
					Key   string
					Value string
				}
				Html struct {
					File string
				}
			}
			E500 struct {
				Json []struct {
					Key   string
					Value string
				}
				Html struct {
					File string
				}
			}
			E504 struct {
				Json []struct {
					Key   string
					Value string
				}
				Html struct {
					File string
				}
			}
			Default struct {
				Json []struct {
					Key   string
					Value string
				}
				Html struct {
					File string
				}
			}
		}
		KeepAlive     bool
		AllowedMethod []string
		SSL           struct {
			On            bool
			CertFile      string
			PrivFile      string
			MinTLSVersion uint16
		}
	}
	NetHttpFastTransporter struct {
		On                  bool
		MaxIdleConns        *int
		MaxIdleConnsPerHost *int
		MaxConnsPerHost     *int
		IdleConnTimeout     *time.Duration
		DNSCacheTimeout     *time.Duration
	}
	HTML struct {
		ViewsTemplateCache bool
	}
	Database struct {
		Tenant struct {
			On bool
		}
		MySQL  dbdrivers.SQLConfig
		Mongo  dbdrivers.MongoConfig
		Redis  dbdrivers.RedisConfig
		Memory dbdrivers.MemoryConfig
	}
	Sentry   SentryConfig
	Security struct {
		HTTP struct {
			Header struct {
				XssProtection         string
				ContentTypeNosniff    string
				XFrameOptions         string
				HstsMaxAge            int
				ContentSecurityPolicy string
			}
		}
	}
	AsyncPool []struct {
		Name       string
		Size       *int
		BlockAfter *int
	}
}
var BeanConfig Config

Hold the useful configuration settings of bean so that we can use it quickly from anywhere.

type DBDeps

type DBDeps struct {
	MasterMySQLDB      *gorm.DB
	MasterMySQLDBName  string
	TenantMySQLDBs     map[uint64]*gorm.DB
	TenantMySQLDBNames map[uint64]string
	MasterMongoDB      *mongo.Client
	MasterMongoDBName  string
	TenantMongoDBs     map[uint64]*mongo.Client
	TenantMongoDBNames map[uint64]string
	MasterRedisDB      *dbdrivers.RedisDBConn
	TenantRedisDBs     map[uint64]*dbdrivers.RedisDBConn
	MemoryDB           *dbdrivers.Memory
}

All database connections are initialized using `DBDeps` structure.

type SentryConfig added in v1.1.18

type SentryConfig struct {
	On                  bool
	Debug               bool
	Dsn                 string
	Timeout             time.Duration
	TracesSampleRate    float64
	SkipTracesEndpoints []string
	ClientOptions       *sentry.ClientOptions
	ConfigureScope      func(scope *sentry.Scope)
}

Directories

Path Synopsis
Safe way to execute `go routine` without crashing the parent process while having a `panic`.
Safe way to execute `go routine` without crashing the parent process while having a `panic`.
cmd
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
bean
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Do not change this file.
Do not change this file.
Package urlpath matches paths against a template.
Package urlpath matches paths against a template.

Jump to

Keyboard shortcuts

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