8bd45193b0
- Create main application logic with HTTP handlers for form submissions - Implement Pushover API integration for sending messages - Add unit tests for handlers and Pushover payload structure - Include Dockerfile and docker-compose configuration for easy deployment - Add example environment file and update README with setup instructions - Create HTML templates for user interface
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
// Load .env file if it exists (not required, only for local development)
|
|
_ = godotenv.Load()
|
|
|
|
// Load environment variables
|
|
pushoverAPIToken := os.Getenv("PUSHOVER_API_TOKEN")
|
|
pushoverUserKey := os.Getenv("PUSHOVER_USER_KEY")
|
|
csrfKey := os.Getenv("CSRF_KEY")
|
|
|
|
if csrfKey == "" {
|
|
// Generate a random key if not provided (not recommended for production)
|
|
csrfKey = "dev-key-change-in-production"
|
|
}
|
|
|
|
// Set up paths relative to binary location
|
|
exePath, err := os.Executable()
|
|
if err != nil {
|
|
log.Fatalf("Failed to get executable path: %v", err)
|
|
}
|
|
baseDir := filepath.Dir(exePath)
|
|
|
|
// Create router
|
|
router := http.NewServeMux()
|
|
|
|
// Register handlers
|
|
router.HandleFunc("GET /", handleIndex(baseDir))
|
|
router.HandleFunc("POST /", handleSend(baseDir, pushoverAPIToken, pushoverUserKey))
|
|
|
|
// Serve static files
|
|
staticDir := filepath.Join(baseDir, "static")
|
|
fs := http.FileServer(http.Dir(staticDir))
|
|
router.Handle("GET /static/", http.StripPrefix("/static/", fs))
|
|
|
|
// Start server
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "5000"
|
|
}
|
|
|
|
addr := fmt.Sprintf(":%s", port)
|
|
log.Printf("Starting server on %s", addr)
|
|
log.Fatal(http.ListenAndServe(addr, router))
|
|
}
|