Skip to content

Commit

Permalink
feat: add http transport options (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeGorbanev authored Sep 6, 2024
1 parent f6b74b8 commit 7213abc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 8 deletions.
8 changes: 8 additions & 0 deletions internal/apple/client_option.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package apple

import "net/http"

type ClientOption func(client *HTTPClient)

func WithWebPlayerURL(url string) ClientOption {
Expand All @@ -13,3 +15,9 @@ func WithAPIURL(url string) ClientOption {
client.apiURL = url
}
}

func WithHTTPTransport(transport *http.Transport) ClientOption {
return func(client *HTTPClient) {
client.httpClient.Transport = transport
}
}
8 changes: 8 additions & 0 deletions internal/spotify/client_option.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package spotify

import "net/http"

type ClientOption func(client *HTTPClient)

func WithAuthURL(url string) ClientOption {
Expand All @@ -13,3 +15,9 @@ func WithAPIURL(url string) ClientOption {
client.apiURL = url
}
}

func WithHTTPTransport(transport *http.Transport) ClientOption {
return func(client *HTTPClient) {
client.httpClient.Transport = transport
}
}
8 changes: 8 additions & 0 deletions internal/yandex/client_option.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package yandex

import "net/http"

type ClientOption func(client *HTTPClient)

func WithAPIURL(url string) ClientOption {
return func(client *HTTPClient) {
client.apiURL = url
}
}

func WithHTTPTransport(transport *http.Transport) ClientOption {
return func(client *HTTPClient) {
client.httpClient.Transport = transport
}
}
8 changes: 0 additions & 8 deletions internal/youtube/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ type HTTPClient struct {
httpClient *http.Client
}

type ClientOption func(client *HTTPClient)

func WithAPIURL(url string) ClientOption {
return func(client *HTTPClient) {
client.apiURL = url
}
}

type getSnippetResponse struct {
Items []*getSnippetItem `json:"items"`
}
Expand Down
17 changes: 17 additions & 0 deletions internal/youtube/client_option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package youtube

import "net/http"

type ClientOption func(client *HTTPClient)

func WithAPIURL(url string) ClientOption {
return func(client *HTTPClient) {
client.apiURL = url
}
}

func WithHTTPTransport(transport *http.Transport) ClientOption {
return func(client *HTTPClient) {
client.httpClient.Transport = transport
}
}
26 changes: 26 additions & 0 deletions registry_options.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package streamnx

import (
"net/http"

"github.com/GeorgeGorbanev/streamnx/internal/apple"
"github.com/GeorgeGorbanev/streamnx/internal/spotify"
"github.com/GeorgeGorbanev/streamnx/internal/translator"
Expand Down Expand Up @@ -64,3 +66,27 @@ func WithYoutubeAPIURL(url string) RegistryOption {
r.clientOptions.youtube = append(r.clientOptions.youtube, youtube.WithAPIURL(url))
}
}

func WithAppleHTTPTransport(transport *http.Transport) RegistryOption {
return func(r *Registry) {
r.clientOptions.apple = append(r.clientOptions.apple, apple.WithHTTPTransport(transport))
}
}

func WithSpotifyHTTPTransport(transport *http.Transport) RegistryOption {
return func(r *Registry) {
r.clientOptions.spotify = append(r.clientOptions.spotify, spotify.WithHTTPTransport(transport))
}
}

func WithYandexHTTPTransport(transport *http.Transport) RegistryOption {
return func(r *Registry) {
r.clientOptions.yandex = append(r.clientOptions.yandex, yandex.WithHTTPTransport(transport))
}
}

func WithYoutubeHTTPTransport(transport *http.Transport) RegistryOption {
return func(r *Registry) {
r.clientOptions.youtube = append(r.clientOptions.youtube, youtube.WithHTTPTransport(transport))
}
}

0 comments on commit 7213abc

Please sign in to comment.