mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
added member provider.
This commit is contained in:
parent
594404824f
commit
7c79b48750
@ -21,6 +21,7 @@ func init() {
|
||||
neko.Service.Configs.Desktop,
|
||||
neko.Service.Configs.Capture,
|
||||
neko.Service.Configs.WebRTC,
|
||||
neko.Service.Configs.Member,
|
||||
neko.Service.Configs.Session,
|
||||
neko.Service.Configs.Server,
|
||||
}, modules.Configs()...)
|
||||
|
44
internal/config/member.go
Normal file
44
internal/config/member.go
Normal file
@ -0,0 +1,44 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type Member struct {
|
||||
Provider string
|
||||
FilePath string
|
||||
Password string
|
||||
AdminPassword string
|
||||
}
|
||||
|
||||
func (Member) Init(cmd *cobra.Command) error {
|
||||
cmd.PersistentFlags().String("members_provider", "file", "choose members provider")
|
||||
if err := viper.BindPFlag("members_provider", cmd.PersistentFlags().Lookup("members_provider")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().String("members_file_path", "/home/neko/members.json", "mebmer file provider path")
|
||||
if err := viper.BindPFlag("members_file_path", cmd.PersistentFlags().Lookup("members_file_path")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().String("password", "neko", "password for connecting to stream")
|
||||
if err := viper.BindPFlag("password", cmd.PersistentFlags().Lookup("password")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cmd.PersistentFlags().String("password_admin", "admin", "admin password for connecting to stream")
|
||||
if err := viper.BindPFlag("password_admin", cmd.PersistentFlags().Lookup("password_admin")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Member) Set() {
|
||||
s.Provider = viper.GetString("members_provider")
|
||||
s.FilePath = viper.GetString("members_file_path")
|
||||
s.Password = viper.GetString("password")
|
||||
s.AdminPassword = viper.GetString("password_admin")
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package dummy
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New() types.MembersDatabase {
|
||||
return &MembersDatabaseCtx{}
|
||||
}
|
||||
|
||||
type MembersDatabaseCtx struct{}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Disconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Insert(id string, profile types.MemberProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Update(id string, profile types.MemberProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Delete(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Select() (map[string]types.MemberProfile, error) {
|
||||
return map[string]types.MemberProfile{}, nil
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/config"
|
||||
"demodesk/neko/internal/session/database/dummy"
|
||||
"demodesk/neko/internal/session/database/file"
|
||||
"demodesk/neko/internal/session/database/object"
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New(config *config.Session) types.MembersDatabase {
|
||||
switch config.DatabaseAdapter {
|
||||
case "file":
|
||||
return file.New(config.FilePath)
|
||||
case "object":
|
||||
return object.New()
|
||||
case "dummy":
|
||||
return dummy.New()
|
||||
}
|
||||
|
||||
return dummy.New()
|
||||
}
|
35
internal/member/dummy/adapter.go
Normal file
35
internal/member/dummy/adapter.go
Normal file
@ -0,0 +1,35 @@
|
||||
package dummy
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New() types.MemberManager {
|
||||
return &MemberManagerCtx{}
|
||||
}
|
||||
|
||||
type MemberManagerCtx struct{}
|
||||
|
||||
func (manager *MemberManagerCtx) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Disconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Insert(id string, profile types.MemberProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Update(id string, profile types.MemberProfile) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Delete(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MemberManagerCtx) Select() (map[string]types.MemberProfile, error) {
|
||||
return map[string]types.MemberProfile{}, nil
|
||||
}
|
@ -10,27 +10,27 @@ import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New(file string) types.MembersDatabase {
|
||||
return &MembersDatabaseCtx{
|
||||
func New(file string) types.MemberManager {
|
||||
return &MemberManagerCtx{
|
||||
file: file,
|
||||
mu: sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
type MembersDatabaseCtx struct {
|
||||
type MemberManagerCtx struct {
|
||||
file string
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Connect() error {
|
||||
func (manager *MemberManagerCtx) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Disconnect() error {
|
||||
func (manager *MemberManagerCtx) Disconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Insert(id string, profile types.MemberProfile) error {
|
||||
func (manager *MemberManagerCtx) Insert(id string, profile types.MemberProfile) error {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -49,7 +49,7 @@ func (manager *MembersDatabaseCtx) Insert(id string, profile types.MemberProfile
|
||||
return manager.serialize(profiles)
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Update(id string, profile types.MemberProfile) error {
|
||||
func (manager *MemberManagerCtx) Update(id string, profile types.MemberProfile) error {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -68,7 +68,7 @@ func (manager *MembersDatabaseCtx) Update(id string, profile types.MemberProfile
|
||||
return manager.serialize(profiles)
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Delete(id string) error {
|
||||
func (manager *MemberManagerCtx) Delete(id string) error {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -87,7 +87,7 @@ func (manager *MembersDatabaseCtx) Delete(id string) error {
|
||||
return manager.serialize(profiles)
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Select() (map[string]types.MemberProfile, error) {
|
||||
func (manager *MemberManagerCtx) Select() (map[string]types.MemberProfile, error) {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -95,7 +95,7 @@ func (manager *MembersDatabaseCtx) Select() (map[string]types.MemberProfile, err
|
||||
return profiles, err
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) deserialize() (map[string]types.MemberProfile, error) {
|
||||
func (manager *MemberManagerCtx) deserialize() (map[string]types.MemberProfile, error) {
|
||||
file, err := os.OpenFile(manager.file, os.O_RDONLY|os.O_CREATE, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -118,7 +118,7 @@ func (manager *MembersDatabaseCtx) deserialize() (map[string]types.MemberProfile
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) serialize(data map[string]types.MemberProfile) error {
|
||||
func (manager *MemberManagerCtx) serialize(data map[string]types.MemberProfile) error {
|
||||
raw, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
22
internal/member/manager.go
Normal file
22
internal/member/manager.go
Normal file
@ -0,0 +1,22 @@
|
||||
package member
|
||||
|
||||
import (
|
||||
"demodesk/neko/internal/config"
|
||||
"demodesk/neko/internal/member/dummy"
|
||||
"demodesk/neko/internal/member/file"
|
||||
"demodesk/neko/internal/member/object"
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New(config *config.Member) types.MemberManager {
|
||||
switch config.Provider {
|
||||
case "file":
|
||||
return file.New(config.FilePath)
|
||||
case "object":
|
||||
return object.New()
|
||||
case "dummy":
|
||||
return dummy.New()
|
||||
}
|
||||
|
||||
return dummy.New()
|
||||
}
|
@ -7,27 +7,27 @@ import (
|
||||
"demodesk/neko/internal/types"
|
||||
)
|
||||
|
||||
func New() types.MembersDatabase {
|
||||
return &MembersDatabaseCtx{
|
||||
func New() types.MemberManager {
|
||||
return &MemberManagerCtx{
|
||||
profiles: make(map[string]types.MemberProfile),
|
||||
mu: sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
type MembersDatabaseCtx struct {
|
||||
type MemberManagerCtx struct {
|
||||
profiles map[string]types.MemberProfile
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Connect() error {
|
||||
func (manager *MemberManagerCtx) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Disconnect() error {
|
||||
func (manager *MemberManagerCtx) Disconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Insert(id string, profile types.MemberProfile) error {
|
||||
func (manager *MemberManagerCtx) Insert(id string, profile types.MemberProfile) error {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -40,7 +40,7 @@ func (manager *MembersDatabaseCtx) Insert(id string, profile types.MemberProfile
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Update(id string, profile types.MemberProfile) error {
|
||||
func (manager *MemberManagerCtx) Update(id string, profile types.MemberProfile) error {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -53,7 +53,7 @@ func (manager *MembersDatabaseCtx) Update(id string, profile types.MemberProfile
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Delete(id string) error {
|
||||
func (manager *MemberManagerCtx) Delete(id string) error {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
||||
@ -66,7 +66,7 @@ func (manager *MembersDatabaseCtx) Delete(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (manager *MembersDatabaseCtx) Select() (map[string]types.MemberProfile, error) {
|
||||
func (manager *MemberManagerCtx) Select() (map[string]types.MemberProfile, error) {
|
||||
manager.mu.Lock()
|
||||
defer manager.mu.Unlock()
|
||||
|
@ -1,6 +1,6 @@
|
||||
package types
|
||||
|
||||
type MembersDatabase interface {
|
||||
type MemberManager interface {
|
||||
Connect() error
|
||||
Disconnect() error
|
||||
|
||||
|
18
neko.go
18
neko.go
@ -11,7 +11,9 @@ import (
|
||||
"demodesk/neko/internal/config"
|
||||
"demodesk/neko/internal/desktop"
|
||||
"demodesk/neko/internal/http"
|
||||
"demodesk/neko/internal/member"
|
||||
"demodesk/neko/internal/session"
|
||||
"demodesk/neko/internal/types"
|
||||
"demodesk/neko/internal/webrtc"
|
||||
"demodesk/neko/internal/websocket"
|
||||
"demodesk/neko/modules"
|
||||
@ -66,6 +68,7 @@ func init() {
|
||||
Desktop: &config.Desktop{},
|
||||
Capture: &config.Capture{},
|
||||
WebRTC: &config.WebRTC{},
|
||||
Member: &config.Member{},
|
||||
Session: &config.Session{},
|
||||
Server: &config.Server{},
|
||||
},
|
||||
@ -106,6 +109,7 @@ type Configs struct {
|
||||
Desktop *config.Desktop
|
||||
Capture *config.Capture
|
||||
WebRTC *config.WebRTC
|
||||
Member *config.Member
|
||||
Session *config.Session
|
||||
Server *config.Server
|
||||
}
|
||||
@ -118,6 +122,7 @@ type Neko struct {
|
||||
desktopManager *desktop.DesktopManagerCtx
|
||||
captureManager *capture.CaptureManagerCtx
|
||||
webRTCManager *webrtc.WebRTCManagerCtx
|
||||
memberManager types.MemberManager
|
||||
sessionManager *session.SessionManagerCtx
|
||||
webSocketManager *websocket.WebSocketManagerCtx
|
||||
apiManager *api.ApiManagerCtx
|
||||
@ -129,6 +134,13 @@ func (neko *Neko) Preflight() {
|
||||
}
|
||||
|
||||
func (neko *Neko) Start() {
|
||||
neko.memberManager = member.New(
|
||||
neko.Configs.Member,
|
||||
)
|
||||
if err := neko.memberManager.Connect(); err != nil {
|
||||
neko.logger.Panic().Err(err).Msg("unable to connect to member manager")
|
||||
}
|
||||
|
||||
neko.sessionManager = session.New(
|
||||
neko.Configs.Session,
|
||||
)
|
||||
@ -181,6 +193,12 @@ func (neko *Neko) Start() {
|
||||
}
|
||||
|
||||
func (neko *Neko) Shutdown() {
|
||||
if err := neko.memberManager.Disconnect(); err != nil {
|
||||
neko.logger.Err(err).Msg("member manager disconnect with an error")
|
||||
} else {
|
||||
neko.logger.Debug().Msg("member manager disconnect")
|
||||
}
|
||||
|
||||
if err := neko.desktopManager.Shutdown(); err != nil {
|
||||
neko.logger.Err(err).Msg("desktop manager shutdown with an error")
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user