Ensure newline

This commit is contained in:
Denis Zheleztsov 2021-04-09 22:04:49 +03:00
parent 2d3ae322e0
commit 1bb5416393
3 changed files with 21 additions and 15 deletions

View File

@ -81,13 +81,8 @@ func (es ESConf) UEHandler(w http.ResponseWriter, r *http.Request) {
LogRequest(r)
ch := make(chan []string)
// Get echolist
go func() {
ch <- es.GetUEchoMessageHashes(e)
}()
messages := <-ch
messages := es.GetUEchoMessageHashes(e)
w.WriteHeader(200)
w.Write([]byte(strings.Join(messages, "\n")))

View File

@ -110,17 +110,18 @@ func (es ESConf) GetEchoMessageHashes(echo string) []string {
log.Error(err.Error())
return hashes
}
defer resp.Body.Close()
content, _ := ioutil.ReadAll(resp.Body)
log.Info(string(content))
content, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error(err.Error())
hashes = append(hashes, "error: Internal error")
return hashes
}
var esr ESSearchResp
err = json.NewDecoder(resp.Body).Decode(&esr)
err = json.Unmarshal(content, &esr)
if err != nil {
b, _ := ioutil.ReadAll(resp.Body)
log.Error(string(b))
log.Error(err.Error())
hashes = append(hashes, "error: Internal error")
return hashes
@ -297,7 +298,7 @@ func (es ESConf) GetUEchoMessageHashes(echoes string) []string {
// Some20SimbolsHash333
for k, v := range eh {
echohashes = append(echohashes, k)
if k == "" {
if k == "" || k == "\n" {
continue
}
for _, e := range v {
@ -308,7 +309,7 @@ func (es ESConf) GetUEchoMessageHashes(echoes string) []string {
}
}
return echohashes
return addNewLineToLastWord(echohashes)
}
// GetXC implements /x/c

View File

@ -11,6 +11,16 @@ import (
"golang.org/x/crypto/bcrypt"
)
func addNewLineToLastWord(slice []string) []string {
l := len(slice) - 1
word := slice[l]
if strings.Contains(word, "\n") {
return slice
}
slice[l] = word + "\n"
return slice
}
func hashAndSalt(authString []byte) string {
hash, err := bcrypt.GenerateFromPassword(authString, bcrypt.MinCost)
if err != nil {