Skip to content

Commit c3e43e0

Browse files
authored
Merge pull request #2 from samocodes/patch-1
patch-1: Updates
2 parents 8c062ca + 44cf0e6 commit c3e43e0

File tree

6 files changed

+15
-23
lines changed

6 files changed

+15
-23
lines changed

cmd/go-lrc/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
"fmt"
54
"log"
5+
"net"
66
"net/http"
77

88
"github.com/samocodes/go-lrc/env"
@@ -19,7 +19,7 @@ func (app *Application) Serve() error {
1919
log.Printf("🚀 Server listening to port %s", port)
2020

2121
srv := &http.Server{
22-
Addr: fmt.Sprintf(":%s", port),
22+
Addr: net.JoinHostPort("localhost", port),
2323
Handler: routes.Routes(),
2424
}
2525

File renamed without changes.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ module github.com/samocodes/go-lrc
33
go 1.22.4
44

55
require (
6-
github.com/go-chi/chi v1.5.5
7-
github.com/go-chi/cors v1.2.1
86
github.com/joho/godotenv v1.5.1
97
github.com/unrolled/secure v1.15.0
108
)
9+
10+
require github.com/go-chi/chi/v5 v5.1.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
github.com/go-chi/chi v1.5.5 h1:vOB/HbEMt9QqBqErz07QehcOKHaWFtuj87tTDVz2qXE=
2-
github.com/go-chi/chi v1.5.5/go.mod h1:C9JqLr3tIYjDOZpzn+BCuxY8z8vmca43EeMgyZt7irw=
3-
github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
4-
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
1+
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
2+
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
53
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
64
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
75
github.com/unrolled/secure v1.15.0 h1:q7x+pdp8jAHnbzxu6UheP8fRlG/rwYTb8TPuQ3rn9Og=

helpers/helpers.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ func GenerateLRC(music types.Music) string {
4040
data.WriteString(fmt.Sprintf("[%s:%s]\n\n", language, music.Language))
4141

4242
for _, lyric := range music.Lyrics {
43-
data.WriteString(fmt.Sprintf("[%s]%s\n", lyric.Time, lyric.Value))
43+
if lyric.Value == "" {
44+
data.WriteString(fmt.Sprintf("[%s]♪\n", lyric.Time))
45+
} else {
46+
data.WriteString(fmt.Sprintf("[%s]%s\n", lyric.Time, lyric.Value))
47+
}
4448
}
4549

4650
return data.String()

web/routes/routes.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"github.com/samocodes/go-lrc/helpers"
1313
"github.com/samocodes/go-lrc/types"
1414

15-
"github.com/go-chi/chi"
16-
"github.com/go-chi/chi/middleware"
17-
"github.com/go-chi/cors"
15+
"github.com/go-chi/chi/v5"
16+
"github.com/go-chi/chi/v5/middleware"
17+
1818
"github.com/unrolled/secure"
1919
)
2020

@@ -25,22 +25,12 @@ func Routes() http.Handler {
2525
FrameDeny: true,
2626
ContentTypeNosniff: true,
2727
BrowserXssFilter: true,
28-
29-
// Allows htmx's script to be loaded
30-
// ContentSecurityPolicy: "default-src 'self'; script-src 'self' https://unpkg.com 'nonce-a23gbfz9e'; style-src 'self';",
3128
})
3229

3330
router := chi.NewRouter()
3431
router.Use(secureMiddleware.Handler)
3532
router.Use(middleware.Recoverer)
3633
router.Use(middleware.Logger)
37-
router.Use(cors.Handler(cors.Options{
38-
AllowedOrigins: []string{"http://*", "https://*"},
39-
AllowedMethods: []string{"GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"},
40-
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
41-
ExposedHeaders: []string{"Link"},
42-
MaxAge: 300,
43-
}))
4434

4535
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
4636
// if request header doesn't accepts text/html, then return a html template
@@ -73,7 +63,7 @@ func Routes() http.Handler {
7363
router.Post("/lrc", func(w http.ResponseWriter, r *http.Request) {
7464
b, err := io.ReadAll(r.Body)
7565
if err != nil {
76-
http.Error(w, "Body was not provided", http.StatusBadRequest)
66+
http.Error(w, "Body was not provided!", http.StatusBadRequest)
7767
return
7868
}
7969

0 commit comments

Comments
 (0)