Categorygithub.com/mawngo/go-corefx
modulepackage
1.3.0
Repository: https://github.com/mawngo/go-corefx.git
Documentation: pkg.go.dev

# README

Core FX

Integrate core feature like configuration slog and sentry into FX.

Install

go get -u github.com/mawngo/go-corefx

Usage

By default, core fx module will load configuration from .configs/app.json then enviroment variables

package main

import (
	"encoding/json"
	"github.com/mawngo/go-corefx"
	"go.uber.org/fx"
)

func main() {
	fx.New(
		configModule,
		corefx.NewModule(),
		fx.Invoke(func(c *myConfig, s fx.Shutdowner) {
			b, _ := json.Marshal(c)
			// app.json: {"app_version": "1.1.1", "log_level": "warn"}
			println(string(b)) // {"app_name":"example","app_version":"1.1.1","log_level":"warn","profile":"","sentry_dsn":"","sentry_log_level":""}
			_ = s.Shutdown()
		}),
	).Run()
}

// requiredConfigModule create a required module that provide corefx.CoreConfig.
var configModule = fx.Module("config",
	fx.Provide(
		newConfig,
		corefx.As[*myConfig](
			new(corefx.CoreConfig),
			new(corefx.SentryConfig), // Optional.
		),
	),
)

// myConfig Create a custom required struct that implement corefx.CoreConfig.
type myConfig struct {
	corefx.CoreEnv
}

func newConfig() *myConfig {
	return &myConfig{
		CoreEnv: corefx.CoreEnv{
			AppName:  "example",
			LogLevel: "info",
		},
	}
}

func (c *myConfig) ProfileValue() string {
	return c.Profile
}

Required: all config implementer should support UnmarshalJSON and MarshalJSON.

# Packages

No description provided by the author

# Functions

As register already registered type T under multiple interfaces.
From create a function that accepts and return self.
LoadJSONConfig load config into CoreConfig.
LoadJSONConfigInto load json config into cfg pointer.
No description provided by the author
NewGlobalSlogLogger create a logger instance and register it globally.
NewModule Create a module that autoconfigure slog, sentry and populate configuration from file or environment.
UseSlogLogger configure fx to use slog.Default logger.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

nolint:staticcheck.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
Named indicate that this service has a name (which may not unique between services).
No description provided by the author