mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
member providers extracted config.
This commit is contained in:
parent
fceae3818b
commit
00586baffc
@ -10,23 +10,18 @@ import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New(file string) types.MemberManager {
|
||||
func New(config Config) types.MemberManager {
|
||||
return &MemberManagerCtx{
|
||||
file: file,
|
||||
config: config,
|
||||
mu: sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
type MemberManagerCtx struct {
|
||||
file string
|
||||
config Config
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
type MemberEntry struct {
|
||||
Password string `json:"password"`
|
||||
Profile types.MemberProfile `json:"profile"`
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Connect() error {
|
||||
return nil
|
||||
}
|
||||
@ -177,7 +172,7 @@ func (manager *MemberManagerCtx) Delete(id string) error {
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) deserialize() (map[string]MemberEntry, error) {
|
||||
file, err := os.OpenFile(manager.file, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
||||
file, err := os.OpenFile(manager.config.File, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -219,5 +214,5 @@ func (manager *MemberManagerCtx) serialize(data map[string]MemberEntry) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ioutil.WriteFile(manager.file, raw, os.ModePerm)
|
||||
return ioutil.WriteFile(manager.config.File, raw, os.ModePerm)
|
||||
}
|
||||
|
14
internal/member/file/types.go
Normal file
14
internal/member/file/types.go
Normal file
@ -0,0 +1,14 @@
|
||||
package file
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type MemberEntry struct {
|
||||
Password string `json:"password"`
|
||||
Profile types.MemberProfile `json:"profile"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
File string
|
||||
}
|
@ -11,9 +11,14 @@ import (
|
||||
func New(config *config.Member) types.MemberManager {
|
||||
switch config.Provider {
|
||||
case "file":
|
||||
return file.New(config.FilePath)
|
||||
return file.New(file.Config{
|
||||
File: config.FilePath,
|
||||
})
|
||||
case "object":
|
||||
return object.New()
|
||||
return object.New(object.Config{
|
||||
AdminPassword: config.AdminPassword,
|
||||
UserPassword: config.Password,
|
||||
})
|
||||
case "dummy":
|
||||
return dummy.New()
|
||||
}
|
||||
|
@ -7,23 +7,20 @@ import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New() types.MemberManager {
|
||||
func New(config Config) types.MemberManager {
|
||||
return &MemberManagerCtx{
|
||||
config: config,
|
||||
entries: make(map[string]MemberEntry),
|
||||
mu: sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
type MemberManagerCtx struct {
|
||||
config Config
|
||||
entries map[string]MemberEntry
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
type MemberEntry struct {
|
||||
Password string `json:"password"`
|
||||
Profile types.MemberProfile `json:"profile"`
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
15
internal/member/object/types.go
Normal file
15
internal/member/object/types.go
Normal file
@ -0,0 +1,15 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
type MemberEntry struct {
|
||||
Password string `json:"password"`
|
||||
Profile types.MemberProfile `json:"profile"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
AdminPassword string
|
||||
UserPassword string
|
||||
}
|
Loading…
Reference in New Issue
Block a user