Compare commits

..

No commits in common. "a7fab72a1e26dbf33aec6e51d42cf817773c8e7f" and "8e7ff7f39a0b475236b9d747a53896155cf25102" have entirely different histories.

2 changed files with 4 additions and 35 deletions

View File

@ -13,12 +13,11 @@ import (
"time" "time"
) )
const defaultUserAgent = "go-lifx" const UserAgent = "lume"
type ( type (
Client struct { Client struct {
accessToken string accessToken string
userAgent string
Client *http.Client Client *http.Client
} }
@ -71,37 +70,12 @@ var errorMap = map[int]error{
523: errors.New("Something went wrong on LIFX's end"), 523: errors.New("Something went wrong on LIFX's end"),
} }
func NewClient(accessToken string, options ...func(*Client)) *Client { func NewClient(accessToken string) *Client {
var c *Client
tr := &http.Transport{
//TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
}
c = &Client{
accessToken: accessToken,
Client: &http.Client{Transport: tr},
}
for _, option := range options {
option(c)
}
return c
}
func WithUserAgent(userAgent string) func(*Client) {
return func(c *Client) {
c.userAgent = userAgent
}
}
func NewClientWithUserAgent(accessToken string, userAgent string) *Client {
tr := &http.Transport{ tr := &http.Transport{
//TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper), //TLSNextProto: make(map[string]func(authority string, c *tls.Conn) http.RoundTripper),
} }
return &Client{ return &Client{
accessToken: accessToken, accessToken: accessToken,
userAgent: userAgent,
Client: &http.Client{Transport: tr}, Client: &http.Client{Transport: tr},
} }
} }
@ -161,7 +135,7 @@ func (c *Client) NewRequest(method, url string, body io.Reader) (req *http.Reque
} }
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.accessToken)) req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", c.accessToken))
req.Header.Add("Content-Type", "application/json") req.Header.Add("Content-Type", "application/json")
req.Header.Add("User-Agent", c.userAgent) req.Header.Add("User-Agent", UserAgent)
return return
} }

View File

@ -11,8 +11,6 @@ import (
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
) )
const userAgent = "lume"
func init() { func init() {
RegisterCommand("help", Command{ RegisterCommand("help", Command{
Func: HelpCmd, Func: HelpCmd,
@ -223,10 +221,7 @@ func Main(args []string) (int, error) {
command := args[1] command := args[1]
c := lifx.NewClient( c := lifx.NewClient(config.AccessToken)
config.AccessToken,
lifx.WithUserAgent(userAgent),
)
cmdArgs := CmdArgs{ cmdArgs := CmdArgs{
Client: c, Client: c,