-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcassiopeia.go
76 lines (64 loc) · 1.99 KB
/
cassiopeia.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Need comment documentation here
package cassiopeia
import (
"context"
"fmt"
"regexp"
"github.com/helloproclub/cassiopeia/blogger"
"github.com/helloproclub/cassiopeia/hall_of_fame"
)
// I guest this is the main package of this service right?
// so, every interface needed in this package should be declared here(e.g blogger and halloffame)
// we also need to create interface that will be implemented by Cassiopeia
// this package shuld be implemented by cassiopeia, the intereface name is my random thought so i dont realy like it.
// every function on Cassiopeia shoud be listed here first
type ProclubMemberHallofFame interface {
}
// Need comment documentation here
type Cassiopeia struct {
blogger blogger.Blogger
hof hall_of_fame.HallOfFame
}
// Need comment documentation here
func NewCassiopeia(b blogger.Blogger, h hall_of_fame.HallOfFame) (*Cassiopeia, error) {
return &Cassiopeia{
blogger: b,
hof: h,
}, nil
}
// Need comment documentation here
func (c *Cassiopeia) ListPosts(ctx context.Context, label, pageToken string) (blogger.PostList, error) {
var (
err error
postList blogger.PostList
)
if label != "" {
// fetch posts with label
if postList, err = c.blogger.ListPostsByLabel(ctx, label, pageToken); err != nil {
return blogger.PostList{}, err
}
} else {
// fetch posts without label
if postList, err = c.blogger.ListPosts(ctx, pageToken); err != nil {
return blogger.PostList{}, err
}
}
rx := regexp.MustCompile(`\/[0-9]{4}\/[0-9]{2}\/[a-z-]*.html`)
for i, _ := range postList.Items {
postList.Items[i].Path = fmt.Sprintf("/posts%v", rx.FindString(postList.Items[i].URL))
postList.Items[i].URL = ""
postList.Items[i].Content = ""
}
return postList, nil
}
// Need comment documentation here
func (c *Cassiopeia) GetPostByPath(ctx context.Context, path string) (blogger.Post, error) {
var (
err error
post blogger.Post
)
if post, err = c.blogger.GetPostByPath(ctx, path); err != nil {
return blogger.Post{}, err
}
return post, nil
}