Skip to content

Instantly share code, notes, and snippets.

@nesv
Last active February 11, 2017 20:46
Show Gist options
  • Save nesv/8a9cc63714434ba19b9b58a6629b85a2 to your computer and use it in GitHub Desktop.
Save nesv/8a9cc63714434ba19b9b58a6629b85a2 to your computer and use it in GitHub Desktop.
Functional options for nesv/go-dynect
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
}
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