Add Shelly-NG 3nd gen devices (#1682)

This commit is contained in:
Markus Thierolf 2021-10-03 11:11:47 +02:00 • committed by GitHub
parent 8facebd7ad
commit cfbb2cbca7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1330 additions and 40 deletions

View file

@ -0,0 +1,24 @@
package basicauth
import (
"encoding/base64"
"net/http"
)
type transport struct {
header string
base http.RoundTripper
}
// NewTransport creates an http transport performing basic auth
func NewTransport(user, password string, base http.RoundTripper) http.RoundTripper {
return &transport{
header: "Basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+password)),
base: base,
}
}
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Set("Authorization", t.header)
return t.base.RoundTrip(req)
}

1113
util/go.sum Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/url"
"strings"
)
// DefaultPort appends given port to connection if not specified
@ -19,6 +20,9 @@ func DefaultPort(conn string, port int) string {
func DefaultScheme(uri string, scheme string) string {
u, err := url.Parse(uri)
if err != nil {
if strings.HasSuffix(err.Error(), "first path segment in URL cannot contain colon") {
return fmt.Sprintf("%s://%s", scheme, uri)
}
return uri
}