feat: wechat provider
This commit is contained in:
43
backend/providers/wechat/provider.go
Normal file
43
backend/providers/wechat/provider.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package wechat
|
||||
|
||||
import (
|
||||
"git.ipao.vip/rogeecn/atom/container"
|
||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||
)
|
||||
|
||||
func DefaultProvider() container.ProviderContainer {
|
||||
return container.ProviderContainer{
|
||||
Provider: Provide,
|
||||
Options: []opt.Option{},
|
||||
}
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
AppID string
|
||||
AppSecret string
|
||||
Token string
|
||||
AesKey string
|
||||
DevMode bool
|
||||
}
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
o := opt.New(opts...)
|
||||
var config Config
|
||||
if err := o.UnmarshalConfig(&config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return container.Container.Provide(func() (*Client, error) {
|
||||
httpClient := DefaultClient
|
||||
if config.DevMode {
|
||||
httpClient = httpClient.DevMode()
|
||||
}
|
||||
return New(
|
||||
WithAppID(config.AppID),
|
||||
WithAppSecret(config.AppSecret),
|
||||
WithAESKey(config.AesKey),
|
||||
WithToken(config.Token),
|
||||
WithClient(httpClient),
|
||||
), nil
|
||||
}, o.DiOptions()...)
|
||||
}
|
||||
Reference in New Issue
Block a user