Skip to content

Commit

Permalink
feat(workflows): add release
Browse files Browse the repository at this point in the history
  • Loading branch information
suhodolskiy committed Aug 27, 2024
1 parent 7afbff6 commit 95767d9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Release Go Binaries

on:
release:
types: [created]
workflow_dispatch:

permissions:
contents: write
packages: write

jobs:
releases-matrix:
name: Release Go Binary
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/386, darwin/amd64
goos: [darwin]
# goarch: ["386", amd64]
steps:
- uses: actions/checkout@v4
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
goversion: "1.18"
ldflags: "-s -w"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
__debug_bin
dist
dist
.idea
57 changes: 31 additions & 26 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package main

import (
"embed"
"encoding/json"
"flag"
"fmt"
"net/http"
"os"
"os/exec"
"path/filepath"
"text/template"
"time"
)

//go:embed index.html
var tpl embed.FS

const command = `
tell application "Spotify"
set ctrack to "{"
Expand Down Expand Up @@ -77,43 +79,46 @@ func main() {
port := flag.String("port", "5783", "http port")
flag.Parse()

ex, _ := os.Executable()
tmpl, err := template.ParseFiles(filepath.Join(ex, "../index.html"))
tmpl, err := template.ParseFS(tpl, "index.html")

if err != nil {
panic(err)
}

http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
response := Response{
Track: getCurrentTrack(),
Refresh: time.Second.Milliseconds(),
Port: *port,
}
http.HandleFunc(
"/", func(w http.ResponseWriter, req *http.Request) {
response := Response{
Track: getCurrentTrack(),
Refresh: time.Second.Milliseconds(),
Port: *port,
}

refreshQueryParam := req.URL.Query().Get("refresh")
refreshQueryParam := req.URL.Query().Get("refresh")

if refreshQueryParam != "" {
if duration, err := time.ParseDuration(refreshQueryParam); err == nil {
response.Refresh = duration.Milliseconds()
if refreshQueryParam != "" {
if duration, err := time.ParseDuration(refreshQueryParam); err == nil {
response.Refresh = duration.Milliseconds()
}
}
}

if err := tmpl.Execute(w, response); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
if err := tmpl.Execute(w, response); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
},
)

http.HandleFunc("/track", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
http.HandleFunc(
"/track", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")

resp, _ := json.Marshal(getCurrentTrack())
resp, _ := json.Marshal(getCurrentTrack())

fmt.Fprint(w, string(resp))
})
fmt.Fprint(w, string(resp))
},
)

fmt.Printf("The server is running on port %s!", *port)
fmt.Printf("Add Overlay to OBS Studio with URL: http://localhost:%s/", *port)

http.ListenAndServe(fmt.Sprintf(":%s", *port), nil)
}

0 comments on commit 95767d9

Please sign in to comment.