Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AuthModule = fx.Provide( func( l *zap.Logger, ) (out sfx.AuthMiddlewareResult, err error) { out.AuthMiddleware = &Author{ unAuthMethods: make(map[string]struct{}), } 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 }
or disable it for a method, add the method name by `AddUnAuthMethod`
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 {
// contains filtered or unexported fields
}
Author is a demo auth service
func (*Author) AddUnAuthMethod ¶ added in v1.0.2
AddUnAuthMethod add you want to disable auth method here
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)
Click to show internal directories.
Click to hide internal directories.