dfx

package
v0.0.0-...-d29eeed Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthModule = fx.Provide(
	func(
		l *zap.Logger,
	) (out sfx.AuthServiceResult, err error) {
		out.AuthService = &Author{}
		return
	},
)

AuthModule is a demo auth module you can implement your own auth service or auth function Auth will check every rpc/http request, if you want to disable it for a service, add `utility.WithoutAuth` in struct of your service

type service struct {
	utility.WithoutAuth
}
View Source
var DemoClientModule = fx.Provide(
	func(
		setting SettingsParams,
		sSetting sfx.SecuritySettingsParams,
		logger *zap.Logger,
	) (out DemoClientResult, err error) {
		if cli, e := NewDemoClient(setting.DemoUrl, logger, sSetting); e != nil {
			err = e
		} else {
			out.DemoClient = cli
		}
		return
	},
)

DemoClientModule you can inject it to other module

View Source
var SettingsModule = fx.Provide(
	func() (out SettingsResult, err error) {
		err = out.LoadFromEnv()
		return
	},
)

SettingsModule config your app settings

View Source
var SqliteDriverModule = fx.Provide(
	func(
		l *zap.Logger,
		s SettingsParams,
	) (out ofx.GormDriverResult, err error) {
		out.Dialector = sqlite.Open(s.GormDns)
		return out, nil
	},
)

SqliteDriverModule you can customize it as gorm support db adapter

Functions

func NewDemoClient

func NewDemoClient(host string, logger *zap.Logger, sSetting sfx.SecuritySettingsParams) (pb2.DemoServiceClient, error)

Types

type Author

type Author struct {
}

Author is a demo auth service

func (*Author) Auth

func (d *Author) Auth(token string) (string, error)

Auth is a demo auth method

type DemoClientParams

type DemoClientParams struct {
	fx.In

	DemoClient pb2.DemoServiceClient `name:"DemoClient"`
}

type DemoClientResult

type DemoClientResult struct {
	fx.Out

	DemoClient pb2.DemoServiceClient `name:"DemoClient"`
}

type SettingsParams

type SettingsParams struct {
	fx.In

	DemoUrl string `name:"DemoUrl"`
	DbName  string `name:"DbName"`
	GormDns string `name:"GormDns"`
}

SettingsParams you can customize it as your need

type SettingsResult

type SettingsResult struct {
	fx.Out

	DemoUrl string `name:"DemoUrl" envconfig:"DEMO_URL" default:"localhost:8081"`
	DbName  string `name:"DbName" envconfig:"DB_NAME" default:"demo"`
	GormDns string `name:"GormDns" envconfig:"GORM_DNS" default:"demo.db"`
}

func (*SettingsResult) LoadFromEnv

func (g *SettingsResult) LoadFromEnv() (err error)

Jump to

Keyboard shortcuts

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