Files
Mediarr/node/node.go
T

57 lines
952 B
Go

package node
import (
"mediarr/cluster"
"mediarr/database"
"mediarr/user"
)
type Node struct {
db database.DatabaseClient
clusterKeyPath string
cluster cluster.Identity
}
type NewNodeParams struct {
DatabaseName string
ClusterKeyPath string
}
func NewNode(params NewNodeParams) (error, Node) {
var databaseName *string
if params.DatabaseName != "" {
databaseName = &params.DatabaseName
}
err, db := database.NewDatabase(database.NewDatabaseParams{
DatabaseName: databaseName,
})
if err != nil {
return err, Node{}
}
clusterKeyPath := params.ClusterKeyPath
if clusterKeyPath == "" {
clusterKeyPath = "cluster.key"
}
return nil, Node{
db: *db,
clusterKeyPath: clusterKeyPath,
}
}
func (n *Node) Close() error {
return n.db.Close()
}
func (n *Node) ClusterIdentity() cluster.Identity {
return n.cluster
}
func (n *Node) Users() *user.Service {
return user.NewService(n.db)
}