/
plugin.go
147 lines (132 loc) · 3.91 KB
/
plugin.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package site
import (
"github.com/gin-gonic/gin"
"github.com/ikeikeikeike/go-sitemap-generator/stm"
"github.com/jinzhu/gorm"
"github.com/kapmahc/fly/plugins/auth"
"github.com/kapmahc/fly/web"
"github.com/kapmahc/fly/web/cache"
"github.com/kapmahc/fly/web/i18n"
"github.com/kapmahc/fly/web/job"
"github.com/kapmahc/fly/web/settings"
"github.com/kapmahc/fly/web/widgets"
"github.com/spf13/viper"
"github.com/unrolled/render"
"golang.org/x/tools/blog/atom"
)
// Plugin plugin
type Plugin struct {
Db *gorm.DB `inject:""`
Jwt *auth.Jwt `inject:""`
Dao *auth.Dao `inject:""`
I18n *i18n.I18n `inject:""`
Settings *settings.Settings `inject:""`
Server *job.Server `inject:""`
Cache *cache.Cache `inject:""`
Wrap *web.Wrap `inject:""`
Render *render.Render `inject:""`
}
// Init load config
func (p *Plugin) Init() {}
// Dashboard dashboard nav
func (p *Plugin) Dashboard(c *gin.Context) []*widgets.Dropdown {
var items []*widgets.Dropdown
if admin, ok := c.Get(auth.IsAdmin); ok && admin.(bool) {
items = append(
items,
widgets.NewDropdown(
"site.dashboard.title",
widgets.NewLink("site.admin.status.title", "/admin/site/status"),
nil,
widgets.NewLink("site.admin.links.index.title", "/admin/links"),
widgets.NewLink("site.admin.cards.index.title", "/admin/cards"),
nil,
widgets.NewLink("site.admin.info.title", "/admin/site/info"),
widgets.NewLink("site.admin.author.title", "/admin/site/author"),
widgets.NewLink("site.admin.seo.title", "/admin/site/seo"),
widgets.NewLink("site.admin.smtp.title", "/admin/site/smtp"),
nil,
widgets.NewLink("site.admin.users.index.title", "/admin/users"),
widgets.NewLink("site.admin.locales.index.title", "/admin/locales"),
widgets.NewLink("site.admin.notices.index.title", "/admin/notices"),
widgets.NewLink("site.admin.leave-words.index.title", "/admin/leave-words"),
widgets.NewLink("site.admin.friend-links.index.title", "/admin/friend-links"),
widgets.NewLink("site.admin.posts.index.title", "/admin/posts"),
),
)
}
return items
}
// Atom rss.atom
func (p *Plugin) Atom(lang string) ([]*atom.Entry, error) {
return []*atom.Entry{}, nil
}
// Sitemap sitemap.xml.gz
func (p *Plugin) Sitemap() ([]stm.URL, error) {
var items []stm.URL
items = append(
items,
stm.URL{"loc": "/leave-words/new"},
stm.URL{"loc": "/notices"},
stm.URL{"loc": "/posts"},
)
var posts []Post
if err := p.Db.Select([]string{"name", "updated_at"}).Find(&posts).Error; err != nil {
return nil, err
}
for _, it := range posts {
items = append(items, stm.URL{"loc": "/posts/show/" + it.Name, "lastmod": it.UpdatedAt})
}
return items, nil
}
// Workers register workers
func (p *Plugin) Workers() map[string]job.Handler {
return map[string]job.Handler{}
}
func init() {
viper.SetDefault("redis", map[string]interface{}{
"host": "localhost",
"port": 6379,
"db": 8,
})
viper.SetDefault("rabbitmq", map[string]interface{}{
"user": "guest",
"password": "guest",
"host": "localhost",
"port": "5672",
"virtual": "fly-dev",
})
viper.SetDefault("database", map[string]interface{}{
"driver": "postgres",
"args": map[string]interface{}{
"host": "localhost",
"port": 5432,
"user": "postgres",
"password": "",
"dbname": "fly_dev",
"sslmode": "disable",
},
"pool": map[string]int{
"max_open": 180,
"max_idle": 6,
},
})
viper.SetDefault("server", map[string]interface{}{
"port": 8080,
"ssl": false,
"name": "localhost",
"theme": "bootstrap",
})
viper.SetDefault("secrets", map[string]interface{}{
"jwt": web.Random(32),
"aes": web.Random(32),
"csrf": web.Random(32),
"session": web.Random(32),
"hmac": web.Random(32),
})
viper.SetDefault("elasticsearch", map[string]interface{}{
"host": "localhost",
"port": 9200,
})
web.Register(&Plugin{})
}