Commit db4a166b authored by Kirill Smelkov's avatar Kirill Smelkov

X parseQuery -> xurl

parent 31ccdcba
// Copyright (C) 2020-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package xurl complements standard package net/url.
package xurl
import (
"fmt"
"net/url"
)
// ParseQuery parses query string into regular map.
// see also url.ParseQuery
func ParseQuery(query string) (map[string]string, error) {
qv, err := url.ParseQuery(query)
if err != nil {
return nil, err
}
q := map[string]string{}
for k, vv := range qv {
if len(vv) == 0 {
return nil, fmt.Errorf("parameter %q without value", k)
}
if len(vv) != 1 {
return nil, fmt.Errorf("duplicate parameter %q ", k)
}
q[k] = vv[0]
}
return q, nil
}
...@@ -36,15 +36,16 @@ import ( ...@@ -36,15 +36,16 @@ import (
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/go123/xnet" "lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/task"
"lab.nexedi.com/kirr/neo/go/internal/xio"
"lab.nexedi.com/kirr/neo/go/internal/xurl"
"lab.nexedi.com/kirr/neo/go/internal/xzlib" "lab.nexedi.com/kirr/neo/go/internal/xzlib"
"lab.nexedi.com/kirr/neo/go/internal/xzodb" "lab.nexedi.com/kirr/neo/go/internal/xzodb"
"lab.nexedi.com/kirr/neo/go/neo/internal/xsha1" "lab.nexedi.com/kirr/neo/go/neo/internal/xsha1"
"lab.nexedi.com/kirr/neo/go/neo/neonet" "lab.nexedi.com/kirr/neo/go/neo/neonet"
"lab.nexedi.com/kirr/neo/go/neo/proto" "lab.nexedi.com/kirr/neo/go/neo/proto"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/internal/log"
"lab.nexedi.com/kirr/neo/go/internal/task"
"lab.nexedi.com/kirr/neo/go/internal/xio"
) )
// Client is NEO node that talks to NEO cluster and exposes access to it via ZODB interfaces. // Client is NEO node that talks to NEO cluster and exposes access to it via ZODB interfaces.
...@@ -625,7 +626,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) ( ...@@ -625,7 +626,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
} }
cred := u.User.String() cred := u.User.String()
x, err := parseQuery(cred) x, err := xurl.ParseQuery(cred)
if err != nil { if err != nil {
return nil, zodb.InvalidTid, fmt.Errorf("credentials: %s", err) return nil, zodb.InvalidTid, fmt.Errorf("credentials: %s", err)
} }
...@@ -664,7 +665,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) ( ...@@ -664,7 +665,7 @@ func openClientByURL(ctx context.Context, u *url.URL, opt *zodb.DriverOptions) (
return nil, zodb.InvalidTid, fmt.Errorf("cluster name not specified") return nil, zodb.InvalidTid, fmt.Errorf("cluster name not specified")
} }
q, err := parseQuery(u.RawQuery) q, err := xurl.ParseQuery(u.RawQuery)
if err != nil { if err != nil {
return nil, zodb.InvalidTid, err return nil, zodb.InvalidTid, err
} }
......
// Copyright (C) 2017-2020 Nexedi SA and Contributors. // Copyright (C) 2017-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -21,9 +21,7 @@ package neo ...@@ -21,9 +21,7 @@ package neo
import ( import (
"context" "context"
"fmt"
"io" "io"
"net/url"
"lab.nexedi.com/kirr/neo/go/internal/log" "lab.nexedi.com/kirr/neo/go/internal/log"
) )
...@@ -36,23 +34,3 @@ func lclose(ctx context.Context, c io.Closer) { ...@@ -36,23 +34,3 @@ func lclose(ctx context.Context, c io.Closer) {
log.Error(ctx, err) log.Error(ctx, err)
} }
} }
// parseQuery parses query string into regular map.
// see also url.ParseQuery
func parseQuery(query string) (map[string]string, error) {
qv, err := url.ParseQuery(query)
if err != nil {
return nil, err
}
q := map[string]string{}
for k, vv := range qv {
if len(vv) == 0 {
return nil, fmt.Errorf("parameter %q without value", k)
}
if len(vv) != 1 {
return nil, fmt.Errorf("duplicate parameter %q ", k)
}
q[k] = vv[0]
}
return q, nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment