chore: use strings.CutPrefix
This commit is contained in:
parent
60ebd9e585
commit
593304a8e2
2 changed files with 4 additions and 4 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue