Skip to content

Commit c720f7c

Browse files
committed
Go fmt
1 parent b9bc2db commit c720f7c

File tree

8 files changed

+224
-224
lines changed

8 files changed

+224
-224
lines changed

ISO-8859-1.go

+57-57
Original file line numberDiff line numberDiff line change
@@ -11,81 +11,81 @@ import (
1111
// ISO-8859-1 support
1212

1313
type charsetISO88591er struct {
14-
r io.ByteReader
15-
buf *bytes.Buffer
14+
r io.ByteReader
15+
buf *bytes.Buffer
1616
}
1717

1818
func newCharsetISO88591(r io.Reader) *charsetISO88591er {
19-
buf := bytes.NewBuffer(make([]byte, 0, utf8.UTFMax))
20-
return &charsetISO88591er{r.(io.ByteReader), buf}
19+
buf := bytes.NewBuffer(make([]byte, 0, utf8.UTFMax))
20+
return &charsetISO88591er{r.(io.ByteReader), buf}
2121
}
2222

2323
func (cs *charsetISO88591er) ReadByte() (b byte, err error) {
24-
// http://unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT
25-
// Date: 1999 July 27; Last modified: 27-Feb-2001 05:08
26-
if cs.buf.Len() <= 0 {
27-
r, err := cs.r.ReadByte()
28-
if err != nil {
29-
return 0, err
30-
}
31-
if r < utf8.RuneSelf {
32-
return r, nil
33-
}
34-
cs.buf.WriteRune(rune(r))
35-
}
36-
return cs.buf.ReadByte()
24+
// http://unicode.org/Public/MAPPINGS/ISO8859/8859-1.TXT
25+
// Date: 1999 July 27; Last modified: 27-Feb-2001 05:08
26+
if cs.buf.Len() <= 0 {
27+
r, err := cs.r.ReadByte()
28+
if err != nil {
29+
return 0, err
30+
}
31+
if r < utf8.RuneSelf {
32+
return r, nil
33+
}
34+
cs.buf.WriteRune(rune(r))
35+
}
36+
return cs.buf.ReadByte()
3737
}
3838

3939
func (cs *charsetISO88591er) Read(p []byte) (int, error) {
40-
// Use ReadByte method.
41-
return 0, errors.New("Use ReadByte()")
40+
// Use ReadByte method.
41+
return 0, errors.New("Use ReadByte()")
4242
}
4343

4444
func isCharset(charset string, names []string) bool {
45-
charset = strings.ToLower(charset)
46-
for _, n := range names {
47-
if charset == strings.ToLower(n) {
48-
return true
49-
}
50-
}
51-
return false
45+
charset = strings.ToLower(charset)
46+
for _, n := range names {
47+
if charset == strings.ToLower(n) {
48+
return true
49+
}
50+
}
51+
return false
5252
}
5353

5454
func isCharsetISO88591(charset string) bool {
55-
// http://www.iana.org/assignments/character-sets
56-
// (last updated 2010-11-04)
57-
names := []string{
58-
// Name
59-
"ISO_8859-1:1987",
60-
// Alias (preferred MIME name)
61-
"ISO-8859-1",
62-
// Aliases
63-
"iso-ir-100",
64-
"ISO_8859-1",
65-
"latin1",
66-
"l1",
67-
"IBM819",
68-
"CP819",
69-
"csISOLatin1",
70-
}
71-
return isCharset(charset, names)
55+
// http://www.iana.org/assignments/character-sets
56+
// (last updated 2010-11-04)
57+
names := []string{
58+
// Name
59+
"ISO_8859-1:1987",
60+
// Alias (preferred MIME name)
61+
"ISO-8859-1",
62+
// Aliases
63+
"iso-ir-100",
64+
"ISO_8859-1",
65+
"latin1",
66+
"l1",
67+
"IBM819",
68+
"CP819",
69+
"csISOLatin1",
70+
}
71+
return isCharset(charset, names)
7272
}
7373

7474
func isCharsetUTF8(charset string) bool {
75-
names := []string{
76-
"UTF-8",
77-
// Default
78-
"",
79-
}
80-
return isCharset(charset, names)
75+
names := []string{
76+
"UTF-8",
77+
// Default
78+
"",
79+
}
80+
return isCharset(charset, names)
8181
}
8282

8383
func charsetReader(charset string, input io.Reader) (io.Reader, error) {
84-
switch {
85-
case isCharsetUTF8(charset):
86-
return input, nil
87-
case isCharsetISO88591(charset):
88-
return newCharsetISO88591(input), nil
89-
}
90-
return nil, errors.New("CharsetReader: unexpected charset: " + charset)
91-
}
84+
switch {
85+
case isCharsetUTF8(charset):
86+
return input, nil
87+
case isCharsetISO88591(charset):
88+
return newCharsetISO88591(input), nil
89+
}
90+
return nil, errors.New("CharsetReader: unexpected charset: " + charset)
91+
}

atom.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ func parseAtom(data []byte, read *db) (*Feed, error) {
1515
if err != nil {
1616
return nil, err
1717
}
18-
18+
1919
out := new(Feed)
2020
out.Title = feed.Title
2121
out.Description = feed.Description
2222
out.Link = feed.Link.Href
2323
out.Image = feed.Image.Image()
2424
out.Refresh = time.Now().Add(10 * time.Minute)
25-
25+
2626
if feed.Items == nil {
2727
return nil, fmt.Errorf("Error: no feeds found in %q.", string(data))
2828
}
29-
29+
3030
out.Items = make([]*Item, 0, len(feed.Items))
3131
out.ItemMap = make(map[string]struct{})
32-
32+
3333
// Process items.
3434
for _, item := range feed.Items {
35-
35+
3636
// Skip items already known.
37-
if read.req <- item.ID; <- read.res {
37+
if read.req <- item.ID; <-read.res {
3838
continue
3939
}
40-
40+
4141
next := new(Item)
4242
next.Title = item.Title
4343
next.Content = item.Content
@@ -50,22 +50,22 @@ func parseAtom(data []byte, read *db) (*Feed, error) {
5050
}
5151
next.ID = item.ID
5252
next.Read = false
53-
53+
5454
if next.ID == "" {
5555
fmt.Printf("Warning: Item %q has no ID and will be ignored.\n", next.Title)
5656
continue
5757
}
58-
58+
5959
if _, ok := out.ItemMap[next.ID]; ok {
6060
fmt.Printf("Warning: Item %q has duplicate ID.\n", next.Title)
6161
continue
6262
}
63-
63+
6464
out.Items = append(out.Items, next)
6565
out.ItemMap[next.ID] = struct{}{}
6666
out.Unread++
6767
}
68-
68+
6969
return out, nil
7070
}
7171

@@ -97,7 +97,7 @@ type atomImage struct {
9797
}
9898

9999
type atomLink struct {
100-
Href string `xml:"href,attr"`
100+
Href string `xml:"href,attr"`
101101
}
102102

103103
func (a *atomImage) Image() *Image {

database.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ func init() {
88
}
99

1010
type db struct {
11-
req chan string
12-
res chan bool
11+
req chan string
12+
res chan bool
1313
known map[string]struct{}
1414
}
1515

1616
func (d *db) Run() {
1717
d.known = make(map[string]struct{})
1818
var s string
19-
19+
2020
for {
21-
s = <- d.req
21+
s = <-d.req
2222
if _, ok := d.known[s]; ok {
2323
d.res <- true
2424
} else {

doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func main() {
1919
if err != nil {
2020
// handle error.
2121
}
22-
22+
2323
// ... Some time later ...
24-
24+
2525
err = feed.Update()
2626
if err != nil {
2727
// handle error.

rss 1.0.go

+27-27
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ func parseRSS1(data []byte, read *db) (*Feed, error) {
2020
if feed.Channel == nil {
2121
return nil, fmt.Errorf("Error: no channel found in %q.", string(data))
2222
}
23-
23+
2424
channel := feed.Channel
25-
25+
2626
out := new(Feed)
2727
out.Title = channel.Title
2828
out.Description = channel.Description
@@ -33,43 +33,43 @@ func parseRSS1(data []byte, read *db) (*Feed, error) {
3333
next := time.Now().Add(time.Duration(channel.MinsToLive) * time.Minute)
3434
for _, hour := range channel.SkipHours {
3535
if hour == next.Hour() {
36-
next.Add(time.Duration(60 - next.Minute()) * time.Minute)
36+
next.Add(time.Duration(60-next.Minute()) * time.Minute)
3737
}
3838
}
3939
trying := true
4040
for trying {
4141
trying = false
4242
for _, day := range channel.SkipDays {
4343
if strings.Title(day) == next.Weekday().String() {
44-
next.Add(time.Duration(24 - next.Hour()) * time.Hour)
44+
next.Add(time.Duration(24-next.Hour()) * time.Hour)
4545
trying = true
4646
break
4747
}
4848
}
4949
}
50-
50+
5151
out.Refresh = next
5252
}
53-
53+
5454
if out.Refresh.IsZero() {
5555
out.Refresh = time.Now().Add(10 * time.Minute)
5656
}
57-
57+
5858
if feed.Items == nil {
5959
return nil, fmt.Errorf("Error: no feeds found in %q.", string(data))
6060
}
61-
61+
6262
out.Items = make([]*Item, 0, len(feed.Items))
6363
out.ItemMap = make(map[string]struct{})
64-
64+
6565
// Process items.
6666
for _, item := range feed.Items {
67-
67+
6868
// Skip items already known.
69-
if read.req <- item.ID; <- read.res {
69+
if read.req <- item.ID; <-read.res {
7070
continue
7171
}
72-
72+
7373
next := new(Item)
7474
next.Title = item.Title
7575
next.Content = item.Content
@@ -82,43 +82,43 @@ func parseRSS1(data []byte, read *db) (*Feed, error) {
8282
}
8383
next.ID = item.ID
8484
next.Read = false
85-
85+
8686
if next.ID == "" {
8787
if next.Link == "" {
8888
fmt.Printf("Warning: Item %q has no ID or link and will be ignored.\n", next.Title)
8989
continue
9090
}
9191
next.ID = next.Link
9292
}
93-
93+
9494
if _, ok := out.ItemMap[next.ID]; ok {
9595
fmt.Printf("Warning: Item %q has duplicate ID.\n", next.Title)
9696
continue
9797
}
98-
98+
9999
out.Items = append(out.Items, next)
100100
out.ItemMap[next.ID] = struct{}{}
101101
out.Unread++
102102
}
103-
103+
104104
return out, nil
105105
}
106106

107107
type rss1_0Feed struct {
108-
XMLName xml.Name `xml:"RDF"`
109-
Channel *rss1_0Channel `xml:"channel"`
110-
Items []rss1_0Item `xml:"item"`
108+
XMLName xml.Name `xml:"RDF"`
109+
Channel *rss1_0Channel `xml:"channel"`
110+
Items []rss1_0Item `xml:"item"`
111111
}
112112

113113
type rss1_0Channel struct {
114-
XMLName xml.Name `xml:"channel"`
115-
Title string `xml:"title"`
116-
Description string `xml:"description"`
117-
Link string `xml:"link"`
118-
Image rss1_0Image `xml:"image"`
119-
MinsToLive int `xml:"ttl"`
120-
SkipHours []int `xml:"skipHours>hour"`
121-
SkipDays []string `xml:"skipDays>day"`
114+
XMLName xml.Name `xml:"channel"`
115+
Title string `xml:"title"`
116+
Description string `xml:"description"`
117+
Link string `xml:"link"`
118+
Image rss1_0Image `xml:"image"`
119+
MinsToLive int `xml:"ttl"`
120+
SkipHours []int `xml:"skipHours>hour"`
121+
SkipDays []string `xml:"skipDays>day"`
122122
}
123123

124124
type rss1_0Item struct {

0 commit comments

Comments
 (0)