mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-05 07:56:52 +08:00
Created commands and config packages in pkg folder for easy import
This commit is contained in:
40
cmd/main.go
40
cmd/main.go
@@ -17,17 +17,11 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"github.com/echovault/echovault/internal"
|
||||
"github.com/echovault/echovault/pkg/commands"
|
||||
"github.com/echovault/echovault/pkg/config"
|
||||
"github.com/echovault/echovault/pkg/echovault"
|
||||
"github.com/echovault/echovault/pkg/modules/acl"
|
||||
"github.com/echovault/echovault/pkg/modules/admin"
|
||||
"github.com/echovault/echovault/pkg/modules/connection"
|
||||
"github.com/echovault/echovault/pkg/modules/generic"
|
||||
"github.com/echovault/echovault/pkg/modules/hash"
|
||||
"github.com/echovault/echovault/pkg/modules/list"
|
||||
"github.com/echovault/echovault/pkg/modules/pubsub"
|
||||
"github.com/echovault/echovault/pkg/modules/set"
|
||||
"github.com/echovault/echovault/pkg/modules/sorted_set"
|
||||
str "github.com/echovault/echovault/pkg/modules/string"
|
||||
"github.com/echovault/echovault/pkg/utils"
|
||||
"log"
|
||||
"os"
|
||||
@@ -35,36 +29,20 @@ import (
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func GetCommands() []utils.Command {
|
||||
var commands []utils.Command
|
||||
commands = append(commands, acl.Commands()...)
|
||||
commands = append(commands, admin.Commands()...)
|
||||
commands = append(commands, generic.Commands()...)
|
||||
commands = append(commands, hash.Commands()...)
|
||||
commands = append(commands, list.Commands()...)
|
||||
commands = append(commands, connection.Commands()...)
|
||||
commands = append(commands, pubsub.Commands()...)
|
||||
commands = append(commands, set.Commands()...)
|
||||
commands = append(commands, sorted_set.Commands()...)
|
||||
commands = append(commands, str.Commands()...)
|
||||
return commands
|
||||
}
|
||||
|
||||
func main() {
|
||||
config, err := internal.GetConfig()
|
||||
|
||||
conf, err := config.Config()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.Background(), utils.ContextServerID("ServerID"), config.ServerID)
|
||||
ctx := context.WithValue(context.Background(), utils.ContextServerID("ServerID"), conf.ServerID)
|
||||
|
||||
// Default BindAddr if it's not specified
|
||||
if config.BindAddr == "" {
|
||||
if conf.BindAddr == "" {
|
||||
if addr, err := internal.GetIPAddress(); err != nil {
|
||||
log.Fatal(err)
|
||||
} else {
|
||||
config.BindAddr = addr
|
||||
conf.BindAddr = addr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +51,10 @@ func main() {
|
||||
|
||||
server := echovault.NewEchoVault(
|
||||
echovault.WithContext(ctx),
|
||||
echovault.WithConfig(config),
|
||||
echovault.WithACL(acl.NewACL(config)),
|
||||
echovault.WithConfig(conf),
|
||||
echovault.WithCommands(commands.All()),
|
||||
echovault.WithACL(acl.NewACL(conf)),
|
||||
echovault.WithPubSub(pubsub.NewPubSub()),
|
||||
echovault.WithCommands(GetCommands()),
|
||||
)
|
||||
|
||||
go server.Start(ctx)
|
||||
|
File diff suppressed because it is too large
Load Diff
59
pkg/commands/commands.go
Normal file
59
pkg/commands/commands.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/echovault/echovault/pkg/modules/acl"
|
||||
"github.com/echovault/echovault/pkg/modules/admin"
|
||||
"github.com/echovault/echovault/pkg/modules/connection"
|
||||
"github.com/echovault/echovault/pkg/modules/generic"
|
||||
"github.com/echovault/echovault/pkg/modules/hash"
|
||||
"github.com/echovault/echovault/pkg/modules/list"
|
||||
"github.com/echovault/echovault/pkg/modules/pubsub"
|
||||
"github.com/echovault/echovault/pkg/modules/set"
|
||||
"github.com/echovault/echovault/pkg/modules/sorted_set"
|
||||
str "github.com/echovault/echovault/pkg/modules/string"
|
||||
"github.com/echovault/echovault/pkg/utils"
|
||||
)
|
||||
|
||||
// All returns all the commands currently available on EchoVault
|
||||
func All() []utils.Command {
|
||||
var commands []utils.Command
|
||||
commands = append(commands, acl.Commands()...)
|
||||
commands = append(commands, admin.Commands()...)
|
||||
commands = append(commands, generic.Commands()...)
|
||||
commands = append(commands, hash.Commands()...)
|
||||
commands = append(commands, list.Commands()...)
|
||||
commands = append(commands, connection.Commands()...)
|
||||
commands = append(commands, pubsub.Commands()...)
|
||||
commands = append(commands, set.Commands()...)
|
||||
commands = append(commands, sorted_set.Commands()...)
|
||||
commands = append(commands, str.Commands()...)
|
||||
return commands
|
||||
}
|
||||
|
||||
// ByCategory only returns commands with at least one of the categories in the categories parameter
|
||||
func ByCategory(categories []string) []utils.Command {
|
||||
commands := All()
|
||||
// TODO: Filter commands and subcommands by category
|
||||
return commands
|
||||
}
|
||||
|
||||
// ByModule only returns commands that belong to one of the modules in the modules parameter
|
||||
func ByModule(modules []string) []utils.Command {
|
||||
commands := All()
|
||||
// TODO: Filter commands by module
|
||||
return commands
|
||||
}
|
||||
|
||||
// ExcludeCategories returns all commands except ones that have a category contained in the categories parameter.
|
||||
func ExcludeCategories(categories []string) []utils.Command {
|
||||
commands := All()
|
||||
// TODO: Filter out commands and subcommands in the specified categories
|
||||
return commands
|
||||
}
|
||||
|
||||
// ExcludeModules returns all commands except ones in a module included in the modules parameter
|
||||
func ExcludeModules(modules []string) []utils.Command {
|
||||
commands := All()
|
||||
// TODO: Filter out commands in the specified modules
|
||||
return commands
|
||||
}
|
8
pkg/config/config.go
Normal file
8
pkg/config/config.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package config
|
||||
|
||||
import "github.com/echovault/echovault/internal"
|
||||
|
||||
// Config returns the default configuration.
|
||||
func Config() (internal.Config, error) {
|
||||
return internal.GetConfig()
|
||||
}
|
Reference in New Issue
Block a user