41 lines
496 B
Go
41 lines
496 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
const (
|
|
URL = iota
|
|
TAG
|
|
DESCRIPTION
|
|
)
|
|
|
|
type Token struct {
|
|
Type int
|
|
Value string
|
|
}
|
|
|
|
func (t Token) String() string {
|
|
return fmt.Sprintf("%v : '%s'", t.Type, t.Value)
|
|
}
|
|
|
|
func Parse(t []Token) Feed {
|
|
var f Feed
|
|
for i := range t {
|
|
token := t[i]
|
|
if token.Type == URL {
|
|
f.URL = token.Value
|
|
}
|
|
|
|
if token.Type == DESCRIPTION {
|
|
f.Description = token.Value
|
|
}
|
|
|
|
if token.Type == TAG {
|
|
f.Tags = append(f.Tags, token.Value)
|
|
}
|
|
}
|
|
|
|
return f
|
|
}
|