Add Shelly-NG 3nd gen devices (#1682)
This commit is contained in:
parent
8facebd7ad
commit
cfbb2cbca7
7 changed files with 1330 additions and 40 deletions
24
util/basicauth/transport.go
Normal file
24
util/basicauth/transport.go
Normal 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
1113
util/go.sum
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue