Last active
February 11, 2017 20:46
-
-
Save nesv/8a9cc63714434ba19b9b58a6629b85a2 to your computer and use it in GitHub Desktop.
Functional options for nesv/go-dynect
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
package dynect | |
import ( | |
"crypto/tls" | |
"net/http" | |
) | |
type ClientOption func(*Client) | |
func InsecureSkipVerify() ClientOption { | |
return func(c *Client) { | |
if c.transport.TLSClientConfig != nil { | |
c.transport.TLSClientConfig.InsecureSkipVerify = true | |
return | |
} | |
c.transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} | |
} | |
} | |
func NewClient(customerName string, options ...ClientOption) *Client { | |
client := &Client{ | |
CustomerName: customerName, | |
transport: &http.Transport{ | |
Proxy: http.ProxyFromEnvironment, | |
}, | |
} | |
for _, option := range options { | |
option(client) | |
} | |
return client | |
} |
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
package main | |
import "github.com/nesv/go-dynect/dynect" | |
func main() { | |
client := dynect.NewClient("my customer name", dynect.InsecureSkipVerify()) | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment