rpcclient: Read first line of cookie instead of trimming space
This commit is contained in:
parent
e6f163e61e
commit
6d521ff8cd
1 changed files with 12 additions and 3 deletions
|
@ -6,18 +6,27 @@
|
||||||
package rpcclient
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func readCookieFile(path string) (username, password string, err error) {
|
func readCookieFile(path string) (username, password string, err error) {
|
||||||
b, err := ioutil.ReadFile(path)
|
f, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
scanner.Scan()
|
||||||
|
err = scanner.Err()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s := scanner.Text()
|
||||||
|
|
||||||
s := strings.TrimSpace(string(b))
|
|
||||||
parts := strings.SplitN(s, ":", 2)
|
parts := strings.SplitN(s, ":", 2)
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
err = fmt.Errorf("malformed cookie file")
|
err = fmt.Errorf("malformed cookie file")
|
||||||
|
|
Loading…
Reference in a new issue