Skip to content

Commit aeab59c

Browse files
author
novnc
committed
refactor: update README and improve filesystem store initialization
1 parent 7dba7f1 commit aeab59c

File tree

3 files changed

+23
-98
lines changed

3 files changed

+23
-98
lines changed

README.md

Lines changed: 14 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,18 @@ A modern, high-performance HTTP clipboard app written in Go with Gin framework.
1212
## Table of Contents
1313

1414
- [Overview](#overview)
15-
- [Features](#-features)
16-
- [Quick Start](#-quick-start)
17-
- [API Endpoints](#-api-endpoints)
18-
- [Client Usage Examples](#-usage-examples)
19-
- [Storage Architecture](#storage-architecture)
20-
- [Configuration](#-configuration)
21-
- [Deployment](#deployment)
22-
- [Docker](#-docker-deployment)
23-
- [Kubernetes](#kubernetes)
24-
- [AWS Lambda](#-aws-lambda-deployment)
25-
- [Monitoring](#-monitoring)
26-
- [Development](#-development)
27-
- [Contributing](#-contributing)
28-
- [License](#-license)
29-
- [Links](#-links)
15+
- [Features](#✨-features)
16+
- [Quick Start](#🚀-quick-start)
17+
- [API Endpoints](#📋-api-endpoints)
18+
- [Storage Backends](#🗄️-storage-backends)
19+
- [Configuration](#⚙️-configuration)
20+
- [Deployment](#☁️-deployment)
21+
- [Docker](#🐳-docker-deployment)
22+
- [Kubernetes](#☸️-kubernetes-deployment)
23+
- [AWS Lambda](#☁️-aws-lambda-deployment)
24+
- [Monitoring](#📊-monitoring)
25+
- [Development](#🔧-development)
26+
- [Links](#🔗-links)
3027

3128
## Overview
3229

@@ -119,9 +116,7 @@ export NCLIP_TTL=24h
119116
./nclip
120117
```
121118

122-
## � Deployment
123-
124-
nclip supports multiple deployment methods: Docker, Kubernetes, and AWS Lambda. Choose the deployment that best fits your needs.
119+
## ☁️ Deployment
125120

126121
### Quick Start Options
127122

@@ -284,7 +279,7 @@ export NCLIP_PORT=3000
284279
./nclip --url https://demo.nclip.app --ttl 48h
285280
```
286281

287-
## �� Monitoring
282+
## 📊 Monitoring
288283

289284
- **Health Check**: `GET /health` - Returns 200 OK with system status
290285
- **Structured Logging**: JSON format with request tracing
@@ -332,79 +327,6 @@ go run main.go
332327
bash scripts/integration-tests.sh
333328
```
334329

335-
### Project Structure
336-
```
337-
/
338-
├── main.go # Unified entry point (server mode + Lambda)
339-
├── main_test.go # Integration tests
340-
├── config/ # Configuration management
341-
│ ├── config.go # Configuration loading from env vars and CLI flags
342-
│ └── config_test.go # Configuration tests
343-
├── handlers/ # HTTP request handlers
344-
│ ├── paste.go # Main paste upload/retrieval handler
345-
│ ├── paste_test.go # Paste handler tests
346-
│ ├── meta.go # Metadata API handler
347-
│ ├── meta_test.go # Metadata handler tests
348-
│ ├── system.go # System endpoints (health, etc.)
349-
│ ├── system_test.go # System handler tests
350-
│ ├── webui.go # Web UI handler
351-
│ ├── webui_test.go # Web UI tests
352-
│ ├── retrieval/ # Paste retrieval handlers
353-
│ └── upload/ # Paste upload handlers
354-
├── internal/ # Private application code
355-
│ └── services/ # Business logic services
356-
│ └── paste_service.go # Paste business logic
357-
├── models/ # Data models and structures
358-
│ ├── paste.go # Paste data model
359-
│ └── paste_test.go # Paste model tests
360-
├── storage/ # Storage abstraction layer
361-
│ ├── interface.go # PasteStore interface definition
362-
│ ├── interface_test.go # Interface tests
363-
│ ├── filesystem.go # Filesystem storage (server mode)
364-
│ ├── filesystem_test.go # Filesystem storage tests
365-
│ ├── s3.go # S3 storage (Lambda mode)
366-
│ ├── s3_test.go # S3 storage tests
367-
│ ├── s3util.go # S3 utility functions
368-
│ ├── s3util_test.go # S3 utility tests
369-
│ └── storage_test.go # Storage integration tests
370-
├── utils/ # Shared utilities
371-
│ ├── debug.go # Debug logging utilities
372-
│ ├── debug_test.go # Debug utility tests
373-
│ ├── mime.go # MIME type detection
374-
│ ├── mime_test.go # MIME detection tests
375-
│ ├── slug.go # Slug generation utilities
376-
│ └── slug_test.go # Slug generation tests
377-
├── static/ # Static web assets
378-
│ ├── index.html # Main web UI
379-
│ ├── favicon.ico # Favicon
380-
│ ├── style.css # CSS styles
381-
│ ├── script.js # JavaScript functionality
382-
│ └── view.html # Paste view template
383-
├── docs/ # Documentation
384-
│ ├── CLIENTS.md # Client usage examples
385-
│ ├── CONTAINER_CLEANUP.md # Container management
386-
│ ├── INTEGRATION-TESTS.md # Integration testing
387-
│ ├── KUBERNETES.md # Kubernetes deployment
388-
│ └── LAMBDA.md # AWS Lambda deployment
389-
├── k8s/ # Kubernetes manifests
390-
│ ├── deployment.yaml # Deployment configuration
391-
│ ├── service.yaml # Service configuration
392-
│ ├── ingress.yaml # Ingress configuration
393-
│ ├── namespace.yaml # Namespace definition
394-
│ ├── kustomization.yaml # Kustomize configuration
395-
│ └── pvc.yaml # Persistent volume claim
396-
├── scripts/ # Utility scripts
397-
│ └── integration-test.sh # Integration test runner
398-
├── .github/ # GitHub configuration
399-
│ └── workflows/ # GitHub Actions workflows
400-
├── Dockerfile # Docker image definition
401-
├── docker-compose.yml # Docker Compose configuration
402-
├── go.mod # Go module definition
403-
├── go.sum # Go module checksums
404-
├── .golangci.yml # Go linting configuration
405-
└── .gitignore # Git ignore rules
406-
```
407-
408330
## 🔗 Links
409331

410332
- **Documentation**: [docs/](docs/)

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func main() {
9999
if dataDir == "" {
100100
dataDir = "./data"
101101
}
102-
// the storage.NewFilesystemStore responsibility to create the data directory belongs to startup code
103102
store, err = storage.NewFilesystemStore(dataDir)
104103
if err != nil {
105104
log.Fatalf("Failed to initialize filesystem storage: %v", err)

storage/filesystem.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package storage
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"log"
67
"os"
78
"path/filepath"
@@ -19,15 +20,18 @@ type FilesystemStore struct {
1920
}
2021

2122
// NewFilesystemStore creates a FilesystemStore for the given data directory.
22-
// If dataDir is empty it defaults to "./data". The caller may create the
23-
// directory at startup (recommended), and StoreContent remains defensive and
24-
// will attempt to create the directory before writing.
23+
// If dataDir is empty it defaults to "./data". The directory is created if it does not exist.
2524
func NewFilesystemStore(dataDir string) (*FilesystemStore, error) {
2625
if dataDir == "" {
2726
dataDir = "./data"
2827
}
29-
// Constructor is side-effect free: main.go should create the data directory at startup.
30-
// StoreContent remains defensive and will create the directory if needed at write time.
28+
// Check if the dataDir not exists and create it with logging
29+
if _, err := os.Stat(dataDir); os.IsNotExist(err) {
30+
log.Printf("[INFO] Creating data directory: %s", dataDir)
31+
if err := os.MkdirAll(dataDir, 0755); err != nil {
32+
return nil, fmt.Errorf("failed to create data directory %s: %w", dataDir, err)
33+
}
34+
}
3135
return &FilesystemStore{
3236
dataDir: dataDir,
3337
bufferSize: 4096,

0 commit comments

Comments
 (0)