removing useless buffer, changing token type to int constants
This commit is contained in:
16
token.go
16
token.go
@ -4,28 +4,34 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
URL = iota
|
||||
TAG
|
||||
DESCRIPTION
|
||||
)
|
||||
|
||||
type Token struct {
|
||||
Type string
|
||||
Type int
|
||||
Value string
|
||||
}
|
||||
|
||||
func (t Token) String() string {
|
||||
return fmt.Sprintf("%s : '%s'", t.Type, t.Value)
|
||||
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" {
|
||||
if token.Type == URL {
|
||||
f.URL = token.Value
|
||||
}
|
||||
|
||||
if token.Type == "DESC" {
|
||||
if token.Type == DESCRIPTION {
|
||||
f.Description = token.Value
|
||||
}
|
||||
|
||||
if token.Type == "TAG" {
|
||||
if token.Type == TAG {
|
||||
f.Tags = append(f.Tags, token.Value)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user