initial commit
This commit is contained in:
24
backend/cmd/config.go
Normal file
24
backend/cmd/config.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
type cliParams struct {
|
||||
ListenAddr string
|
||||
ListenPort int
|
||||
DataDir string
|
||||
SettingsFile string
|
||||
}
|
||||
|
||||
func (p *cliParams) Validate() error {
|
||||
// Ensure Generated Directories
|
||||
imgDir := path.Join(p.DataDir, "generated/images")
|
||||
if err := os.MkdirAll(imgDir, 0755); err != nil {
|
||||
return fmt.Errorf("failed to create images directory: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
50
backend/cmd/main.go
Normal file
50
backend/cmd/main.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"reichard.io/aethera/internal/server"
|
||||
"reichard.io/aethera/internal/store"
|
||||
)
|
||||
|
||||
var (
|
||||
params = cliParams{
|
||||
ListenAddr: "localhost",
|
||||
ListenPort: 8080,
|
||||
DataDir: "./data",
|
||||
}
|
||||
rootCmd = &cobra.Command{Use: "aethera"}
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().StringVar(¶ms.DataDir, "data-dir", "data", "Directory to store generated images")
|
||||
rootCmd.PersistentFlags().StringVar(¶ms.ListenAddr, "listen", "localhost", "Address to listen on")
|
||||
rootCmd.PersistentFlags().IntVar(¶ms.ListenPort, "port", 8080, "Port to listen on")
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Validate Params
|
||||
if err := params.Validate(); err != nil {
|
||||
logrus.Fatalf("failed to validate parameters: %v", err)
|
||||
}
|
||||
|
||||
// Initialize Store
|
||||
fileStore, err := store.NewFileStore(path.Join(params.DataDir, "settings.json"))
|
||||
if err != nil {
|
||||
logrus.Fatalf("failed to create store: %v", err)
|
||||
}
|
||||
|
||||
// Start Server
|
||||
rootCmd.Run = func(cmd *cobra.Command, args []string) {
|
||||
server.StartServer(fileStore, params.DataDir, params.ListenAddr, params.ListenPort)
|
||||
}
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
logrus.Fatal(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user