core

package module
v0.0.28 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 43 Imported by: 11 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DateFormat         = "2006-01-02"
	DateTimeFormat     = "2006-01-02 15:04:05"
	DateTimeZoneFormat = "2006-01-02T15:04:05.999Z07:00"
)
View Source
const ErrValidation = "ERR_VALIDATION"

Variables

View Source
var AppName string
View Source
var BuildDate string
View Source
var BuildVersion string
View Source
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.

View Source
View Source
var Mode = os.Getenv("MODE")
View Source
var Task = &cobra.Command{}
View Source
var TaskConfig any
View Source
var Translator = ut.New(it.New(), it.New())
View Source
var Validator = validator.New()

Functions

func AddEndpointNameMetrics

func AddEndpointNameMetrics(str string, ctx context.Context) context.Context

func ConvertStringToTimeDate

func ConvertStringToTimeDate(input string) (time.Time, error)

func DatePtrToString added in v0.0.3

func DatePtrToString(date *time.Time) string

func DatePtrToStringPtr added in v0.0.3

func DatePtrToStringPtr(date *time.Time) *string

func DateTimeToString

func DateTimeToString(date time.Time) string

func DateToString

func DateToString(date time.Time) string

func DateToStringPtr

func DateToStringPtr(date time.Time) *string

func Decrypt added in v0.0.19

func Decrypt(ciphertextHex string, keyStr string) ([]byte, error)

decrypt decritta un messaggio esadecimale usando l'AppID come chiave. Il nonce è atteso all'inizio del ciphertext decodificato da hex.

func Encrypt added in v0.0.19

func Encrypt(plaintext []byte, keyStr string) ([]byte, error)

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 FormatBytes(b int64) string

func GenerateHttpClientWithInstrumentation

func GenerateHttpClientWithInstrumentation(serviceName string) *http.Client

func GetHostname

func GetHostname() string

func GetMidnight added in v0.0.3

func GetMidnight(t time.Time) time.Time

func GetTimestamp

func GetTimestamp() string

func Invoke

func Invoke(invoke any, acceptedmodes ...string)

Invoke registra una funzione eseguita all'avvio (side-effect). acceptedmodes opzionale.

func IsMode added in v0.0.28

func IsMode(acceptedmodes ...string) bool

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 NowString

func NowString() string

func NowTime

func NowTime() time.Time

func Populate added in v0.0.11

func Populate(top any, acceptedmodes ...string)

Populate registra un target per fx.Populate. acceptedmodes opzionale.

func Provide added in v0.0.28

func Provide(provide any, acceptedmodes ...string)

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

func ProvideAs[T any](ctor any, acceptedmodes ...string)

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

func ProvideAsNamed[T any](ctor any, name string, acceptedmodes ...string)

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

func ProvideAsNamedWith[T any](ctor any, name string, value any, acceptedmodes ...string)

ProvideAsNamedWith è ProvideAsNamed con il valore consumato dal costruttore.

core.ProvideAsNamedWith[IClient](svc.New, &cfg.C, "primary")

func ProvideAsWith added in v0.0.28

func ProvideAsWith[T any](ctor any, value any, acceptedmodes ...string)

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

func ProvideNamed(ctor any, name string, acceptedmodes ...string)

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

func ProvideNamedWith(ctor any, name string, value any, acceptedmodes ...string)

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

func ProvideWith(provide any, value any, acceptedmodes ...string)

ProvideWith registra un costruttore insieme al valore (tipicamente il config) che consuma, in un'unica chiamata. acceptedmodes opzionale.

func ReadConfig

func ReadConfig(projectConfigFile, ConfigFileEnvVar string, appconfig any) error

func Run added in v0.0.5

func Run()

func Start

func Start(ctx context.Context) (*fx.App, error)

func StringPtrToString added in v0.0.4

func StringPtrToString(s *string) string

func StringToDatePtr

func StringToDatePtr(date string) *time.Time

func StringToDateTime

func StringToDateTime(date string) time.Time

func StringToDateTimePtr

func StringToDateTimePtr(date string) *time.Time

func Supply

func Supply(value any, acceptedmodes ...string)

Supply registra un valore già istanziato. acceptedmodes opzionale come in Provide.

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

func (*ApplicationError) Log added in v0.0.26

func (e *ApplicationError) Log(op fmt.Stringer, fields ...Field)

type Config

type Config struct {
	Log struct {
		Ignore     bool
		Level      string
		EnableJSON bool
		Metric     bool
	}
	AppConfig any `yaml:"config" mapstructure:"config" json:"config"`
}

type Field added in v0.0.26

type Field struct {
	Key   string
	Value any
}

func F added in v0.0.26

func F(k string, v any) Field

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 In added in v0.0.28

type In = fx.In

type MetricLogHook

type MetricLogHook struct {
	LogEvent metric.Int64Counter
}

LevelHook applies a different hook for each level.

func (*MetricLogHook) Init

func (m *MetricLogHook) Init()

func (*MetricLogHook) Run

func (m *MetricLogHook) Run(e *zerolog.Event, level zerolog.Level, message string)

type Out added in v0.0.28

type Out = fx.Out

type ServerMetrics

type ServerMetrics struct {
}

func NewServerMetrics

func NewServerMetrics(lc fx.Lifecycle) *ServerMetrics

type Tracer

type Tracer struct {
	TracerProvider *trace.TracerProvider
}

func NewTracer added in v0.0.3

func NewTracer(lc fx.Lifecycle) *Tracer

Directories

Path Synopsis
Package lock defines a neutral, backend-agnostic distributed-lock primitive.
Package lock defines a neutral, backend-agnostic distributed-lock primitive.

Jump to

Keyboard shortcuts

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