Reorganise

This commit is contained in:
Brieuc Dubois 2023-12-22 22:05:30 +01:00
parent 0ddeff0c90
commit 12d1cff06a
10 changed files with 60 additions and 54 deletions

14
Makefile Normal file
View File

@ -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

BIN
bin/trakr Executable file

Binary file not shown.

View File

@ -1,17 +0,0 @@
<body>
<div class="container">
<h2>Your Tracking Pixel Link</h2>
<input type="text" id="pixelLink" value="Generated Link Here" readonly>
<button onclick="copyLink()">Copy Link</button>
</div>
<script>
function copyLink() {
var copyText = document.getElementById("pixelLink");
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
document.execCommand("copy");
alert("Copied the link: " + copyText.value);
}
</script>
</body>

2
go.mod
View File

@ -1,4 +1,4 @@
module trakr
module git.bhasher.com/bhasher/trakr
go 1.21.4

34
main.go
View File

@ -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()
}

View File

@ -1,4 +1,4 @@
package main
package server
import (
"database/sql"

View File

@ -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

39
server/server.go Normal file
View File

@ -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
}