Files
agent-evals/internal/config/config.go
Evan Reichard 702281c6cf feat: implement WYSIWYG markdown editor with Go backend and React frontend
- Backend: Go HTTP server with Cobra CLI (--data-dir, --port, --host flags)
- CRUD REST API for markdown files with JSON error responses
- File storage in flat directory structure (flat structure, .md files only)
- Comprehensive logrus logging for all operations
- Static file serving for frontend build (./frontend/dist)
- Frontend: React + TypeScript + Tailwind CSS
- Markdown editor with live GFM preview
- File management: list, create, open, save, delete
- Theme system (Dark, Light, System) with persistence
- Responsive design for desktop and mobile
- Backend tests (storage, API handlers) and frontend tests
2026-02-06 16:04:34 -05:00

54 lines
1.2 KiB
Go

package config
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
// Config holds the application configuration
type Config struct {
DataDir string
Port int
Host string
}
// NewConfig creates a new config with default values
func NewConfig() *Config {
return &Config{
DataDir: "./data",
Port: 8080,
Host: "127.0.0.1",
}
}
// AddFlags adds the CLI flags to the command
func (c *Config) AddFlags(cmd *cobra.Command) {
cmd.PersistentFlags().StringVar(&c.DataDir, "data-dir", c.DataDir, "Storage path for markdown files")
cmd.PersistentFlags().IntVar(&c.Port, "port", c.Port, "Server port")
cmd.PersistentFlags().StringVar(&c.Host, "host", c.Host, "Bind address")
}
// Validate validates the configuration
func (c *Config) Validate() error {
if c.Port < 1 || c.Port > 65535 {
return fmt.Errorf("invalid port: %d", c.Port)
}
return nil
}
// DataDirPath returns the absolute path to the data directory
func (c *Config) DataDirPath() string {
absPath, err := filepath.Abs(c.DataDir)
if err != nil {
return c.DataDir
}
return absPath
}
// EnsureDataDir ensures the data directory exists
func (c *Config) EnsureDataDir() error {
return os.MkdirAll(c.DataDirPath(), 0755)
}