mirror of
https://github.com/shazow/ssh-chat.git
synced 2025-06-06 18:33:05 +03:00
Using bufio instead of ioutil.
This commit is contained in:
parent
580ad79a22
commit
68e82ff115
24
server.go
24
server.go
@ -10,7 +10,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"net/http"
|
"net/http"
|
||||||
"io/ioutil"
|
"bufio"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
@ -313,21 +313,15 @@ func getGithubPubKeys(user string) ([]ssh.PublicKey, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
bodyStr := string(body)
|
|
||||||
|
|
||||||
// More informative error than that from base64 DecodeString
|
|
||||||
if bodyStr == "Not Found" {
|
|
||||||
return nil, fmt.Errorf("No github user %s found", user)
|
|
||||||
}
|
|
||||||
|
|
||||||
pubs := []ssh.PublicKey{}
|
pubs := []ssh.PublicKey{}
|
||||||
for _, key := range strings.SplitN(bodyStr, "\n", -1) {
|
scanner := bufio.NewScanner(resp.Body)
|
||||||
splitKey := strings.SplitN(key, " ", -1)
|
for scanner.Scan() {
|
||||||
|
text := scanner.Text()
|
||||||
|
if text == "Not Found" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
splitKey := strings.SplitN(text, " ", -1)
|
||||||
|
|
||||||
// In case of malformated key
|
// In case of malformated key
|
||||||
if len(splitKey) < 2 {
|
if len(splitKey) < 2 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user