-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
62 lines (50 loc) Β· 1.5 KB
/
Copy pathmain.go
File metadata and controls
62 lines (50 loc) Β· 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"html/template"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/joho/godotenv"
)
func main() {
// Load environment variables
err := godotenv.Load()
if err != nil {
log.Println("Warning: .env file not found, using system environment variables")
}
// Initialize clients
pineconeAPI := NewPineconeClient(
os.Getenv("PINECONE_API_KEY"),
os.Getenv("PINECONE_V2_HOST"),
os.Getenv("PINECONE_V2_INDEX"),
)
voyageAPI := NewVoyageClient(os.Getenv("VOYAGE_API_KEY"))
// Load templates
templates := template.Must(template.ParseGlob("templates/*.html"))
app := &App{
templates: templates,
pineconeAPI: pineconeAPI,
voyageAPI: voyageAPI,
rssCache: make(map[string]RSSCacheItem),
}
// Setup routes
r := mux.NewRouter()
// Static files
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
// Routes
r.HandleFunc("/", app.handleHome).Methods("GET")
r.HandleFunc("/search", app.handleSearch).Methods("GET")
r.HandleFunc("/api/search", app.handleAPISearch).Methods("GET", "POST")
r.HandleFunc("/api/export/opml", app.handleOPMLExport).Methods("GET", "POST")
r.HandleFunc("/api/export/csv", app.handleCSVExport).Methods("GET", "POST")
r.HandleFunc("/rss", app.handleRSSFeed).Methods("GET")
// Start server
port := "8000"
if p := os.Getenv("PORT"); p != "" {
port = p
}
fmt.Printf("π€ BlogNerd server starting on http://localhost:%s\n", port)
log.Fatal(http.ListenAndServe(":"+port, r))
}