fetcher/idec/parser.go
Denis Zheleztsov d826a868b9 Switch to go-idec
Added Tags, Repto and address fields.
Fix content-type issues
2017-12-07 17:07:46 +03:00

50 lines
857 B
Go

package idec
import (
"strconv"
"strings"
idec "github.com/Difrex/go-idec"
)
// ParseMessage ...
func ParseMessage(message string) (Message, error) {
var m Message
msg, err := idec.ParseMessage(message)
if err != nil {
return m, err
}
m.Tags = msg.Tags.II
m.Echo = msg.Echo
m.Timestamp = msg.Timestamp
m.From = msg.From
m.Address = msg.Address
m.To = msg.To
m.Subg = msg.Subg
m.Body = msg.Body
m.Repto = msg.Tags.Repto
m.ID = msg.ID
return m, err
}
// ParseEchoList parse /list.txt
func ParseEchoList(list string) ([]Echo, error) {
var echoes []Echo
for _, e := range strings.Split(list, "\n") {
desc := strings.Split(e, ":")
if len(desc) <= 1 {
break
}
count, err := strconv.Atoi(desc[1])
if err != nil {
return echoes, err
}
echoes = append(echoes, Echo{desc[0], count, desc[2]})
}
return echoes, nil
}