Documentation
¶
Index ¶
- Constants
- Variables
- func AddEndpointNameMetrics(str string, ctx context.Context) context.Context
- func ConvertStringToTimeDate(input string) (time.Time, error)
- func DatePtrToString(date *time.Time) string
- func DatePtrToStringPtr(date *time.Time) *string
- func DateTimeToString(date time.Time) string
- func DateToString(date time.Time) string
- func DateToStringPtr(date time.Time) *string
- func Decrypt(ciphertextHex string, keyStr string) ([]byte, error)
- func Encrypt(plaintext []byte, keyStr string) ([]byte, error)
- func Exec[T ITaskRunner](runner T, shutdowner fx.Shutdowner)
- func Execute[T ITaskRunner]()
- func FormatBytes(b int64) string
- func GenerateHttpClientWithInstrumentation(serviceName string) *http.Client
- func GetHostname() string
- func GetMidnight(t time.Time) time.Time
- func GetTimestamp() string
- func Invoke(invoke any, acceptedmodes ...string)
- func IsMode(acceptedmodes ...string) bool
- func Module(name string, register func())
- func NowString() string
- func NowTime() time.Time
- func Populate(top any, acceptedmodes ...string)
- func Provide(provide any, acceptedmodes ...string)
- func ProvideAs[T any](ctor any, acceptedmodes ...string)
- func ProvideAsNamed[T any](ctor any, name string, acceptedmodes ...string)
- func ProvideAsNamedWith[T any](ctor any, name string, value any, acceptedmodes ...string)
- func ProvideAsWith[T any](ctor any, value any, acceptedmodes ...string)
- func ProvideNamed(ctor any, name string, acceptedmodes ...string)
- func ProvideNamedWith(ctor any, name string, value any, acceptedmodes ...string)
- func ProvideWith(provide any, value any, acceptedmodes ...string)
- func ReadConfig(projectConfigFile, ConfigFileEnvVar string, appconfig any) error
- func Run()
- func Start(ctx context.Context) (*fx.App, error)
- func StringPtrToString(s *string) string
- func StringToDatePtr(date string) *time.Time
- func StringToDateTime(date string) time.Time
- func StringToDateTimePtr(date string) *time.Time
- func Supply(value any, acceptedmodes ...string)
- type ApplicationError
- func BusinessErrorWithCodeAndMessage(code, message string) *ApplicationError
- func BusinessErrorWithError(err error) *ApplicationError
- func ConcurrentN[T, R any](items []T, concurrency int, fn func(T) (R, *ApplicationError)) ([]R, *ApplicationError)
- func ConcurrentTwo[A, B any](firstTask func() (A, *ApplicationError), ...) (A, B, *ApplicationError)
- func NotFoundError() *ApplicationError
- func StringToDate(date string) (time.Time, *ApplicationError)
- func TechnicalErrorWithCodeAndMessage(code, message string) *ApplicationError
- func TechnicalErrorWithError(err error) *ApplicationError
- func ValidateStruct(i interface{}) *ApplicationError
- type Config
- type Field
- type FlagDefinition
- type ITaskRunner
- type In
- type MetricLogHook
- type Out
- type ServerMetrics
- type Tracer
Constants ¶
const ( DateFormat = "2006-01-02" DateTimeFormat = "2006-01-02 15:04:05" DateTimeZoneFormat = "2006-01-02T15:04:05.999Z07:00" )
const ErrValidation = "ERR_VALIDATION"
Variables ¶
var AppName string
var BuildDate string
var BuildVersion string
var HealthHandler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte("OK")) })
HealthHandler is a simple liveness endpoint that always returns HTTP 200 OK.
var Logo []byte
var Mode = os.Getenv("MODE")
var SHA string
var Task = &cobra.Command{}
var TaskConfig any
var Validator = validator.New()
Functions ¶
func AddEndpointNameMetrics ¶
func DatePtrToString ¶ added in v0.0.3
func DatePtrToStringPtr ¶ added in v0.0.3
func DateTimeToString ¶
func DateToString ¶
func DateToStringPtr ¶
func Decrypt ¶ added in v0.0.19
decrypt decritta un messaggio esadecimale usando l'AppID come chiave. Il nonce è atteso all'inizio del ciphertext decodificato da hex.
func Exec ¶ added in v0.0.11
func Exec[T ITaskRunner](runner T, shutdowner fx.Shutdowner)
func Execute ¶ added in v0.0.5
func Execute[T ITaskRunner]()
func FormatBytes ¶ added in v0.0.26
func GetHostname ¶
func GetHostname() string
func GetTimestamp ¶
func GetTimestamp() string
func Invoke ¶
Invoke registra una funzione eseguita all'avvio (side-effect). acceptedmodes opzionale.
func IsMode ¶ added in v0.0.28
IsMode reports whether the current Mode is among the given modes. With no modes it returns true (i.e. "any mode"), coherently with the *If helpers.
func Module ¶ added in v0.0.28
func Module(name string, register func())
Module raggruppa in un fx.Module(name) tutte le registrazioni (Provide/Supply/Invoke, e i loro wrapper ProvideAs/ProvideNamed/...) effettuate dentro register. Serve solo per il namespacing del grafo/log fx: i provide NON sono privati (nessun fx.Private), quindi restano visibili all'intera app e i value group aggregano come prima (un consumer nel modulo vede anche i produttori a root/antenati). Il mode-gating resta per-registrazione (ogni Provide/Supply gate-a con IsMode prima di finire nello scope). Le chiamate fuori da Module continuano a registrare nello scope root, quindi è retrocompatibile.
core.Module("batch", func() { storemongo.Module(); scheduler.Module(cfg) })
func Populate ¶ added in v0.0.11
Populate registra un target per fx.Populate. acceptedmodes opzionale.
func Provide ¶ added in v0.0.28
Provide registra un costruttore/valore. Se acceptedmodes è vuoto registra sempre; altrimenti solo se Mode è tra quelli indicati.
core.Provide(NewData) // sempre core.Provide(NewData, "batch") // solo in mode "batch"
func ProvideAs ¶ added in v0.0.28
ProvideAs registra ctor annotandolo per essere fornito come l'interfaccia T, eliminando il boilerplate fx.Annotate(ctor, fx.As(new(T))). Il costruttore si passa nudo; l'interfaccia è il type parameter. acceptedmodes opzionale.
core.ProvideAs[IData](NewData) core.ProvideAs[IData](NewData, engine.Batch, engine.Worker)
func ProvideAsNamed ¶ added in v0.0.28
ProvideAsNamed registra ctor annotandolo sia come interfaccia T (fx.As) sia con un nome (fx.ResultTags), combinando ProvideAs e ProvideNamed.
core.ProvideAsNamed[IClient](svc.New, "primary")
func ProvideAsNamedWith ¶ added in v0.0.28
ProvideAsNamedWith è ProvideAsNamed con il valore consumato dal costruttore.
core.ProvideAsNamedWith[IClient](svc.New, &cfg.C, "primary")
func ProvideAsWith ¶ added in v0.0.28
ProvideAsWith è ProvideWith con il costruttore registrato come l'interfaccia T.
core.ProvideAsWith[IClient](NewService, &cfg.C, engine.Batch, engine.Worker, engine.Api)
func ProvideNamed ¶ added in v0.0.28
ProvideNamed registra ctor annotandolo con un nome (fx.ResultTags(`name:"..."`)), eliminando il boilerplate fx.Annotate(ctor, fx.ResultTags(`name:"..."`)). Il costruttore si passa nudo come primo parametro; acceptedmodes opzionale.
core.ProvideNamed(locker.NewCatalogoLocker, "catalogo") core.ProvideNamed(locker.NewJobLocker, "job", engine.Batch)
func ProvideNamedWith ¶ added in v0.0.28
ProvideNamedWith è ProvideNamed con il valore (tipicamente il config) che il costruttore consuma, fornito nella stessa chiamata (posizione coerente con ProvideWith).
core.ProvideNamedWith(mngr.NewClient, &cfg.MngrConfig, "mngr")
func ProvideWith ¶ added in v0.0.28
ProvideWith registra un costruttore insieme al valore (tipicamente il config) che consuma, in un'unica chiamata. acceptedmodes opzionale.
func ReadConfig ¶
func StringPtrToString ¶ added in v0.0.4
func StringToDatePtr ¶
func StringToDateTime ¶
func StringToDateTimePtr ¶
Types ¶
type ApplicationError ¶
type ApplicationError struct {
StatusCode int `json:"-" bson:"statusCode"`
Ambit string `json:"ambit"`
Code string `json:"code"`
Message string `json:"message"`
}
func BusinessErrorWithCodeAndMessage ¶
func BusinessErrorWithCodeAndMessage(code, message string) *ApplicationError
func BusinessErrorWithError ¶
func BusinessErrorWithError(err error) *ApplicationError
func ConcurrentN ¶ added in v0.0.26
func ConcurrentN[T, R any](items []T, concurrency int, fn func(T) (R, *ApplicationError)) ([]R, *ApplicationError)
ConcurrentN runs fn on each item with at most concurrency goroutines in parallel. Results are returned in the same order as inputs; the first error encountered is returned.
func ConcurrentTwo ¶ added in v0.0.26
func ConcurrentTwo[A, B any]( firstTask func() (A, *ApplicationError), secondTask func() (B, *ApplicationError), ) (A, B, *ApplicationError)
ConcurrentTwo runs two tasks in parallel. Both goroutines always complete — no goroutine leak.
func NotFoundError ¶
func NotFoundError() *ApplicationError
func StringToDate ¶
func StringToDate(date string) (time.Time, *ApplicationError)
func TechnicalErrorWithCodeAndMessage ¶
func TechnicalErrorWithCodeAndMessage(code, message string) *ApplicationError
func TechnicalErrorWithError ¶
func TechnicalErrorWithError(err error) *ApplicationError
func ValidateStruct ¶ added in v0.0.4
func ValidateStruct(i interface{}) *ApplicationError
func (*ApplicationError) Error ¶
func (m *ApplicationError) Error() string
func (*ApplicationError) GetStatus ¶
func (m *ApplicationError) GetStatus() int
func (*ApplicationError) IsBusinessError ¶
func (m *ApplicationError) IsBusinessError() bool
func (*ApplicationError) IsTechnicalError ¶
func (m *ApplicationError) IsTechnicalError() bool
type FlagDefinition ¶ added in v0.0.5
type FlagDefinition struct {
// contains filtered or unexported fields
}
type ITaskRunner ¶ added in v0.0.5
type ITaskRunner interface {
Execute()
}
type MetricLogHook ¶
type MetricLogHook struct {
LogEvent metric.Int64Counter
}
LevelHook applies a different hook for each level.
func (*MetricLogHook) Init ¶
func (m *MetricLogHook) Init()
type ServerMetrics ¶
type ServerMetrics struct {
}
func NewServerMetrics ¶
func NewServerMetrics(lc fx.Lifecycle) *ServerMetrics
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package lock defines a neutral, backend-agnostic distributed-lock primitive.
|
Package lock defines a neutral, backend-agnostic distributed-lock primitive. |