mirror of
https://github.com/foomo/contentserver.git
synced 2025-10-16 12:25:44 +00:00
feat: make http transport client exchangeable
This commit is contained in:
parent
ae29f1060c
commit
93fcca1a5f
@ -1,6 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/foomo/contentserver/content"
|
||||
@ -18,16 +19,26 @@ func NewClient(
|
||||
server string,
|
||||
connectionPoolSize int,
|
||||
waitTimeout time.Duration,
|
||||
) (c *Client, err error) {
|
||||
return NewClientWithTransport(NewSocketTransport(server, connectionPoolSize, waitTimeout))
|
||||
}
|
||||
|
||||
func NewClientWithTransport(
|
||||
transport transport,
|
||||
) (c *Client, err error) {
|
||||
c = &Client{
|
||||
t: newSocketTransport(server, connectionPoolSize, waitTimeout),
|
||||
t: transport,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func NewHTTPClient(server string) (c *Client, err error) {
|
||||
return NewHTTPClientWithTransport(NewHTTPTransport(server, http.DefaultClient))
|
||||
}
|
||||
|
||||
func NewHTTPClientWithTransport(transport transport) (c *Client, err error) {
|
||||
c = &Client{
|
||||
t: newHTTPTransport(server),
|
||||
t: transport,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@ -14,10 +14,10 @@ type httpTransport struct {
|
||||
endpoint string
|
||||
}
|
||||
|
||||
func newHTTPTransport(server string) transport {
|
||||
func NewHTTPTransport(server string, client *http.Client) transport {
|
||||
return &httpTransport{
|
||||
endpoint: server,
|
||||
client: http.DefaultClient,
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ type socketTransport struct {
|
||||
connPool *connectionPool
|
||||
}
|
||||
|
||||
func newSocketTransport(server string, connectionPoolSize int, waitTimeout time.Duration) transport {
|
||||
func NewSocketTransport(server string, connectionPoolSize int, waitTimeout time.Duration) transport {
|
||||
return &socketTransport{
|
||||
connPool: newConnectionPool(server, connectionPoolSize, waitTimeout),
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user