From b4556330b65cc56ba5e4f979f2a15c2ee8bcf3b7 Mon Sep 17 00:00:00 2001 From: Erikas Date: Thu, 4 Jul 2024 23:29:32 +0300 Subject: [PATCH] Initial upload --- .github/workflows/build-binaries.yml | 53 ++ .github/workflows/build-docker-images.yml | 107 +++ .gitignore | 25 + Dockerfile | 14 + README.md | 22 + auth.go | 139 ++++ benchmarks.go | 384 +++++++++++ cmd/flightlesssomething/main.go | 25 + config.go | 61 ++ csv.go | 256 +++++++ docker-compose.yaml | 16 + embed.go | 6 + go.mod | 59 ++ go.sum | 317 +++++++++ models.go | 37 + server.go | 97 +++ templates/benchmark.tmpl | 780 ++++++++++++++++++++++ templates/benchmark_create.tmpl | 23 + templates/benchmarks.tmpl | 69 ++ templates/error.tmpl | 7 + templates/error_raw.tmpl | 1 + templates/footer.tmpl | 7 + templates/header.tmpl | 45 ++ templates/user.tmpl | 37 + user.go | 94 +++ 25 files changed, 2681 insertions(+) create mode 100644 .github/workflows/build-binaries.yml create mode 100644 .github/workflows/build-docker-images.yml create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 auth.go create mode 100644 benchmarks.go create mode 100644 cmd/flightlesssomething/main.go create mode 100644 config.go create mode 100644 csv.go create mode 100644 docker-compose.yaml create mode 100644 embed.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 models.go create mode 100644 server.go create mode 100644 templates/benchmark.tmpl create mode 100644 templates/benchmark_create.tmpl create mode 100644 templates/benchmarks.tmpl create mode 100644 templates/error.tmpl create mode 100644 templates/error_raw.tmpl create mode 100644 templates/footer.tmpl create mode 100644 templates/header.tmpl create mode 100644 templates/user.tmpl create mode 100644 user.go diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml new file mode 100644 index 0000000..751ce46 --- /dev/null +++ b/.github/workflows/build-binaries.yml @@ -0,0 +1,53 @@ +name: Build binaries +run-name: Build binaries ${{ github.event.release.tag_name }} + +on: + release: + types: [published] + +jobs: + build: + name: Build binaries + runs-on: ubuntu-latest + strategy: + matrix: + platform: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.22" + + - name: Build binary + run: | + export GOOS=$(echo ${{ matrix.platform }} | awk -F/ '{print $1}') + export GOARCH=$(echo ${{ matrix.platform }} | awk -F/ '{print $2}') + export GOARM=$(echo ${{ matrix.platform }} | awk -F/ '{print $3}' | sed 's/v//') + export CGO_ENABLED=0 + + reponame="${{ github.event.repository.name }}" + version="${{ github.event.release.tag_name }}" + fullarch="${GOARCH}$(echo ${{ matrix.platform }} | awk -F/ '{print $3}')" + filename="${reponame}_${version}_${GOOS}_${fullarch}" + + go build -ldflags "-w -s -X main.version=$version -extldflags '-static'" -o "$filename" cmd/$reponame/main.go + + echo "FILENAME=$filename" >> $GITHUB_ENV + + - name: Compress binary + run: | + tar -czvf "${{ env.FILENAME }}.tar.gz" "${{ env.FILENAME }}" + + - name: Upload binary + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: ${{ env.FILENAME }}.tar.gz + tag: ${{ github.event.release.tag_name }} + overwrite: false diff --git a/.github/workflows/build-docker-images.yml b/.github/workflows/build-docker-images.yml new file mode 100644 index 0000000..cd5e291 --- /dev/null +++ b/.github/workflows/build-docker-images.yml @@ -0,0 +1,107 @@ +name: Build Docker images +run-name: Build Docker images ${{ github.event.release.tag_name }} + +on: + release: + types: [published] + +jobs: + build: + name: Build images + runs-on: ubuntu-latest + strategy: + matrix: + platform: + - linux/amd64 + - linux/arm64 + - linux/arm/v7 + - linux/arm/v6 + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Go Build Cache for Docker + uses: actions/cache@v3 + with: + path: go-build-cache + key: ${{ matrix.platform }}-go-build-cache-${{ hashFiles('**/go.sum') }} + + - name: inject go-build-cache into docker + uses: reproducible-containers/buildkit-cache-dance@v2.1.2 + with: + cache-source: go-build-cache + + - name: Build and push Docker images + id: build + uses: docker/build-push-action@v5 + with: + context: . + platforms: ${{ matrix.platform }} + labels: ${{ steps.meta.outputs.labels }} + outputs: type=image,name=ghcr.io/${{ github.repository }},push-by-digest=true,name-canonical=true,push=true + cache-from: type=gha + cache-to: type=gha,mode=max + build-args: | + version=${{ github.event.release.tag_name }} + + - name: Export digest + run: | + mkdir -p /tmp/digests + digest="${{ steps.build.outputs.digest }}" + touch "/tmp/digests/${digest#sha256:}" + + - name: Upload digest + uses: actions/upload-artifact@v3 + with: + name: digests + path: /tmp/digests/* + if-no-files-found: error + retention-days: 1 + + merge: + name: Merge images + runs-on: ubuntu-latest + needs: build + steps: + - name: Download digests + uses: actions/download-artifact@v3 + with: + name: digests + path: /tmp/digests + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Create manifest list and push + working-directory: /tmp/digests + run: | + docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ + $(printf 'ghcr.io/${{ github.repository }}@sha256:%s ' *) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..159583b --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# If you prefer the allow list template instead of the deny list, see community template: +# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore +# +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# Custom +/data diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..97a610f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM --platform=$BUILDPLATFORM golang:1.22-alpine AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +ARG TARGETOS +ARG TARGETARCH +ARG TARGETVARIANT +ARG version +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH GOARM=${TARGETVARIANT#v} go build -a -ldflags "-w -s -X main.version=$version -extldflags '-static'" -o fm ./cmd/flightlesssomething/main.go + +FROM scratch +COPY --from=builder /app/fm /fm +ENTRYPOINT ["/fm"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..1c3656c --- /dev/null +++ b/README.md @@ -0,0 +1,22 @@ +# FlightlessSomething + +[flightlessmango.com](https://flightlessmango.com/) website clone, written in Go. + +Ever wanted to say _holy crap, who wrote this shit?_ - well, now you can. This project is written not by web developer (or developer at all), so likelly full of vulnerabilities. 🤷 + +# Features + +* Written in Go: + * Fast performance + * Multithreaded + * Single, statically linked binary +* Uses `gin` web framework +* Uses `gorm` ORM (Can be easily ported to other databases) + +## Features that will NOT be included + +* TLS/SSL/ACME - use reverse proxy (I suggest [Caddy](https://github.com/caddyserver/caddy)) + +# Pull requests + +Pull requests are _more_ than welcome, especially fixing vulnerabilities. diff --git a/auth.go b/auth.go new file mode 100644 index 0000000..af2fbc5 --- /dev/null +++ b/auth.go @@ -0,0 +1,139 @@ +package flightlesssomething + +import ( + "context" + "crypto/rand" + "encoding/hex" + "encoding/json" + "io" + "net/http" + + "github.com/gin-contrib/sessions" + "github.com/gin-gonic/gin" +) + +type DiscordUser struct { + ID string `json:"id"` + Username string `json:"username"` +} + +func getLogin(c *gin.Context) { + session := sessions.Default(c) + + discordState, err := getRandomString() + if err != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Failed to generate random string", + }) + return + } + + session.Set("DiscordState", discordState) + session.Save() + + c.Redirect(http.StatusTemporaryRedirect, discordConf.AuthCodeURL(discordState)) +} + +func getLoginCallback(c *gin.Context) { + session := sessions.Default(c) + + discordState := session.Get("DiscordState") + if c.Query("state") != discordState { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Invalid Discord state", + }) + return + } + + token, err := discordConf.Exchange(context.Background(), c.Query("code")) + if err != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Failed to exchange code for token", + }) + return + } + + res, err := discordConf.Client(context.Background(), token).Get("https://discord.com/api/users/@me") + if err != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Failed to get user details from Discord", + }) + return + } + if res.StatusCode != 200 { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Failed to get user details from Discord", + }) + return + } + defer res.Body.Close() + + body, err := io.ReadAll(res.Body) + if err != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Failed to read response body from Discord", + }) + return + } + + var discordUser DiscordUser + err = json.Unmarshal([]byte(body), &discordUser) + if err != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Failed to unmarshal response body from Discord", + }) + return + } + + user := User{ + DiscordID: discordUser.ID, + Username: discordUser.Username, + } + result := db.Model(&user).Where("discord_id = ?", discordUser.ID).Updates(&user) + if result.Error != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Error occurred while updating user details", + }) + return + } + if result.RowsAffected == 0 { + result = db.Create(&user) + if result.Error != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Error occurred while creating user", + }) + return + } + } + + // Retrieve the updated user details from the database + result = db.Model(&user).Where("discord_id = ?", discordUser.ID).First(&user) + if result.Error != nil { + c.HTML(http.StatusInternalServerError, "error_raw.tmpl", gin.H{ + "errorMessage": "Error occurred while retrieving user details", + }) + return + } + + session.Set("ID", user.ID) + session.Set("Username", user.Username) + session.Save() + + c.Redirect(http.StatusTemporaryRedirect, "/") +} + +func getLogout(c *gin.Context) { + session := sessions.Default(c) + session.Clear() + session.Save() + + c.Redirect(http.StatusTemporaryRedirect, "/") +} + +func getRandomString() (string, error) { + bytes := make([]byte, 16) + if _, err := rand.Read(bytes); err != nil { + return "", err + } + return hex.EncodeToString(bytes), nil +} diff --git a/benchmarks.go b/benchmarks.go new file mode 100644 index 0000000..6d95b83 --- /dev/null +++ b/benchmarks.go @@ -0,0 +1,384 @@ +package flightlesssomething + +import ( + "fmt" + "net/http" + "strconv" + "strings" + "sync" + + "github.com/gin-contrib/sessions" + "github.com/gin-gonic/gin" +) + +const BENCHMARKS_PER_PAGE = 10 + +func getBenchmarks(c *gin.Context) { + session := sessions.Default(c) + + // Get "query" value + query := c.Query("query") + + // Get "page" value + page := c.DefaultQuery("page", "1") + pageInt, _ := strconv.Atoi(page) + if pageInt < 1 { + pageInt = 1 + } + + // Get benchmarks according to query + var benchmarks []Benchmark + tx := db. + Preload("User"). + Order("created_at DESC"). + Offset((pageInt - 1) * BENCHMARKS_PER_PAGE). + Limit(BENCHMARKS_PER_PAGE) + if query != "" { + tx = tx.Where("title LIKE ?", "%"+query+"%").Or("description LIKE ?", "%"+query+"%") + } + result := tx.Find(&benchmarks) + if result.Error != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while fetching benchmarks", + }) + return + } + + // Get total number of benchmarks matching the query + var benchmarksTotal int64 + tx = db.Model(&Benchmark{}) + if query != "" { + tx = tx.Where("title LIKE ?", "%"+query+"%").Or("description LIKE ?", "%"+query+"%") + } + result = tx.Count(&benchmarksTotal) + if result.Error != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while counting benchmarks", + }) + return + } + + // Calculate pagination values + prevPage := pageInt - 1 + nextPage := pageInt + 1 + totalPages := (int(benchmarksTotal) + BENCHMARKS_PER_PAGE - 1) / BENCHMARKS_PER_PAGE + + c.HTML(http.StatusOK, "benchmarks.tmpl", gin.H{ + "activePage": "benchmarks", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "benchmarks": benchmarks, + "benchmarksTotal": benchmarksTotal, + + // Query parameters + "query": query, + "page": pageInt, + + // Pagination values + "prevPage": prevPage, + "nextPage": nextPage, + "totalPages": totalPages, + }) +} + +func getBenchmarkCreate(c *gin.Context) { + session := sessions.Default(c) + if session.Get("Username") == "" { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Please authenticate to create a benchmark", + }) + } + + c.HTML(http.StatusOK, "benchmark_create.tmpl", gin.H{ + "activePage": "benchmark", + "username": session.Get("Username"), + "userID": session.Get("ID"), + }) +} + +func postBenchmarkCreate(c *gin.Context) { + session := sessions.Default(c) + if session.Get("Username") == "" { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Please authenticate to create a benchmark", + }) + return + } + + title := strings.TrimSpace(c.PostForm("title")) + if len(title) > 100 || title == "" { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Title must not be empty or exceed 100 characters", + }) + return + } + + description := strings.TrimSpace(c.PostForm("description")) + if len(description) > 500 || description == "" { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Description must not be empty or exceed 500 characters", + }) + return + } + + form, err := c.MultipartForm() + if err != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while parsing form data", + }) + return + } + files := form.File["files"] + if len(files) == 0 { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "No files uploaded", + }) + return + } + if len(files) > 30 { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Too many files uploaded (max 30)", + }) + return + } + + // Read CSV files + // Store to disk only when DB record is created successfully + csvFiles, csvSpecs, err := readCSVFiles(files) + if err != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while reading CSV files: " + err.Error(), + }) + return + } + + benchmark := Benchmark{ + UserID: session.Get("ID").(uint), + Title: title, + Description: description, + + SpecDistro: csvSpecs.Distro, + SpecCPU: csvSpecs.Distro, + SpecGPU: csvSpecs.GPU, + SpecRAM: csvSpecs.RAM, + SpecKernel: csvSpecs.Kernel, + SpecScheduler: csvSpecs.Scheduler, + } + + result := db.Create(&benchmark) + if result.Error != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while creating benchmark: " + result.Error.Error(), + }) + return + } + + // Store CSV files to disk + err = storeBenchmarkData(csvFiles, benchmark.ID) + if err != nil { + db.Unscoped().Delete(&benchmark) // Hard delete from DB + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while storing benchmark data: " + err.Error(), + }) + return + } + + // Redirect to the newly created benchmark using GET request + c.Redirect(http.StatusSeeOther, fmt.Sprintf("/benchmark/%d", benchmark.ID)) +} + +func deleteBenchmark(c *gin.Context) { + session := sessions.Default(c) + if session.Get("Username") == "" { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Please authenticate to create a benchmark", + }) + return + } + + // Get benchmark ID from the path + id := c.Param("id") + + // Check if user owns the benchmark + var benchmark Benchmark + result := db.First(&benchmark, id) + if result.Error != nil { + c.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Internal server error occurred: " + result.Error.Error(), + }) + return + } + if benchmark.UserID != session.Get("ID") { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "You do not own this benchmark", + }) + return + } + + // Delete benchmark from DB + result = db.Delete(&benchmark) + if result.Error != nil { + c.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Internal server error occurred: " + result.Error.Error(), + }) + return + } + + // Delete benchmark data from disk + err := deleteBenchmarkData(benchmark.ID) + if err != nil { + c.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Internal server error occurred: " + err.Error(), + }) + return + } + + // Redirect to the benchmarks page + c.Header("HX-Redirect", "/benchmarks") + c.JSON(http.StatusOK, gin.H{ + "message": "Benchmark deleted successfully", + }) +} + +func getBenchmark(c *gin.Context) { + session := sessions.Default(c) + + // Get benchmark ID from the path + id := c.Param("id") + + // Get benchmark details + intID, err := strconv.Atoi(id) + if err != nil { + c.HTML(http.StatusInternalServerError, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Internal server error occurred: " + err.Error(), + }) + return + } + + var benchmark Benchmark + benchmark.ID = uint(intID) + + var csvFiles []*CSVFile + var errCSV, errDB error + errHTTPStatus := http.StatusInternalServerError + + wg := sync.WaitGroup{} + wg.Add(2) + + go func() { + defer wg.Done() + csvFiles, errCSV = retrieveBenchmarkData(benchmark.ID) + }() + + go func() { + defer wg.Done() + result := db.Preload("User").First(&benchmark, id) + if result.Error != nil { + errDB = result.Error + return + } + if result.RowsAffected == 0 { + errDB = fmt.Errorf("Benchmark not found") + errHTTPStatus = http.StatusNotFound + return + } + }() + + wg.Wait() + + err = errDB + if err == nil { + err = errCSV + } + if err != nil { + c.HTML(errHTTPStatus, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + "errorMessage": "Error occurred: " + errDB.Error(), + }) + return + } + + c.HTML(http.StatusOK, "benchmark.tmpl", gin.H{ + "activePage": "benchmark", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "benchmark": benchmark, + "benchmarkData": csvFiles, + }) +} diff --git a/cmd/flightlesssomething/main.go b/cmd/flightlesssomething/main.go new file mode 100644 index 0000000..4bc6cda --- /dev/null +++ b/cmd/flightlesssomething/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "flightlesssomething" + "fmt" + "log" +) + +var ( + version string +) + +func main() { + c, err := flightlesssomething.NewConfig() + if err != nil { + log.Fatalln("Failed to get config:", err) + } + + if c.Version { + fmt.Println("Version:", version) + return + } + + flightlesssomething.Start(c) +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..30252fc --- /dev/null +++ b/config.go @@ -0,0 +1,61 @@ +package flightlesssomething + +import ( + "errors" + "flag" + + "github.com/csmith/envflag" +) + +type Config struct { + Bind string + DataDir string + + DiscordClientID string + DiscordClientSecret string + DiscordRedirectURL string + + Version bool +} + +func NewConfig() (*Config, error) { + // Define the flags + bind := flag.String("bind", "0.0.0.0:8080", "Bind address and port") + dataDir := flag.String("data-dir", "/data", "Path where data would be stored") + discordClientID := flag.String("discord-client-id", "", "Discord OAuth2 client ID (see https://discord.com/developers/applications)") + discordClientSecret := flag.String("discord-client-secret", "", "Discord OAuth2 client secret (see https://discord.com/developers/applications)") + discordRedirectURL := flag.String("discord-redirect-url", "", "Discord OAuth2 redirect URL (:///login/callback)") + flagVersion := flag.Bool("version", false, "prints version of the application") + + envflag.Parse(envflag.WithPrefix("FS_")) + + // Assign the parsed flag values to the Config struct + config := &Config{ + Bind: *bind, + DataDir: *dataDir, + DiscordClientID: *discordClientID, + DiscordClientSecret: *discordClientSecret, + DiscordRedirectURL: *discordRedirectURL, + + Version: *flagVersion, + } + + if config.Version { + return config, nil + } + + if config.DataDir == "" { + return nil, errors.New("missing data-dir argument") + } + if config.DiscordClientID == "" { + return nil, errors.New("missing discord-client-id argument") + } + if config.DiscordClientSecret == "" { + return nil, errors.New("missing discord-client-secret argument") + } + if config.DiscordRedirectURL == "" { + return nil, errors.New("missing discord-redirect-url argument") + } + + return config, nil +} diff --git a/csv.go b/csv.go new file mode 100644 index 0000000..33ee177 --- /dev/null +++ b/csv.go @@ -0,0 +1,256 @@ +package flightlesssomething + +import ( + "bufio" + "bytes" + "encoding/gob" + "errors" + "fmt" + "log" + "math/big" + "mime/multipart" + "os" + "path/filepath" + "strings" + + "github.com/dustin/go-humanize" + "github.com/klauspost/compress/zstd" +) + +type CSVFile struct { + Filename string + + FPSPointsArray string + FrameTimeArray string + CPULoadArray string + GPULoadArray string + CPUTempArray string + GPUTempArray string + GPUCoreClockArray string + GPUMemClockArray string + GPUVRAMUsedArray string + GPUPowerArray string + RAMUsedArray string + SwapUsedArray string +} + +type CSVSpecs struct { + MaxPoints int + + Distro string + Kernel string + GPU string + CPU string + RAM string + Scheduler string +} + +// readCSVFiles reads multiple CSV files and returns a slice of CSVFile pointers and the maximum number of FPS records found in any file +func readCSVFiles(files []*multipart.FileHeader) ([]*CSVFile, *CSVSpecs, error) { + csvFiles := make([]*CSVFile, 0) + csvSpecs := &CSVSpecs{} + + var linesCount int + + for _, fileHeader := range files { + csvFile := CSVFile{} + + file, err := fileHeader.Open() + if err != nil { + return nil, nil, err + } + defer file.Close() + + scanner := bufio.NewScanner(file) + + // Set file name (without extension) + csvFile.Filename = strings.TrimSuffix(fileHeader.Filename, ".csv") + + // First line should contain this: os,cpu,gpu,ram,kernel,driver,cpuscheduler + if !scanner.Scan() { + return nil, nil, errors.New("invalid CSV file (err 1)") + } + record := strings.Split(strings.TrimRight(scanner.Text(), ","), ",") + if len(record) != 7 { + return nil, nil, errors.New("invalid CSV file (err 2)") + } + + // Second line should contain values + if !scanner.Scan() { + return nil, nil, errors.New("invalid CSV file (err 3)") + } + record = strings.Split(scanner.Text(), ",") + + for i, v := range record { + switch i { + case 0: + csvSpecs.Distro = truncateString(strings.TrimSpace(v)) + case 1: + csvSpecs.CPU = truncateString(strings.TrimSpace(v)) + case 2: + csvSpecs.GPU = truncateString(strings.TrimSpace(v)) + case 3: + kilobytes := new(big.Int) + _, ok := kilobytes.SetString(strings.TrimSpace(v), 10) + if !ok { + return nil, nil, errors.New("failed to convert RAM to big.Int") + } + bytes := new(big.Int).Mul(kilobytes, big.NewInt(1024)) + csvSpecs.RAM = humanize.Bytes(bytes.Uint64()) + case 4: + csvSpecs.Kernel = truncateString(strings.TrimSpace(v)) + case 6: + csvSpecs.Scheduler = truncateString(strings.TrimSpace(v)) + } + } + + // 3rd line contain headers for benchmark data: fps,frametime,cpu_load,gpu_load,cpu_temp,gpu_temp,gpu_core_clock,gpu_mem_clock,gpu_vram_used,gpu_power,ram_used,swap_used,process_rss,elapsed + if !scanner.Scan() { + return nil, nil, errors.New("invalid CSV file (err 5)") + } + record = strings.Split(strings.TrimRight(scanner.Text(), ","), ",") + if len(record) != 14 { + return nil, nil, errors.New("invalid CSV file (err 6)") + } + + fpsPoints := make([]string, 0, linesCount) + frametimePoints := make([]string, 0, linesCount) + cpuLoadPoints := make([]string, 0, linesCount) + gpuLoadPoints := make([]string, 0, linesCount) + cpuTempPoints := make([]string, 0, linesCount) + gpuTempPoints := make([]string, 0, linesCount) + gpuCoreClockPoints := make([]string, 0, linesCount) + gpuMemClockPoints := make([]string, 0, linesCount) + gpuVRAMUsedPoints := make([]string, 0, linesCount) + gpuPowerPoints := make([]string, 0, linesCount) + RAMUsedPoints := make([]string, 0, linesCount) + SWAPUsedPoints := make([]string, 0, linesCount) + + var counter uint + + for scanner.Scan() { + record = strings.Split(scanner.Text(), ",") + if len(record) != 14 { + return nil, nil, errors.New("invalid CSV file (err 7)") + } + fpsPoints = append(fpsPoints, record[0]) + frametimePoints = append(frametimePoints, record[1]) + cpuLoadPoints = append(cpuLoadPoints, record[2]) + gpuLoadPoints = append(gpuLoadPoints, record[3]) + cpuTempPoints = append(cpuTempPoints, record[4]) + gpuTempPoints = append(gpuTempPoints, record[5]) + gpuCoreClockPoints = append(gpuCoreClockPoints, record[6]) + gpuMemClockPoints = append(gpuMemClockPoints, record[7]) + gpuVRAMUsedPoints = append(gpuVRAMUsedPoints, record[8]) + gpuPowerPoints = append(gpuPowerPoints, record[9]) + RAMUsedPoints = append(RAMUsedPoints, record[10]) + SWAPUsedPoints = append(SWAPUsedPoints, record[11]) + + counter++ + if counter == 100000 { + return nil, nil, errors.New("too large CSV file") + } + } + + // More efficient buffer allocation + linesCount = len(fpsPoints) + + if err := scanner.Err(); err != nil { + log.Println("error (4) parsing CSV:", err) + return nil, nil, err + } + + if len(fpsPoints) == 0 { + return nil, nil, errors.New("invalid CSV file (err 8)") + } + + if len(fpsPoints) > csvSpecs.MaxPoints { + csvSpecs.MaxPoints = len(fpsPoints) + } + + csvFile.FPSPointsArray = strings.Join(fpsPoints, ",") + csvFile.FrameTimeArray = strings.Join(frametimePoints, ",") + csvFile.CPULoadArray = strings.Join(cpuLoadPoints, ",") + csvFile.GPULoadArray = strings.Join(gpuLoadPoints, ",") + csvFile.CPUTempArray = strings.Join(cpuTempPoints, ",") + csvFile.GPUTempArray = strings.Join(gpuTempPoints, ",") + csvFile.GPUCoreClockArray = strings.Join(gpuCoreClockPoints, ",") + csvFile.GPUMemClockArray = strings.Join(gpuMemClockPoints, ",") + csvFile.GPUVRAMUsedArray = strings.Join(gpuVRAMUsedPoints, ",") + csvFile.GPUPowerArray = strings.Join(gpuPowerPoints, ",") + csvFile.RAMUsedArray = strings.Join(RAMUsedPoints, ",") + csvFile.SwapUsedArray = strings.Join(SWAPUsedPoints, ",") + + csvFiles = append(csvFiles, &csvFile) + } + + return csvFiles, csvSpecs, nil +} + +// truncateString truncates the input string to a maximum of 100 characters and appends "..." if it exceeds that length. +func truncateString(s string) string { + const maxLength = 100 + if len(s) > maxLength { + return s[:maxLength] + "..." + } + return s +} + +func storeBenchmarkData(csvFiles []*CSVFile, benchmarkID uint) error { + // Store to disk + filePath := filepath.Join(benchmarksDir, fmt.Sprintf("%d.bin", benchmarkID)) + file, err := os.Create(filePath) + if err != nil { + return err + } + defer file.Close() + + // Convert to []byte + var buffer bytes.Buffer + gobEncoder := gob.NewEncoder(&buffer) + err = gobEncoder.Encode(csvFiles) + if err != nil { + return err + } + + // Compress and write to file + zstdEncoder, err := zstd.NewWriter(file, zstd.WithEncoderLevel(zstd.SpeedFastest)) + if err != nil { + return err + } + defer zstdEncoder.Close() + _, err = zstdEncoder.Write(buffer.Bytes()) + return err +} + +func retrieveBenchmarkData(benchmarkID uint) (csvFiles []*CSVFile, err error) { + filePath := filepath.Join(benchmarksDir, fmt.Sprintf("%d.bin", benchmarkID)) + file, err := os.Open(filePath) + if err != nil { + return nil, err + } + defer file.Close() + + // Decompress and read from file + zstdDecoder, err := zstd.NewReader(file) + if err != nil { + return nil, err + } + defer zstdDecoder.Close() + + var buffer bytes.Buffer + _, err = buffer.ReadFrom(zstdDecoder) + if err != nil { + return nil, err + } + + // Decode + gobDecoder := gob.NewDecoder(&buffer) + err = gobDecoder.Decode(&csvFiles) + return csvFiles, err +} + +func deleteBenchmarkData(benchmarkID uint) error { + filePath := filepath.Join(benchmarksDir, fmt.Sprintf("%d.bin", benchmarkID)) + return os.Remove(filePath) +} diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..5ecfff9 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,16 @@ +services: + + flightlesssomething: + image: ghcr.io/erkexzcx/flightlesssomething:latest + container_name: flightlesssomething + ports: + - "8080:8080" + volumes: + - ./flightlesssomething/data:/data + environment: + - FS_BIND="0.0.0.0:8080" + - FS_DATA_DIR="/data" + - FS_DISCORD_CLIENT_ID="xxxxxxxxxxxxxxxxxx" + - FS_DISCORD_CLIENT_SECRET="xxxxxxxxxxxxxxxxxx" + - FS_DISCORD_REDIRECT_URL=":///login/callback" + restart: unless-stopped diff --git a/embed.go b/embed.go new file mode 100644 index 0000000..ff25851 --- /dev/null +++ b/embed.go @@ -0,0 +1,6 @@ +package flightlesssomething + +import "embed" + +//go:embed templates/* +var templatesFS embed.FS diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5a21f1b --- /dev/null +++ b/go.mod @@ -0,0 +1,59 @@ +module flightlesssomething + +go 1.22 + +require github.com/gin-gonic/gin v1.10.0 + +require ( + github.com/gorilla/context v1.1.2 // indirect + github.com/gorilla/securecookie v1.1.2 // indirect + github.com/gorilla/sessions v1.2.2 // indirect + github.com/wader/gormstore/v2 v2.0.3 // indirect +) + +require ( + github.com/bytedance/sonic v1.11.6 // indirect + github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/cloudwego/base64x v0.1.4 // indirect + github.com/cloudwego/iasm v0.2.0 // indirect + github.com/csmith/envflag v1.0.0 + github.com/dustin/go-humanize v1.0.1 + github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gin-contrib/sessions v1.0.1 + github.com/gin-contrib/sse v0.1.0 // indirect + github.com/glebarez/go-sqlite v1.21.2 // indirect + github.com/glebarez/sqlite v1.11.0 + github.com/go-playground/locales v0.14.1 // indirect + github.com/go-playground/universal-translator v0.18.1 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect + github.com/goccy/go-json v0.10.2 // indirect + github.com/google/uuid v1.3.0 // indirect + github.com/jinzhu/inflection v1.0.0 // indirect + github.com/jinzhu/now v1.1.5 // indirect + github.com/json-iterator/go v1.1.12 // indirect + github.com/klauspost/compress v1.17.9 + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect + github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/twitchyliquid64/golang-asm v0.15.1 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/oauth2 v0.21.0 + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/sqlite v1.5.6 // indirect + gorm.io/gorm v1.25.10 + modernc.org/libc v1.22.5 // indirect + modernc.org/mathutil v1.5.0 // indirect + modernc.org/memory v1.5.0 // indirect + modernc.org/sqlite v1.23.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..5f35142 --- /dev/null +++ b/go.sum @@ -0,0 +1,317 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= +github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/csmith/envflag v1.0.0 h1:ARMp9RyT/+1eMevJrB0cQeHxBlGpnoLSjuPdGVINzIA= +github.com/csmith/envflag v1.0.0/go.mod h1:cE/k+xEpKPaIvo7Tz3RubNpWXRRf/WcI+bvPopn4VE0= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gin-contrib/sessions v1.0.1 h1:3hsJyNs7v7N8OtelFmYXFrulAf6zSR7nW/putcPEHxI= +github.com/gin-contrib/sessions v1.0.1/go.mod h1:ouxSFM24/OgIud5MJYQJLpy6AwxQ5EYO9yLhbtObGkM= +github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= +github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= +github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo= +github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k= +github.com/glebarez/sqlite v1.11.0 h1:wSG0irqzP6VurnMEpFGer5Li19RpIRi2qvQz++w0GMw= +github.com/glebarez/sqlite v1.11.0/go.mod h1:h8/o8j5wiAsqSPoWELDUdJXhjAhsVliSn7bWZjOhrgQ= +github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= +github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= +github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= +github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= +github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= +github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= +github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= +github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= +github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o= +github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM= +github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= +github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA= +github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo= +github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= +github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY= +github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ= +github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0= +github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= +github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= +github.com/jackc/chunkreader/v2 v2.0.1/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= +github.com/jackc/pgconn v0.0.0-20190420214824-7e0022ef6ba3/go.mod h1:jkELnwuX+w9qN5YIfX0fl88Ehu4XC3keFuOJJk9pcnA= +github.com/jackc/pgconn v0.0.0-20190824142844-760dd75542eb/go.mod h1:lLjNuW/+OfW9/pnVKPazfWOgNfH2aPem8YQ7ilXGvJE= +github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsUgOEh9hBm+xYTstcNHg7UPMVJqRfQxq4s= +github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= +github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= +github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= +github.com/jackc/pgconn v1.13.0 h1:3L1XMNV2Zvca/8BYhzcRFS70Lr0WlDg16Di6SFGAbys= +github.com/jackc/pgconn v1.13.0/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= +github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= +github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= +github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= +github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= +github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgproto3 v1.1.0 h1:FYYE4yRw+AgI8wXIinMlNjBbp/UitDJwfj5LqqewP1A= +github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= +github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= +github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190609003834-432c2951c711/go.mod h1:uH0AWtUmuShn0bcesswc4aBTWGvw0cAxIJp+6OB//Wg= +github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= +github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= +github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y= +github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b h1:C8S2+VttkHFdOOCXJe+YGfa4vHYwlt4Zx+IVXQ97jYg= +github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= +github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= +github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= +github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= +github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= +github.com/jackc/pgtype v1.12.0 h1:Dlq8Qvcch7kiehm8wPGIW0W3KsCCHJnRacKW0UM8n5w= +github.com/jackc/pgtype v1.12.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= +github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= +github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= +github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= +github.com/jackc/pgx/v4 v4.17.2 h1:0Ut0rpeKwvIVbMQ1KbMBU4h6wxehBI535LK6Flheh8E= +github.com/jackc/pgx/v4 v4.17.2/go.mod h1:lcxIZN44yMIrWI78a5CpucdD14hX0SBDbNRvjDBItsw= +github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= +github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= +github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= +github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU= +github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y= +github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= +github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3 h1:x3LgcvujjG+mx8PUMfPmwn3tcu2aA95uCB6ilGGObWk= +github.com/ravener/discord-oauth2 v0.0.0-20230514095040-ae65713199b3/go.mod h1:P/mZMYLZ87lqRSECEWsOqywGrO1hlZkk9RTwEw35IP4= +github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= +github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= +github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= +github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= +github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= +github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/wader/gormstore/v2 v2.0.3 h1:/29GWPauY8xZkpLnB8hsp+dZfP3ivA9fiDw1YVNTp6U= +github.com/wader/gormstore/v2 v2.0.3/go.mod h1:sr3N3a8F1+PBc3fHoKaphFqDXLRJ9Oe6Yow0HxKFbbg= +github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= +go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= +go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= +go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= +go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= +golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= +golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= +golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190823170909-c4a336ef6a2f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= +golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/mysql v1.4.0 h1:P+gpa0QGyNma39khn1vZMS/eXEJxTwHz4Q26NR4C8fw= +gorm.io/driver/mysql v1.4.0/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= +gorm.io/driver/postgres v1.4.1 h1:DutsKq2LK2Ag65q/+VygWth0/L4GAVOp+sCtg6WzZjs= +gorm.io/driver/postgres v1.4.1/go.mod h1:whNfh5WhhHs96honoLjBAMwJGYEuA3m1hvgUbNXhPCw= +gorm.io/driver/sqlite v1.4.1/go.mod h1:AKZZCAoFfOWHF7Nd685Iq8Uywc0i9sWJlzpoE/INzsw= +gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE= +gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4= +gorm.io/gorm v1.23.7/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= +gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= +gorm.io/gorm v1.23.10/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= +gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s= +gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +modernc.org/libc v1.22.5 h1:91BNch/e5B0uPbJFgqbxXuOnxBQjlS//icfQEGmvyjE= +modernc.org/libc v1.22.5/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= +modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= +modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= +modernc.org/memory v1.5.0 h1:N+/8c5rE6EqugZwHii4IFsaJ7MUhoWX07J5tC/iI5Ds= +modernc.org/memory v1.5.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= +modernc.org/sqlite v1.23.1 h1:nrSBg4aRQQwq59JpvGEQ15tNxoO5pX/kUjcRNwSAGQM= +modernc.org/sqlite v1.23.1/go.mod h1:OrDj17Mggn6MhE+iPbBNf7RGKODDE9NFT0f3EwDzJqk= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= +rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= diff --git a/models.go b/models.go new file mode 100644 index 0000000..d40f579 --- /dev/null +++ b/models.go @@ -0,0 +1,37 @@ +package flightlesssomething + +import ( + "github.com/dustin/go-humanize" + "gorm.io/gorm" +) + +type User struct { + gorm.Model + DiscordID string + Username string + + Benchmarks []Benchmark `gorm:"constraint:OnDelete:CASCADE;"` +} + +type Benchmark struct { + gorm.Model + UserID uint + Title string + Description string + SpecDistro string + SpecCPU string + SpecGPU string + SpecRAM string + SpecKernel string + SpecScheduler string + + CreatedAtHumanized string `gorm:"-"` // Human readable "X h/m/s ago" version of CreatedAt (filled automatically) + + User User `gorm:"foreignKey:UserID;"` +} + +// AfterFind is a GORM hook that is called after a record is found +func (b *Benchmark) AfterFind(tx *gorm.DB) (err error) { + b.CreatedAtHumanized = humanize.Time(b.CreatedAt) + return nil +} diff --git a/server.go b/server.go new file mode 100644 index 0000000..3f0b311 --- /dev/null +++ b/server.go @@ -0,0 +1,97 @@ +package flightlesssomething + +import ( + "html/template" + "net/http" + "os" + "path/filepath" + + "github.com/gin-contrib/sessions" + gormsessions "github.com/gin-contrib/sessions/gorm" + "github.com/gin-gonic/gin" + "github.com/glebarez/sqlite" + "github.com/ravener/discord-oauth2" + "golang.org/x/oauth2" + "gorm.io/gorm" +) + +var ( + // GORM database object + db *gorm.DB + + // Discord conf object + discordConf *oauth2.Config + + // Benchmarks directory + benchmarksDir string +) + +func Start(c *Config) { + // Setup data dir // + + _, err := os.Stat(c.DataDir) + if os.IsNotExist(err) { + err := os.Mkdir(c.DataDir, 0755) + if err != nil { + panic("Failed to create data dir: " + err.Error()) + } + } else if err != nil { + panic("Failed to check data dir: " + err.Error()) + } + + benchmarksDir = filepath.Join(c.DataDir, "benchmarks") + _, err = os.Stat(benchmarksDir) + if os.IsNotExist(err) { + err := os.Mkdir(benchmarksDir, 0755) + if err != nil { + panic("Failed to create benchmarks dir: " + err.Error()) + } + } else if err != nil { + panic("Failed to check benchmarks dir: " + err.Error()) + } + + // Setup Discord OAuth2 // + + discordConf = &oauth2.Config{ + Endpoint: discord.Endpoint, + Scopes: []string{discord.ScopeIdentify}, + RedirectURL: c.DiscordRedirectURL, + ClientID: c.DiscordClientID, + ClientSecret: c.DiscordClientSecret, + } + + // Setup gorm (database) // + + db, err = gorm.Open(sqlite.Open(filepath.Join(c.DataDir, "database.db")), &gorm.Config{}) + if err != nil { + panic(err) + } + store := gormsessions.NewStore(db, true, []byte("secret")) + db.AutoMigrate(&Benchmark{}) + + // Setup gin // + + r := gin.Default() + r.Use(sessions.Sessions("mysession", store)) + + // Parse the embedded templates + tmpl := template.Must(template.ParseFS(templatesFS, "templates/*.tmpl")) + r.SetHTMLTemplate(tmpl) + + r.GET("/", func(c *gin.Context) { c.Redirect(http.StatusTemporaryRedirect, "/benchmarks") }) + + r.GET("/benchmarks", getBenchmarks) + + r.GET("/benchmark", getBenchmarkCreate) + r.POST("/benchmark", postBenchmarkCreate) + r.GET("/benchmark/:id", getBenchmark) + r.DELETE("/benchmark/:id", deleteBenchmark) + + r.GET("/user/:id", getUser) + + r.GET("/login", getLogin) + r.GET("/login/callback", getLoginCallback) + r.GET("/logout", getLogout) + + r.Run(c.Bind) +} diff --git a/templates/benchmark.tmpl b/templates/benchmark.tmpl new file mode 100644 index 0000000..5f16c05 --- /dev/null +++ b/templates/benchmark.tmpl @@ -0,0 +1,780 @@ +{{template "header.tmpl" .}} + +
+
+
+
+
{{ .benchmark.Title }}
+

{{ .benchmark.Description }}

+

Submitted {{ .benchmark.CreatedAtHumanized }} by {{ .benchmark.User.Username }}.

+
+
+
+
+
    +
  • Distro: {{ .benchmark.SpecDistro }}
  • +
  • Kernel: {{ .benchmark.SpecKernel }}
  • +
  • GPU: {{ .benchmark.SpecGPU }}
  • +
  • CPU: {{ .benchmark.SpecCPU }}
  • +
  • RAM: {{ .benchmark.SpecRAM }}
  • +
  • Scheduler: {{ .benchmark.SpecScheduler }}
  • +
+
+
+ +{{if .username}} +Delete benchmark +{{end}} + + + +
+
+ +
+
+

+ +

+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+ +
+ + + 50% +
+
+ + + + + + + + + +{{template "footer.tmpl" .}} diff --git a/templates/benchmark_create.tmpl b/templates/benchmark_create.tmpl new file mode 100644 index 0000000..a584679 --- /dev/null +++ b/templates/benchmark_create.tmpl @@ -0,0 +1,23 @@ +{{template "header.tmpl" .}} + +
+

New benchmark

+
+ +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +{{template "footer.tmpl" .}} diff --git a/templates/benchmarks.tmpl b/templates/benchmarks.tmpl new file mode 100644 index 0000000..8c28aeb --- /dev/null +++ b/templates/benchmarks.tmpl @@ -0,0 +1,69 @@ +{{template "header.tmpl" .}} + +
+

Benchmarks

+ {{if .username}} + New benchmark + {{end}} +
+ +
+
+ + + + +
+
+ +

Benchmarks found: {{ .benchmarksTotal }}

+ +
+ {{- range .benchmarks -}} +
+ +
+
{{ .Title }}
+ {{ .CreatedAtHumanized }} +
+
+

{{ .Description }}

+ By {{ .User.Username }} +
+
+ {{- end -}} +
+ + + +
+ +
+ +{{template "footer.tmpl" .}} diff --git a/templates/error.tmpl b/templates/error.tmpl new file mode 100644 index 0000000..a84aaf8 --- /dev/null +++ b/templates/error.tmpl @@ -0,0 +1,7 @@ +{{template "header.tmpl" .}} + +

Error

+ +

{{ .errorMessage }}

+ +{{template "footer.tmpl" .}} diff --git a/templates/error_raw.tmpl b/templates/error_raw.tmpl new file mode 100644 index 0000000..5a4c7c5 --- /dev/null +++ b/templates/error_raw.tmpl @@ -0,0 +1 @@ +{{ .errorMessage }} \ No newline at end of file diff --git a/templates/footer.tmpl b/templates/footer.tmpl new file mode 100644 index 0000000..6291e2d --- /dev/null +++ b/templates/footer.tmpl @@ -0,0 +1,7 @@ + + + + + + + diff --git a/templates/header.tmpl b/templates/header.tmpl new file mode 100644 index 0000000..e335e6b --- /dev/null +++ b/templates/header.tmpl @@ -0,0 +1,45 @@ + + + + + + + + FlightlessSomething + + +
+ diff --git a/templates/user.tmpl b/templates/user.tmpl new file mode 100644 index 0000000..5c665f5 --- /dev/null +++ b/templates/user.tmpl @@ -0,0 +1,37 @@ +{{template "header.tmpl" .}} + +

Benchmarks by {{ .user.Username }}

+ +

Benchmarks found: {{ .benchmarksTotal }}

+ + + + +
+ +
+ +{{template "footer.tmpl" .}} diff --git a/user.go b/user.go new file mode 100644 index 0000000..7b20285 --- /dev/null +++ b/user.go @@ -0,0 +1,94 @@ +package flightlesssomething + +import ( + "net/http" + "strconv" + + "github.com/gin-contrib/sessions" + "github.com/gin-gonic/gin" +) + +func getUser(c *gin.Context) { + session := sessions.Default(c) + + // Get "page" value + page := c.DefaultQuery("page", "1") + pageInt, _ := strconv.Atoi(page) + if pageInt < 1 { + pageInt = 1 + } + + id := c.Param("id") + + // Get user details + var user User + result := db.Where("id = ?", id).First(&user) + if result.Error != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while fetching user details", + }) + return + } + + // Get benchmarks of the user + var benchmarks []Benchmark + tx := db. + Where("user_id = ?", id). + Order("created_at DESC"). + Offset((pageInt - 1) * BENCHMARKS_PER_PAGE). + Limit(BENCHMARKS_PER_PAGE) + result = tx.Find(&benchmarks) + if result.Error != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while fetching benchmarks", + }) + return + } + + // Get total number of benchmarks of the user + var benchmarksTotal int64 + tx = db.Where("user_id = ?", id).Model(&Benchmark{}) + result = tx.Count(&benchmarksTotal) + if result.Error != nil { + c.HTML(http.StatusUnauthorized, "error.tmpl", gin.H{ + "activePage": "error", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "errorMessage": "Error occurred while counting benchmarks", + }) + return + } + + // Calculate pagination values + prevPage := pageInt - 1 + nextPage := pageInt + 1 + totalPages := (int(benchmarksTotal) + BENCHMARKS_PER_PAGE - 1) / BENCHMARKS_PER_PAGE + + c.HTML(http.StatusOK, "user.tmpl", gin.H{ + "activePage": "user", + "username": session.Get("Username"), + "userID": session.Get("ID"), + + "benchmarks": benchmarks, + "benchmarksTotal": benchmarksTotal, + + "user": user, + + // Query parameters + "page": pageInt, + + // Pagination values + "prevPage": prevPage, + "nextPage": nextPage, + "totalPages": totalPages, + }) +}