-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kaneshin/feature/imageurl
Add feature to parse image URI using http client
- Loading branch information
Showing
9 changed files
with
251 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package pigeon | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/kaneshin/pigeon/credentials" | ||
) | ||
|
||
type ( | ||
// A Config provides service configuration for service clients. By default, | ||
// all clients will use the {defaults.DefaultConfig} structure. | ||
Config struct { | ||
// The credentials object to use when signing requests. | ||
// Defaults to application credentials file. | ||
Credentials *credentials.Credentials | ||
|
||
// The HTTP client to use when sending requests. | ||
// Defaults to `http.DefaultClient`. | ||
HTTPClient *http.Client | ||
} | ||
) | ||
|
||
// NewConfig returns a pointer of new Config objects. | ||
func NewConfig() *Config { | ||
return &Config{} | ||
} | ||
|
||
// WithCredentials sets a config Credentials value returning a Config pointer | ||
// for chaining. | ||
func (c *Config) WithCredentials(creds *credentials.Credentials) *Config { | ||
c.Credentials = creds | ||
return c | ||
} | ||
|
||
// WithHTTPClient sets a config HTTPClient value returning a Config pointer | ||
// for chaining. | ||
func (c *Config) WithHTTPClient(client *http.Client) *Config { | ||
c.HTTPClient = client | ||
return c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package pigeon | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/kaneshin/pigeon/credentials" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
conf := NewConfig() | ||
assert.NotNil(conf) | ||
assert.Nil(conf.Credentials) | ||
assert.Nil(conf.HTTPClient) | ||
|
||
creds := credentials.NewApplicationCredentials("") | ||
client := http.DefaultClient | ||
conf.WithCredentials(creds). | ||
WithHTTPClient(client) | ||
assert.NotNil(conf.Credentials) | ||
assert.NotNil(conf.HTTPClient) | ||
} |
Oops, something went wrong.