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
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/foomo/contentserver/content"
|
"github.com/foomo/contentserver/content"
|
||||||
@ -18,16 +19,26 @@ func NewClient(
|
|||||||
server string,
|
server string,
|
||||||
connectionPoolSize int,
|
connectionPoolSize int,
|
||||||
waitTimeout time.Duration,
|
waitTimeout time.Duration,
|
||||||
|
) (c *Client, err error) {
|
||||||
|
return NewClientWithTransport(NewSocketTransport(server, connectionPoolSize, waitTimeout))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClientWithTransport(
|
||||||
|
transport transport,
|
||||||
) (c *Client, err error) {
|
) (c *Client, err error) {
|
||||||
c = &Client{
|
c = &Client{
|
||||||
t: newSocketTransport(server, connectionPoolSize, waitTimeout),
|
t: transport,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHTTPClient(server string) (c *Client, err error) {
|
func NewHTTPClient(server string) (c *Client, err error) {
|
||||||
|
return NewHTTPClientWithTransport(NewHTTPTransport(server, http.DefaultClient))
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHTTPClientWithTransport(transport transport) (c *Client, err error) {
|
||||||
c = &Client{
|
c = &Client{
|
||||||
t: newHTTPTransport(server),
|
t: transport,
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,10 @@ type httpTransport struct {
|
|||||||
endpoint string
|
endpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHTTPTransport(server string) transport {
|
func NewHTTPTransport(server string, client *http.Client) transport {
|
||||||
return &httpTransport{
|
return &httpTransport{
|
||||||
endpoint: server,
|
endpoint: server,
|
||||||
client: http.DefaultClient,
|
client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,7 @@ type socketTransport struct {
|
|||||||
connPool *connectionPool
|
connPool *connectionPool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSocketTransport(server string, connectionPoolSize int, waitTimeout time.Duration) transport {
|
func NewSocketTransport(server string, connectionPoolSize int, waitTimeout time.Duration) transport {
|
||||||
return &socketTransport{
|
return &socketTransport{
|
||||||
connPool: newConnectionPool(server, connectionPoolSize, waitTimeout),
|
connPool: newConnectionPool(server, connectionPoolSize, waitTimeout),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user