diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ec52baf --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +.PHONY: build run clean + +all: clean build run + +build: + mkdir -p bin + go build -o ./bin/trakr . + +run: + ./bin/trakr + +clean: + go clean + rm -rf bin \ No newline at end of file diff --git a/bin/trakr b/bin/trakr new file mode 100755 index 0000000..1e329d0 Binary files /dev/null and b/bin/trakr differ diff --git a/create.html b/create.html deleted file mode 100644 index 618b247..0000000 --- a/create.html +++ /dev/null @@ -1,17 +0,0 @@ - -
-

Your Tracking Pixel Link

- - -
- - - \ No newline at end of file diff --git a/go.mod b/go.mod index 5a95183..5f184e9 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module trakr +module git.bhasher.com/bhasher/trakr go 1.21.4 diff --git a/main.go b/main.go index 2f2a0fb..f3c36e4 100644 --- a/main.go +++ b/main.go @@ -1,39 +1,9 @@ package main import ( - "fmt" - "log" - "net/http" - - _ "github.com/mattn/go-sqlite3" + "git.bhasher.com/bhasher/trakr/server" ) -var onePixelGIF = []byte{ - 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, - 0x01, 0x00, 0x80, 0xff, 0x00, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, - 0x01, 0x00, 0x3b, -} - func main() { - db = initDB("data.sqlite") - - http.HandleFunc("/new", newPixelPageHandler) - http.HandleFunc("/create-pixel", createPixelHandler) - http.HandleFunc("/p/", pixelHandler) - http.HandleFunc("/dashboard", dashboardHandler) - - addr := ":8080" - - fmt.Printf("Server is up and running on http://localhost%s\n", addr) - - log.Fatal(http.ListenAndServe(addr, nil)) -} - -type PixelStats struct { - Title string - TotalViews int - UniqueViews int - UUID string + server.Server() } diff --git a/dashboard.html b/public/html/dashboard.html similarity index 100% rename from dashboard.html rename to public/html/dashboard.html diff --git a/new.html b/public/html/new.html similarity index 100% rename from new.html rename to public/html/new.html diff --git a/db.go b/server/db.go similarity index 98% rename from db.go rename to server/db.go index 64ced72..2b084ba 100644 --- a/db.go +++ b/server/db.go @@ -1,4 +1,4 @@ -package main +package server import ( "database/sql" diff --git a/handlers.go b/server/handlers.go similarity index 95% rename from handlers.go rename to server/handlers.go index f34eea0..33880ac 100644 --- a/handlers.go +++ b/server/handlers.go @@ -1,4 +1,4 @@ -package main +package server import ( "crypto/sha256" @@ -12,7 +12,7 @@ import ( ) func newPixelPageHandler(w http.ResponseWriter, r *http.Request) { - tmpl, err := template.ParseFiles("new.html") + tmpl, err := template.ParseFiles("public/html/new.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -120,7 +120,7 @@ func dashboardHandler(w http.ResponseWriter, r *http.Request) { } // Render the template - tmpl, err := template.ParseFiles("dashboard.html") + tmpl, err := template.ParseFiles("public/html/dashboard.html") if err != nil { http.Error(w, "Error loading template", http.StatusInternalServerError) return diff --git a/server/server.go b/server/server.go new file mode 100644 index 0000000..8acbd17 --- /dev/null +++ b/server/server.go @@ -0,0 +1,39 @@ +package server + +import ( + "fmt" + "log" + "net/http" + + _ "github.com/mattn/go-sqlite3" +) + +var onePixelGIF = []byte{ + 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, + 0x01, 0x00, 0x80, 0xff, 0x00, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, + 0x01, 0x00, 0x3b, +} + +func Server() { + db = initDB("data.sqlite") + + http.HandleFunc("/new", newPixelPageHandler) + http.HandleFunc("/create-pixel", createPixelHandler) + http.HandleFunc("/p/", pixelHandler) + http.HandleFunc("/dashboard", dashboardHandler) + + addr := ":8080" + + fmt.Printf("Server is up and running on http://localhost%s\n", addr) + + log.Fatal(http.ListenAndServe(addr, nil)) +} + +type PixelStats struct { + Title string + TotalViews int + UniqueViews int + UUID string +}