Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove duplicated code
  • Loading branch information
silvanocerza committed Jan 27, 2022
commit 73dba778762c6a6b1556e13a50c02f9685d20688
9 changes: 3 additions & 6 deletions i18n/cmd/commands/transifex/pull_transifex.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func getLanguages() []string {
os.Exit(1)
}

req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+apiKey)
addHeaders(req)

res, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -118,8 +117,7 @@ func startTranslationDownload(languageCode string) string {
os.Exit(1)
}

req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+apiKey)
addHeaders(req)

res, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -162,8 +160,7 @@ func getDownloadURL(languageCode, downloadID string) string {
os.Exit(1)
}

req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+apiKey)
addHeaders(req)

client := http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
Expand Down
6 changes: 2 additions & 4 deletions i18n/cmd/commands/transifex/push_transifex.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ func uploadSourceFile(resourceFile *paths.Path) string {
os.Exit(1)
}

req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+apiKey)
addHeaders(req)

res, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down Expand Up @@ -122,8 +121,7 @@ func checkUploadStatus(uploadID string) {
os.Exit(1)
}

req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+apiKey)
addHeaders(req)

res, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions i18n/cmd/commands/transifex/transifex.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package transifex

import (
"fmt"
"net/http"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -62,3 +63,8 @@ func preRun(cmd *cobra.Command, args []string) {
os.Exit(1)
}
}

func addHeaders(req *http.Request) {
req.Header.Set("Content-Type", "application/vnd.api+json")
req.Header.Set("Authorization", "Bearer "+apiKey)
}