diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 5287089..da4b89c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,5 +1,7 @@ builds: - main: ./cmd/unspeech + ldflags: + - -X main.version={{.Version}} # remove 386 goarch: - amd64 diff --git a/Dockerfile b/Dockerfile index d1fa7eb..d9f0476 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,9 @@ RUN go mod download COPY . . -RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -o ./result/unspeech ./cmd/unspeech +ARG VERSION=0.0.0 + +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -ldflags="-X main.version=${VERSION}" -o ./result/unspeech ./cmd/unspeech # https://github.com/GoogleContainerTools/distroless FROM gcr.io/distroless/static-debian12 AS app diff --git a/cmd/unspeech/main.go b/cmd/unspeech/main.go index 08a3957..539fbfb 100644 --- a/cmd/unspeech/main.go +++ b/cmd/unspeech/main.go @@ -14,11 +14,12 @@ import ( "github.com/moeru-ai/unspeech/pkg/ho" ) +var version = "0.0.0" + func main() { rootCmd := &cobra.Command{ - Use: "unspeech", - // TODO: set version - Version: "0.0.0", + Use: "unspeech", + Version: version, RunE: func(cmd *cobra.Command, args []string) error { slog.SetDefault(slog.New(tint.NewHandler(os.Stdout, nil))) diff --git a/internal/middlewares/error_handler.go b/internal/middlewares/error_handler.go index a93fbe8..a914a79 100644 --- a/internal/middlewares/error_handler.go +++ b/internal/middlewares/error_handler.go @@ -23,8 +23,9 @@ func HandleErrors() echo.MiddlewareFunc { slog.Error("unknown error responded", slog.Any("error", err.Error())) } if 500 >= errResp.Status || errResp.Status < 600 { - attrs := make([]slog.Attr, 0) - attrs = append(attrs, logs.Caller(errResp.Caller())...) + callerAttrs := logs.Caller(errResp.Caller()) + attrs := make([]slog.Attr, 0, len(callerAttrs)+1) + attrs = append(attrs, callerAttrs...) attrs = append(attrs, slog.Any("error", errResp.Error())) slog.Error("error occurred during request", lo.ToAnySlice(attrs)...) } diff --git a/pkg/backend/doubao/voices.go b/pkg/backend/doubao/voices.go index ba6659c..a7abb23 100644 --- a/pkg/backend/doubao/voices.go +++ b/pkg/backend/doubao/voices.go @@ -39,6 +39,7 @@ func HandleVoices(c echo.Context, options mo.Option[types.VoicesRequestOptions]) voices := make([]types.Voice, 0, len(voicesResponse)) for _, voice := range voicesResponse { + //nolint:mnd voices = append(voices, types.Voice{ ID: voice.Voice, Name: voice.Name, diff --git a/pkg/backend/microsoft/speech.go b/pkg/backend/microsoft/speech.go index bae7544..45fe0eb 100644 --- a/pkg/backend/microsoft/speech.go +++ b/pkg/backend/microsoft/speech.go @@ -35,12 +35,12 @@ type ssml struct { } type extraBody struct { - DisableSSML mo.Option[bool] `json:"disable_ssml,omitempty"` + DisableSSML mo.Option[bool] `json:"disable_ssml,omitzero"` Region string `json:"region"` - DeploymentID mo.Option[string] `json:"deployment_id,omitempty"` - Lang mo.Option[string] `json:"lang,omitempty"` - Gender mo.Option[string] `json:"gender,omitempty"` - SampleRate mo.Option[uint] `json:"sample_rate,omitempty"` + DeploymentID mo.Option[string] `json:"deployment_id,omitzero"` + Lang mo.Option[string] `json:"lang,omitzero"` + Gender mo.Option[string] `json:"gender,omitzero"` + SampleRate mo.Option[uint] `json:"sample_rate,omitzero"` } var ( diff --git a/sdk/typescript/tsdown.config.ts b/sdk/typescript/tsdown.config.ts index 09a3ec5..16cf001 100644 --- a/sdk/typescript/tsdown.config.ts +++ b/sdk/typescript/tsdown.config.ts @@ -6,5 +6,5 @@ export default defineConfig({ dts: true, entry: [join('src', 'index.ts')], format: 'esm', - tsconfig: 'tsconfig.lib.json', + tsconfig: 'tsconfig.json', })