A deployable markdown editor that connects with your self hosted files and lets you edit in a beautiful interface

Initialize Go backend project structure

- Create backend directory structure with organized internal packages
- Add main.go with basic HTTP server and graceful shutdown
- Configure Go modules and add godotenv dependency
- Create Makefile with common development tasks
- Add .env.example with all configuration options
- Add .gitignore for backend artifacts
- Build test successful

+171
+25
backend/.env.example
··· 1 + # Server Configuration 2 + PORT=8080 3 + FRONTEND_URL=http://localhost:4321 4 + ALLOWED_ORIGINS=http://localhost:4321 5 + 6 + # GitHub OAuth 7 + GITHUB_CLIENT_ID=your_github_client_id 8 + GITHUB_CLIENT_SECRET=your_github_client_secret 9 + GITHUB_REDIRECT_URL=http://localhost:8080/api/auth/github/callback 10 + 11 + # Session 12 + SESSION_SECRET=your-random-session-secret-min-32-chars-change-this-in-production 13 + SESSION_SECURE=false 14 + SESSION_MAX_AGE=86400 15 + 16 + # Database 17 + DATABASE_PATH=./data/markedit.db 18 + 19 + # Git Configuration 20 + GIT_CACHE_DIR=./data/repos 21 + GIT_AUTHOR_NAME=MarkEdit 22 + GIT_AUTHOR_EMAIL=markedit@example.com 23 + 24 + # Logging 25 + LOG_LEVEL=debug
+37
backend/.gitignore
··· 1 + # Binaries 2 + bin/ 3 + *.exe 4 + *.dll 5 + *.so 6 + *.dylib 7 + 8 + # Test binary, built with `go test -c` 9 + *.test 10 + 11 + # Output of the go coverage tool 12 + *.out 13 + 14 + # Environment variables 15 + .env 16 + 17 + # Database files 18 + *.db 19 + *.db-shm 20 + *.db-wal 21 + 22 + # Data directory 23 + data/ 24 + 25 + # Go workspace file 26 + go.work 27 + 28 + # IDE 29 + .vscode/ 30 + .idea/ 31 + *.swp 32 + *.swo 33 + *~ 34 + 35 + # OS files 36 + .DS_Store 37 + Thumbs.db
+34
backend/Makefile
··· 1 + .PHONY: run build test clean migrate-up migrate-down 2 + 3 + # Run the server 4 + run: 5 + go run cmd/server/main.go 6 + 7 + # Build the binary 8 + build: 9 + go build -o bin/markedit cmd/server/main.go 10 + 11 + # Run tests 12 + test: 13 + go test -v ./... 14 + 15 + # Clean build artifacts 16 + clean: 17 + rm -rf bin/ 18 + 19 + # Run migrations up 20 + migrate-up: 21 + @echo "Migrations will be implemented later" 22 + 23 + # Run migrations down 24 + migrate-down: 25 + @echo "Migrations will be implemented later" 26 + 27 + # Install dependencies 28 + deps: 29 + go mod download 30 + go mod tidy 31 + 32 + # Development watch mode (requires air) 33 + dev: 34 + air
+68
backend/cmd/server/main.go
··· 1 + package main 2 + 3 + import ( 4 + "context" 5 + "fmt" 6 + "log" 7 + "net/http" 8 + "os" 9 + "os/signal" 10 + "syscall" 11 + "time" 12 + 13 + "github.com/joho/godotenv" 14 + ) 15 + 16 + func main() { 17 + // Load environment variables 18 + if err := godotenv.Load(); err != nil { 19 + log.Println("No .env file found, using environment variables") 20 + } 21 + 22 + // Get port from environment 23 + port := os.Getenv("PORT") 24 + if port == "" { 25 + port = "8080" 26 + } 27 + 28 + // Create HTTP server 29 + srv := &http.Server{ 30 + Addr: ":" + port, 31 + Handler: http.HandlerFunc(healthCheckHandler), 32 + ReadTimeout: 15 * time.Second, 33 + WriteTimeout: 15 * time.Second, 34 + IdleTimeout: 60 * time.Second, 35 + } 36 + 37 + // Start server in a goroutine 38 + go func() { 39 + log.Printf("Starting server on port %s", port) 40 + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { 41 + log.Fatalf("Failed to start server: %v", err) 42 + } 43 + }() 44 + 45 + // Wait for interrupt signal 46 + quit := make(chan os.Signal, 1) 47 + signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) 48 + <-quit 49 + 50 + log.Println("Shutting down server...") 51 + 52 + // Graceful shutdown 53 + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) 54 + defer cancel() 55 + 56 + if err := srv.Shutdown(ctx); err != nil { 57 + log.Fatalf("Server forced to shutdown: %v", err) 58 + } 59 + 60 + log.Println("Server exited") 61 + } 62 + 63 + // Temporary health check handler 64 + func healthCheckHandler(w http.ResponseWriter, r *http.Request) { 65 + w.Header().Set("Content-Type", "application/json") 66 + w.WriteHeader(http.StatusOK) 67 + fmt.Fprintf(w, `{"status":"ok","version":"0.1.0"}`) 68 + }
+5
backend/go.mod
··· 1 + module github.com/yourusername/markedit 2 + 3 + go 1.24.1 4 + 5 + require github.com/joho/godotenv v1.5.1
+2
backend/go.sum
··· 1 + github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= 2 + github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=