Skip to content

Commit

Permalink
chore: lo.Must instead of panic and err handling (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww authored Dec 20, 2024
1 parent ab8601e commit 132031c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
9 changes: 3 additions & 6 deletions pkg/backend/elevenlabs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/labstack/echo/v4"
"github.com/moeru-ai/unspeech/pkg/apierrors"
"github.com/nekomeowww/fo"
"github.com/samber/lo"
"github.com/samber/mo"
)

Expand All @@ -21,7 +21,7 @@ type ElevenLabsOptions struct {
}

func elevenlabs(c echo.Context, options FullOptions) mo.Result[any] {
reqURL := fo.May(url.Parse("https://api.elevenlabs.io/v1/text-to-speech")).
reqURL := lo.Must(url.Parse("https://api.elevenlabs.io/v1/text-to-speech")).
JoinPath(options.Voice).
String()

Expand All @@ -30,10 +30,7 @@ func elevenlabs(c echo.Context, options FullOptions) mo.Result[any] {
ModelID: options.Model,
}

payload, err := json.Marshal(values)
if err != nil {
panic(err)
}
payload := lo.Must(json.Marshal(values))

req, err := http.NewRequestWithContext(
c.Request().Context(),
Expand Down
6 changes: 2 additions & 4 deletions pkg/backend/openai.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/labstack/echo/v4"
"github.com/moeru-ai/unspeech/pkg/apierrors"
"github.com/samber/lo"
"github.com/samber/mo"
)

Expand All @@ -21,10 +22,7 @@ func openai(c echo.Context, options FullOptions) mo.Result[any] {
Speed: options.Speed,
}

payload, err := json.Marshal(values)
if err != nil {
panic(err)
}
payload := lo.Must(json.Marshal(values))

req, err := http.NewRequestWithContext(
c.Request().Context(),
Expand Down

0 comments on commit 132031c

Please sign in to comment.