add default provider
This commit is contained in:
@@ -29,6 +29,10 @@ type ProviderContainer struct {
|
|||||||
|
|
||||||
type Providers []ProviderContainer
|
type Providers []ProviderContainer
|
||||||
|
|
||||||
|
func (p Providers) With(pcs Providers) Providers {
|
||||||
|
return append(p, pcs...)
|
||||||
|
}
|
||||||
|
|
||||||
func (p Providers) Provide(config *viper.Viper) error {
|
func (p Providers) Provide(config *viper.Viper) error {
|
||||||
for _, provider := range p {
|
for _, provider := range p {
|
||||||
provider.Options = append(provider.Options, opt.Config(config))
|
provider.Options = append(provider.Options, opt.Config(config))
|
||||||
|
|||||||
14
defautl_http.go
Normal file
14
defautl_http.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package atom
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/providers/http/gin"
|
||||||
|
"github.com/rogeecn/atom/providers/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func DefaultHTTP(providers ...container.ProviderContainer) container.Providers {
|
||||||
|
return append(container.Providers{
|
||||||
|
log.DefaultProvider(),
|
||||||
|
gin.DefaultProvider(),
|
||||||
|
}, providers...)
|
||||||
|
}
|
||||||
@@ -3,10 +3,22 @@ package captcha
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/utils/opt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPrefix = "Captcha"
|
const DefaultPrefix = "Captcha"
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Long uint // 验证码长度
|
Long uint // 验证码长度
|
||||||
Width uint // 验证码宽度
|
Width uint // 验证码宽度
|
||||||
|
|||||||
@@ -2,10 +2,22 @@ package mysql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/utils/opt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPrefix = "MySQL"
|
const DefaultPrefix = "MySQL"
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MySQL database config
|
// MySQL database config
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Host string
|
Host string
|
||||||
|
|||||||
@@ -2,10 +2,22 @@ package postgres
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/utils/opt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPrefix = "Postgres"
|
const DefaultPrefix = "Postgres"
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
package sqlite
|
package sqlite
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/utils/opt"
|
||||||
|
)
|
||||||
|
|
||||||
const DefaultPrefix = "SQLite"
|
const DefaultPrefix = "SQLite"
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
File string
|
File string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,13 @@ import (
|
|||||||
"github.com/brianvoe/gofakeit/v6"
|
"github.com/brianvoe/gofakeit/v6"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Provide(opts ...opt.Option) error {
|
func Provide(opts ...opt.Option) error {
|
||||||
o := opt.New(opts...)
|
o := opt.New(opts...)
|
||||||
return container.Container.Provide(func() (*gofakeit.Faker, error) {
|
return container.Container.Provide(func() (*gofakeit.Faker, error) {
|
||||||
|
|||||||
@@ -12,6 +12,15 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(http.DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
conf *http.Config
|
conf *http.Config
|
||||||
Engine *gin.Engine
|
Engine *gin.Engine
|
||||||
|
|||||||
@@ -3,11 +3,23 @@ package jwt
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/providers/http"
|
||||||
"github.com/rogeecn/atom/providers/log"
|
"github.com/rogeecn/atom/providers/log"
|
||||||
|
"github.com/rogeecn/atom/utils/opt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultPrefix = "JWT"
|
const DefaultPrefix = "JWT"
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(http.DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
SigningKey string // jwt签名
|
SigningKey string // jwt签名
|
||||||
ExpiresTime string // 过期时间
|
ExpiresTime string // 过期时间
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/rogeecn/atom/container"
|
||||||
|
"github.com/rogeecn/atom/utils/opt"
|
||||||
|
)
|
||||||
|
|
||||||
const DefaultPrefix = "Log"
|
const DefaultPrefix = "Log"
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{
|
||||||
|
opt.Prefix(DefaultPrefix),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Level Level
|
Level Level
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,13 @@ import (
|
|||||||
"golang.org/x/sync/singleflight"
|
"golang.org/x/sync/singleflight"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Provide(opts ...opt.Option) error {
|
func Provide(opts ...opt.Option) error {
|
||||||
o := opt.New(opts...)
|
o := opt.New(opts...)
|
||||||
return container.Container.Provide(func() (*singleflight.Group, error) {
|
return container.Container.Provide(func() (*singleflight.Group, error) {
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ import (
|
|||||||
"github.com/gofrs/uuid"
|
"github.com/gofrs/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func DefaultProvider() container.ProviderContainer {
|
||||||
|
return container.ProviderContainer{
|
||||||
|
Provider: Provide,
|
||||||
|
Options: []opt.Option{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Generator struct {
|
type Generator struct {
|
||||||
generator uuid.Generator
|
generator uuid.Generator
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user