From 593304a8e2643203488af4e5a14bf86660fd1ca8 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 12 Feb 2023 13:25:26 +0100 Subject: [PATCH] chore: use strings.CutPrefix --- provider/mqtt/client.go | 4 ++-- vehicle/porsche/identity.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/provider/mqtt/client.go b/provider/mqtt/client.go index eb15f5701..afdcaf656 100644 --- a/provider/mqtt/client.go +++ b/provider/mqtt/client.go @@ -52,10 +52,10 @@ const secure = "tls://" // NewClient creates new Mqtt publisher func NewClient(log *util.Logger, broker, user, password, clientID string, qos byte, insecure bool, opts ...Option) (*Client, error) { - isSecure := strings.HasPrefix(broker, secure) + broker, isSecure := strings.CutPrefix(broker, secure) // strip schema as it breaks net.SplitHostPort - broker = util.DefaultPort(strings.TrimPrefix(broker, secure), 1883) + broker = util.DefaultPort(broker, 1883) if isSecure { broker = secure + broker } diff --git a/vehicle/porsche/identity.go b/vehicle/porsche/identity.go index 1c8522e44..49b5bfef3 100644 --- a/vehicle/porsche/identity.go +++ b/vehicle/porsche/identity.go @@ -181,8 +181,8 @@ func (v *Identity) fetchToken(oc *oauth2.Config) (*oauth2.Token, error) { resp.Body.Close() rawQuery := resp.Request.URL.RawQuery - if strings.HasPrefix(resp.Header.Get("Location"), "One-Product-App") { - rawQuery = strings.Replace(resp.Header.Get("Location"), "One-Product-App://porsche-id/oauth2redirect?", "", 1) + if location, ok := strings.CutPrefix(resp.Header.Get("Location"), "One-Product-App://porsche-id/oauth2redirect?"); ok { + rawQuery = location } query, err := url.ParseQuery(rawQuery) if err != nil {