GraphQL API and utilities for the rpdata project
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
package mirclike
import ( "errors" "strings" "time"
"git.aiterp.net/rpdata/api/models" )
// ErrEmptyLog is returned by ParseLog if there are no (valid) posts in the log.
var ErrEmptyLog = errors.New("No valid posts found in log")
// ParseLog parses the log and returns the things that can be gleamed from them.
func ParseLog(data string, date time.Time, strict bool) (models.Log, []models.Post, error) { lines := strings.Split(data, "\n") posts := make([]models.Post, 0, len(lines)) prev := models.Post{}
for _, line := range lines { line = strings.Trim(line, "\r\t ") if len(line) < 1 { continue }
post, err := ParsePost(line, date, prev) if err != nil { if strict { return models.Log{}, nil, err }
continue }
posts = append(posts, post) prev = post }
if len(posts) == 0 { return models.Log{}, nil, ErrEmptyLog }
log := models.Log{ Date: posts[0].Time, }
return log, posts, nil }
|