github.com/lbryio/lbcd@v0.22.119/rpcclient/cookiefile.go (about) 1 // Copyright (c) 2017 The Namecoin developers 2 // Copyright (c) 2019 The btcsuite developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package rpcclient 7 8 import ( 9 "bufio" 10 "fmt" 11 "os" 12 "strings" 13 ) 14 15 func readCookieFile(path string) (username, password string, err error) { 16 f, err := os.Open(path) 17 if err != nil { 18 return 19 } 20 defer f.Close() 21 22 scanner := bufio.NewScanner(f) 23 scanner.Scan() 24 err = scanner.Err() 25 if err != nil { 26 return 27 } 28 s := scanner.Text() 29 30 parts := strings.SplitN(s, ":", 2) 31 if len(parts) != 2 { 32 err = fmt.Errorf("malformed cookie file") 33 return 34 } 35 36 username, password = parts[0], parts[1] 37 return 38 }