From 2fbc5fa02410e2d3f3a0df8edfd9af95304b3ac5 Mon Sep 17 00:00:00 2001 From: deepzz0 Date: Thu, 29 Apr 2021 11:17:20 +0800 Subject: [PATCH] chore: rename blog->eiblog --- Makefile | 6 +- .../{blog.Dockerfile => eiblog.Dockerfile} | 0 cmd/{blog => eiblog}/main.go | 16 ++--- conf/app.yml | 4 +- pkg/cache/cache.go | 16 ++--- pkg/cache/render/render.go | 4 +- pkg/cache/store/mongodb.go | 6 +- pkg/config/config.go | 16 ++--- pkg/core/backup/api.go | 8 +++ pkg/core/{blog => backup}/docs/docs.go | 2 +- pkg/core/{blog => backup}/docs/swagger.json | 0 pkg/core/{blog => backup}/docs/swagger.yaml | 0 pkg/core/{blog => eiblog}/admin/admin.go | 6 +- pkg/core/{blog => eiblog}/api.go | 4 +- pkg/core/eiblog/docs/docs.go | 65 +++++++++++++++++++ pkg/core/eiblog/docs/swagger.json | 13 ++++ pkg/core/eiblog/docs/swagger.yaml | 10 +++ pkg/core/{blog => eiblog}/file/file.go | 0 pkg/core/{blog => eiblog}/file/timer.go | 12 ++-- pkg/core/{blog => eiblog}/page/be.go | 12 ++-- pkg/core/{blog => eiblog}/page/fe.go | 30 ++++----- pkg/core/{blog => eiblog}/page/page.go | 0 pkg/core/{blog => eiblog}/swag/swag.go | 2 +- pkg/internal/disqus.go | 26 ++++---- pkg/internal/pinger.go | 12 ++-- pkg/internal/qiniu.go | 18 ++--- scripts/dist_tar.sh | 2 +- 27 files changed, 193 insertions(+), 97 deletions(-) rename build/package/{blog.Dockerfile => eiblog.Dockerfile} (100%) rename cmd/{blog => eiblog}/main.go (73%) create mode 100644 pkg/core/backup/api.go rename pkg/core/{blog => backup}/docs/docs.go (95%) rename pkg/core/{blog => backup}/docs/swagger.json (100%) rename pkg/core/{blog => backup}/docs/swagger.yaml (100%) rename pkg/core/{blog => eiblog}/admin/admin.go (99%) rename pkg/core/{blog => eiblog}/api.go (95%) create mode 100644 pkg/core/eiblog/docs/docs.go create mode 100644 pkg/core/eiblog/docs/swagger.json create mode 100644 pkg/core/eiblog/docs/swagger.yaml rename pkg/core/{blog => eiblog}/file/file.go (100%) rename pkg/core/{blog => eiblog}/file/timer.go (93%) rename pkg/core/{blog => eiblog}/page/be.go (96%) rename pkg/core/{blog => eiblog}/page/fe.go (92%) rename pkg/core/{blog => eiblog}/page/page.go (100%) rename pkg/core/{blog => eiblog}/swag/swag.go (84%) diff --git a/Makefile b/Makefile index 13b61ce..a8da9a2 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,9 @@ _app: # below you should write -# run blog app -blog: - @scripts/run_app.sh blog +# run eiblog app +eiblog: + @scripts/run_app.sh eiblog # run backup app backup: diff --git a/build/package/blog.Dockerfile b/build/package/eiblog.Dockerfile similarity index 100% rename from build/package/blog.Dockerfile rename to build/package/eiblog.Dockerfile diff --git a/cmd/blog/main.go b/cmd/eiblog/main.go similarity index 73% rename from cmd/blog/main.go rename to cmd/eiblog/main.go index 5975163..a89d3bd 100644 --- a/cmd/blog/main.go +++ b/cmd/eiblog/main.go @@ -6,11 +6,11 @@ import ( "path/filepath" "github.com/eiblog/eiblog/pkg/config" - "github.com/eiblog/eiblog/pkg/core/blog" - "github.com/eiblog/eiblog/pkg/core/blog/admin" - "github.com/eiblog/eiblog/pkg/core/blog/file" - "github.com/eiblog/eiblog/pkg/core/blog/page" - "github.com/eiblog/eiblog/pkg/core/blog/swag" + "github.com/eiblog/eiblog/pkg/core/eiblog" + "github.com/eiblog/eiblog/pkg/core/eiblog/admin" + "github.com/eiblog/eiblog/pkg/core/eiblog/file" + "github.com/eiblog/eiblog/pkg/core/eiblog/page" + "github.com/eiblog/eiblog/pkg/core/eiblog/swag" "github.com/eiblog/eiblog/pkg/mid" "github.com/gin-gonic/gin" @@ -26,7 +26,7 @@ func main() { } func runHTTPServer(endRun chan bool) { - if !config.Conf.BlogApp.EnableHTTP { + if !config.Conf.EiBlogApp.EnableHTTP { return } @@ -57,14 +57,14 @@ func runHTTPServer(endRun chan bool) { admin.RegisterRoutes(e) // admin router - group := e.Group("/admin", blog.AuthFilter) + group := e.Group("/admin", eiblog.AuthFilter) { page.RegisterRoutesAuthz(group) admin.RegisterRoutesAuthz(group) } // start - address := fmt.Sprintf(":%d", config.Conf.BlogApp.HTTPPort) + address := fmt.Sprintf(":%d", config.Conf.EiBlogApp.HTTPPort) go e.Run(address) fmt.Println("HTTP server running on: " + address) } diff --git a/conf/app.yml b/conf/app.yml index 6d4fa37..a1d6625 100644 --- a/conf/app.yml +++ b/conf/app.yml @@ -3,9 +3,9 @@ database: driver: mongodb source: mongodb://localhost:27017 eshost: http://localhost:9200 -blogapp: +eiblogapp: mode: - name: cmd-blog + name: cmd-eiblog enablehttp: true httpport: 9000 host: example.com diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 87be8c4..a7197e2 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -35,7 +35,7 @@ func init() { // init timezone var err error tools.TimeLocation, err = time.LoadLocation( - config.Conf.BlogApp.General.Timezone) + config.Conf.EiBlogApp.General.Timezone) if err != nil { panic(err) } @@ -106,7 +106,7 @@ func (c *Cache) RepArticle(oldArticle, newArticle *model.Article) { c.ArticlesMap[newArticle.Slug] = newArticle render.GenerateExcerptMarkdown(newArticle) - if newArticle.ID < config.Conf.BlogApp.General.StartID { + if newArticle.ID < config.Conf.EiBlogApp.General.StartID { return } if oldArticle != nil { // 移除旧文章 @@ -179,7 +179,7 @@ func (c *Cache) PageArticleFE(page int, pageSize int) (prev, var l int for l = len(c.Articles); l > 0; l-- { - if c.Articles[l-1].ID >= config.Conf.BlogApp.General.StartID { + if c.Articles[l-1].ID >= config.Conf.EiBlogApp.General.StartID { break } } @@ -293,11 +293,11 @@ func (c *Cache) recalcLinkedList(article *model.Article, del bool) { // 添加操作 _, idx := c.FindArticleByID(article.ID) if idx == 0 && c.Articles[idx+1].ID >= - config.Conf.BlogApp.General.StartID { + config.Conf.EiBlogApp.General.StartID { article.Next = c.Articles[idx+1] c.Articles[idx+1].Prev = article } else if idx > 0 && c.Articles[idx-1].ID >= - config.Conf.BlogApp.General.StartID { + config.Conf.EiBlogApp.General.StartID { article.Prev = c.Articles[idx-1] if c.Articles[idx-1].Next != nil { article.Next = c.Articles[idx-1].Next @@ -395,7 +395,7 @@ func (c *Cache) redelArticle(article *model.Article) { // loadOrInit 读取数据或初始化 func (c *Cache) loadOrInit() error { - blogapp := config.Conf.BlogApp + blogapp := config.Conf.EiBlogApp // blogger blogger := &model.Blogger{ BlogName: strings.Title(blogapp.Account.Username), @@ -552,7 +552,7 @@ func (c *Cache) regeneratePages() { // timerClean 定时清理文章 func (c *Cache) timerClean() { - dur := time.Duration(config.Conf.BlogApp.General.Clean) + dur := time.Duration(config.Conf.EiBlogApp.General.Clean) ticker := time.NewTicker(dur * time.Hour) for range ticker.C { @@ -565,7 +565,7 @@ func (c *Cache) timerClean() { // timerDisqus disqus定时操作 func (c *Cache) timerDisqus() { - dur := time.Duration(config.Conf.BlogApp.Disqus.Interval) + dur := time.Duration(config.Conf.EiBlogApp.Disqus.Interval) ticker := time.NewTicker(dur * time.Hour) for range ticker.C { diff --git a/pkg/cache/render/render.go b/pkg/cache/render/render.go index 480420f..bee034d 100644 --- a/pkg/cache/render/render.go +++ b/pkg/cache/render/render.go @@ -36,7 +36,7 @@ const ( var ( // 渲染markdown操作和截取摘要操作 - regIdentifier = regexp.MustCompile(config.Conf.BlogApp.General.Identifier) + regIdentifier = regexp.MustCompile(config.Conf.EiBlogApp.General.Identifier) // header regHeader = regexp.MustCompile("") ) @@ -60,7 +60,7 @@ func RenderPage(md []byte) []byte { // GenerateExcerptMarkdown 生成预览和描述 func GenerateExcerptMarkdown(article *model.Article) { - blogapp := config.Conf.BlogApp + blogapp := config.Conf.EiBlogApp if strings.HasPrefix(article.Content, blogapp.General.DescPrefix) { index := strings.Index(article.Content, "\r\n") diff --git a/pkg/cache/store/mongodb.go b/pkg/cache/store/mongodb.go index f08bcb3..d988cf5 100644 --- a/pkg/cache/store/mongodb.go +++ b/pkg/cache/store/mongodb.go @@ -117,7 +117,7 @@ func (db *mongodb) LoadInsertAccount(ctx context.Context, collection := db.Database(mongoDBName).Collection(collectionAccount) - filter := bson.M{"username": config.Conf.BlogApp.Account.Username} + filter := bson.M{"username": config.Conf.EiBlogApp.Account.Username} result := collection.FindOne(ctx, filter) err = result.Err() if err != nil { @@ -211,7 +211,7 @@ func (db *mongodb) InsertArticle(ctx context.Context, article *model.Article) er // 可手动分配ID或者分配ID, 占位至起始id for article.ID == 0 { id := db.nextValue(ctx, counterNameArticle) - if id < config.Conf.BlogApp.General.StartID { + if id < config.Conf.EiBlogApp.General.StartID { continue } else { article.ID = id @@ -236,7 +236,7 @@ func (db *mongodb) RemoveArticle(ctx context.Context, id int) error { func (db *mongodb) CleanArticles(ctx context.Context) error { collection := db.Database(mongoDBName).Collection(collectionArticle) - exp := time.Now().Add(time.Duration(config.Conf.BlogApp.General.Trash) * time.Hour) + exp := time.Now().Add(time.Duration(config.Conf.EiBlogApp.General.Trash) * time.Hour) filter := bson.M{"deleted_at": bson.M{"$gt": time.Time{}, "$lt": exp}} _, err := collection.DeleteMany(ctx, filter) return err diff --git a/pkg/config/config.go b/pkg/config/config.go index 332818c..13e4af7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -107,8 +107,8 @@ type Blogger struct { Copyright string `yaml:"copyright"` } -// BlogApp config -type BlogApp struct { +// EiBlogApp config +type EiBlogApp struct { Mode StaticVersion int `yaml:"staticversion"` @@ -125,12 +125,12 @@ type BlogApp struct { // Config app config type Config struct { - RunMode string `yaml:"runmode"` - AppName string `yaml:"appname"` - Database Database `yaml:"database"` - ESHost string `yaml:"eshost"` - BlogApp BlogApp `yaml:"blogapp"` - BackupApp Mode `yaml:"backupapp"` + RunMode string `yaml:"runmode"` + AppName string `yaml:"appname"` + Database Database `yaml:"database"` + ESHost string `yaml:"eshost"` + EiBlogApp EiBlogApp `yaml:"eiblogapp"` + BackupApp Mode `yaml:"backupapp"` } // load config file diff --git a/pkg/core/backup/api.go b/pkg/core/backup/api.go new file mode 100644 index 0000000..8c8daaa --- /dev/null +++ b/pkg/core/backup/api.go @@ -0,0 +1,8 @@ +// Package backup provides ... +package backup + +// @title APP Demo API +// @version 1.0 +// @description This is a sample server celler server. + +// @BasePath /api diff --git a/pkg/core/blog/docs/docs.go b/pkg/core/backup/docs/docs.go similarity index 95% rename from pkg/core/blog/docs/docs.go rename to pkg/core/backup/docs/docs.go index af25249..2d67999 100644 --- a/pkg/core/blog/docs/docs.go +++ b/pkg/core/backup/docs/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2021-04-26 15:31:15.52194 +0800 CST m=+0.022347488 +// 2021-04-29 11:12:59.387582 +0800 CST m=+0.016433684 package docs diff --git a/pkg/core/blog/docs/swagger.json b/pkg/core/backup/docs/swagger.json similarity index 100% rename from pkg/core/blog/docs/swagger.json rename to pkg/core/backup/docs/swagger.json diff --git a/pkg/core/blog/docs/swagger.yaml b/pkg/core/backup/docs/swagger.yaml similarity index 100% rename from pkg/core/blog/docs/swagger.yaml rename to pkg/core/backup/docs/swagger.yaml diff --git a/pkg/core/blog/admin/admin.go b/pkg/core/eiblog/admin/admin.go similarity index 99% rename from pkg/core/blog/admin/admin.go rename to pkg/core/eiblog/admin/admin.go index fa9078c..c688202 100644 --- a/pkg/core/blog/admin/admin.go +++ b/pkg/core/eiblog/admin/admin.go @@ -12,7 +12,7 @@ import ( "github.com/eiblog/eiblog/pkg/cache" "github.com/eiblog/eiblog/pkg/config" - "github.com/eiblog/eiblog/pkg/core/blog" + "github.com/eiblog/eiblog/pkg/core/eiblog" "github.com/eiblog/eiblog/pkg/internal" "github.com/eiblog/eiblog/pkg/model" "github.com/eiblog/eiblog/tools" @@ -67,7 +67,7 @@ func handleAcctLogin(c *gin.Context) { return } // 登录成功 - blog.SetLogin(c, user) + eiblog.SetLogin(c, user) cache.Ei.Account.LoginIP = c.ClientIP() cache.Ei.Account.LoginAt = time.Now() @@ -197,7 +197,7 @@ func handleAPIPostDelete(c *gin.Context) { var ids []int for _, v := range c.PostFormArray("cid[]") { id, err := strconv.Atoi(v) - if err != nil || id < config.Conf.BlogApp.General.StartID { + if err != nil || id < config.Conf.EiBlogApp.General.StartID { responseNotice(c, NoticeNotice, "参数错误", "") return } diff --git a/pkg/core/blog/api.go b/pkg/core/eiblog/api.go similarity index 95% rename from pkg/core/blog/api.go rename to pkg/core/eiblog/api.go index f8cca50..dcf0d28 100644 --- a/pkg/core/blog/api.go +++ b/pkg/core/eiblog/api.go @@ -1,5 +1,5 @@ -// Package blog provides ... -package blog +// Package eiblog provides ... +package eiblog import ( "net/http" diff --git a/pkg/core/eiblog/docs/docs.go b/pkg/core/eiblog/docs/docs.go new file mode 100644 index 0000000..1b91044 --- /dev/null +++ b/pkg/core/eiblog/docs/docs.go @@ -0,0 +1,65 @@ +// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// This file was generated by swaggo/swag at +// 2021-04-29 11:12:59.414073 +0800 CST m=+0.019228292 + +package docs + +import ( + "bytes" + "encoding/json" + + "github.com/alecthomas/template" + "github.com/swaggo/swag" +) + +var doc = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "This is a sample server celler server.", + "title": "APP Demo API", + "contact": {}, + "license": {}, + "version": "1.0" + }, + "host": "{{.Host}}", + "basePath": "/api", + "paths": {} +}` + +type swaggerInfo struct { + Version string + Host string + BasePath string + Schemes []string + Title string + Description string +} + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = swaggerInfo{ Schemes: []string{}} + +type s struct{} + +func (s *s) ReadDoc() string { + t, err := template.New("swagger_info").Funcs(template.FuncMap{ + "marshal": func(v interface {}) string { + a, _ := json.Marshal(v) + return string(a) + }, + }).Parse(doc) + if err != nil { + return doc + } + + var tpl bytes.Buffer + if err := t.Execute(&tpl, SwaggerInfo); err != nil { + return doc + } + + return tpl.String() +} + +func init() { + swag.Register(swag.Name, &s{}) +} diff --git a/pkg/core/eiblog/docs/swagger.json b/pkg/core/eiblog/docs/swagger.json new file mode 100644 index 0000000..ad814c2 --- /dev/null +++ b/pkg/core/eiblog/docs/swagger.json @@ -0,0 +1,13 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a sample server celler server.", + "title": "APP Demo API", + "contact": {}, + "license": {}, + "version": "1.0" + }, + "host": "{{.Host}}", + "basePath": "/api", + "paths": {} +} \ No newline at end of file diff --git a/pkg/core/eiblog/docs/swagger.yaml b/pkg/core/eiblog/docs/swagger.yaml new file mode 100644 index 0000000..43dfcf7 --- /dev/null +++ b/pkg/core/eiblog/docs/swagger.yaml @@ -0,0 +1,10 @@ +basePath: /api +host: '{{.Host}}' +info: + contact: {} + description: This is a sample server celler server. + license: {} + title: APP Demo API + version: "1.0" +paths: {} +swagger: "2.0" diff --git a/pkg/core/blog/file/file.go b/pkg/core/eiblog/file/file.go similarity index 100% rename from pkg/core/blog/file/file.go rename to pkg/core/eiblog/file/file.go diff --git a/pkg/core/blog/file/timer.go b/pkg/core/eiblog/file/timer.go similarity index 93% rename from pkg/core/blog/file/timer.go rename to pkg/core/eiblog/file/timer.go index c8b26f4..2567516 100644 --- a/pkg/core/blog/file/timer.go +++ b/pkg/core/eiblog/file/timer.go @@ -46,8 +46,8 @@ func timerFeed() { params := map[string]interface{}{ "Title": cache.Ei.Blogger.BTitle, "SubTitle": cache.Ei.Blogger.SubTitle, - "Host": config.Conf.BlogApp.Host, - "FeedrURL": config.Conf.BlogApp.FeedRPC.FeedrURL, + "Host": config.Conf.EiBlogApp.Host, + "FeedrURL": config.Conf.EiBlogApp.FeedRPC.FeedrURL, "BuildDate": now.Format(time.RFC1123Z), "Articles": articles, } @@ -75,7 +75,7 @@ func timerSitemap() { params := map[string]interface{}{ "Articles": cache.Ei.Articles, - "Host": config.Conf.BlogApp.Host, + "Host": config.Conf.EiBlogApp.Host, } f, err := os.OpenFile("assets/sitemap.xml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { @@ -101,7 +101,7 @@ func generateOpensearch() { params := map[string]string{ "BTitle": cache.Ei.Blogger.BTitle, "SubTitle": cache.Ei.Blogger.SubTitle, - "Host": config.Conf.BlogApp.Host, + "Host": config.Conf.EiBlogApp.Host, } f, err := os.OpenFile("assets/opensearch.xml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { @@ -124,7 +124,7 @@ func generateRobots() { return } params := map[string]string{ - "Host": config.Conf.BlogApp.Host, + "Host": config.Conf.EiBlogApp.Host, } f, err := os.OpenFile("assets/robots.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { @@ -147,7 +147,7 @@ func generateCrossdomain() { return } params := map[string]string{ - "Host": config.Conf.BlogApp.Host, + "Host": config.Conf.EiBlogApp.Host, } f, err := os.OpenFile("assets/crossdomain.xml", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) if err != nil { diff --git a/pkg/core/blog/page/be.go b/pkg/core/eiblog/page/be.go similarity index 96% rename from pkg/core/blog/page/be.go rename to pkg/core/eiblog/page/be.go index e468c95..2c88913 100644 --- a/pkg/core/blog/page/be.go +++ b/pkg/core/eiblog/page/be.go @@ -13,7 +13,7 @@ import ( "github.com/eiblog/eiblog/pkg/cache" "github.com/eiblog/eiblog/pkg/cache/store" "github.com/eiblog/eiblog/pkg/config" - "github.com/eiblog/eiblog/pkg/core/blog" + "github.com/eiblog/eiblog/pkg/core/eiblog" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" @@ -23,7 +23,7 @@ import ( func baseBEParams(c *gin.Context) gin.H { return gin.H{ "Author": cache.Ei.Account.Username, - "Qiniu": config.Conf.BlogApp.Qiniu, + "Qiniu": config.Conf.EiBlogApp.Qiniu, } } @@ -31,8 +31,8 @@ func baseBEParams(c *gin.Context) gin.H { func handleLoginPage(c *gin.Context) { logout := c.Query("logout") if logout == "true" { - blog.SetLogout(c) - } else if blog.IsLogined(c) { + eiblog.SetLogout(c) + } else if eiblog.IsLogined(c) { c.Redirect(http.StatusFound, "/admin/profile") return } @@ -70,7 +70,7 @@ func handleAdminPost(c *gin.Context) { params["Title"] = "撰写文章 | " + cache.Ei.Blogger.BTitle } params["Path"] = c.Request.URL.Path - params["Domain"] = config.Conf.BlogApp.Host + params["Domain"] = config.Conf.EiBlogApp.Host params["Series"] = cache.Ei.Series var tags []T for tag := range cache.Ei.TagArticles { @@ -104,7 +104,7 @@ func handleAdminPosts(c *gin.Context) { params["KW"] = kw var max int params["List"], max = cache.Ei.PageArticleBE(se, kw, false, false, - pg, config.Conf.BlogApp.General.PageSize) + pg, config.Conf.EiBlogApp.General.PageSize) if pg < max { vals.Set("page", fmt.Sprint(pg+1)) params["Next"] = vals.Encode() diff --git a/pkg/core/blog/page/fe.go b/pkg/core/eiblog/page/fe.go similarity index 92% rename from pkg/core/blog/page/fe.go rename to pkg/core/eiblog/page/fe.go index 3f0e27b..482fd54 100644 --- a/pkg/core/blog/page/fe.go +++ b/pkg/core/eiblog/page/fe.go @@ -26,19 +26,19 @@ func baseFEParams(c *gin.Context) gin.H { cookie, err := c.Request.Cookie("v") if err != nil || cookie.Value != - fmt.Sprint(config.Conf.BlogApp.StaticVersion) { - version = config.Conf.BlogApp.StaticVersion + fmt.Sprint(config.Conf.EiBlogApp.StaticVersion) { + version = config.Conf.EiBlogApp.StaticVersion } return gin.H{ "BlogName": cache.Ei.Blogger.BlogName, "SubTitle": cache.Ei.Blogger.SubTitle, "BTitle": cache.Ei.Blogger.BTitle, "BeiAn": cache.Ei.Blogger.BeiAn, - "Domain": config.Conf.BlogApp.Host, + "Domain": config.Conf.EiBlogApp.Host, "CopyYear": time.Now().Year(), - "Twitter": config.Conf.BlogApp.Twitter, - "Qiniu": config.Conf.BlogApp.Qiniu, - "Disqus": config.Conf.BlogApp.Disqus, + "Twitter": config.Conf.EiBlogApp.Twitter, + "Qiniu": config.Conf.EiBlogApp.Qiniu, + "Disqus": config.Conf.EiBlogApp.Disqus, "Version": version, } } @@ -65,7 +65,7 @@ func handleHomePage(c *gin.Context) { pn = 1 } params["Prev"], params["Next"], params["List"] = cache.Ei.PageArticleFE(pn, - config.Conf.BlogApp.General.PageNum) + config.Conf.EiBlogApp.General.PageNum) renderHTMLHomeLayout(c, "home", params) } @@ -151,7 +151,7 @@ func handleSearchPage(c *gin.Context) { params["Word"] = q vals := c.Request.URL.Query() - result, err := internal.ElasticSearch(q, config.Conf.BlogApp.General.PageNum, start-1) + result, err := internal.ElasticSearch(q, config.Conf.EiBlogApp.General.PageNum, start-1) if err != nil { logrus.Error("HandleSearchPage.ElasticSearch: ", err) } else { @@ -163,17 +163,17 @@ func handleSearchPage(c *gin.Context) { } } params["SearchResult"] = result - if num := start - config.Conf.BlogApp.General.PageNum; num > 0 { + if num := start - config.Conf.EiBlogApp.General.PageNum; num > 0 { vals.Set("start", fmt.Sprint(num)) params["Prev"] = vals.Encode() } - if num := start + config.Conf.BlogApp.General.PageNum; result.Hits.Total >= num { + if num := start + config.Conf.EiBlogApp.General.PageNum; result.Hits.Total >= num { vals.Set("start", fmt.Sprint(num)) params["Next"] = vals.Encode() } } } else { - params["HotWords"] = config.Conf.BlogApp.HotWords + params["HotWords"] = config.Conf.EiBlogApp.HotWords } renderHTMLHomeLayout(c, "search", params) } @@ -324,16 +324,16 @@ func handleBeaconPage(c *gin.Context) { ua := c.Request.UserAgent() vals := c.Request.URL.Query() - vals.Set("v", config.Conf.BlogApp.Google.V) - vals.Set("tid", config.Conf.BlogApp.Google.Tid) - vals.Set("t", config.Conf.BlogApp.Google.T) + vals.Set("v", config.Conf.EiBlogApp.Google.V) + vals.Set("tid", config.Conf.EiBlogApp.Google.Tid) + vals.Set("t", config.Conf.EiBlogApp.Google.T) cookie, _ := c.Cookie("u") vals.Set("cid", cookie) vals.Set("dl", c.Request.Referer()) vals.Set("uip", c.ClientIP()) go func() { - req, err := http.NewRequest("POST", config.Conf.BlogApp.Google.URL, + req, err := http.NewRequest("POST", config.Conf.EiBlogApp.Google.URL, strings.NewReader(vals.Encode())) if err != nil { logrus.Error("HandleBeaconPage.NewRequest: ", err) diff --git a/pkg/core/blog/page/page.go b/pkg/core/eiblog/page/page.go similarity index 100% rename from pkg/core/blog/page/page.go rename to pkg/core/eiblog/page/page.go diff --git a/pkg/core/blog/swag/swag.go b/pkg/core/eiblog/swag/swag.go similarity index 84% rename from pkg/core/blog/swag/swag.go rename to pkg/core/eiblog/swag/swag.go index 5e8b9b2..69fb3f5 100644 --- a/pkg/core/blog/swag/swag.go +++ b/pkg/core/eiblog/swag/swag.go @@ -2,7 +2,7 @@ package swag import ( - _ "github.com/eiblog/eiblog/pkg/core/blog/docs" // docs + _ "github.com/eiblog/eiblog/pkg/core/eiblog/docs" // docs "github.com/gin-gonic/gin" ginSwagger "github.com/swaggo/gin-swagger" diff --git a/pkg/internal/disqus.go b/pkg/internal/disqus.go index 45bbbca..9763676 100644 --- a/pkg/internal/disqus.go +++ b/pkg/internal/disqus.go @@ -24,9 +24,9 @@ const ( ) func checkDisqusConfig() error { - if config.Conf.BlogApp.Disqus.ShortName != "" && - config.Conf.BlogApp.Disqus.PublicKey != "" && - config.Conf.BlogApp.Disqus.AccessToken != "" { + if config.Conf.EiBlogApp.Disqus.ShortName != "" && + config.Conf.EiBlogApp.Disqus.PublicKey != "" && + config.Conf.EiBlogApp.Disqus.AccessToken != "" { return nil } return errors.New("disqus: config incompleted") @@ -49,8 +49,8 @@ func PostsCount(articles map[string]*model.Article) error { } vals := url.Values{} - vals.Set("api_key", config.Conf.BlogApp.Disqus.PublicKey) - vals.Set("forum", config.Conf.BlogApp.Disqus.ShortName) + vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey) + vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName) // batch get var count, index int for _, article := range articles { @@ -128,8 +128,8 @@ func PostsList(slug, cursor string) (*postsListResp, error) { } vals := url.Values{} - vals.Set("api_key", config.Conf.BlogApp.Disqus.PublicKey) - vals.Set("forum", config.Conf.BlogApp.Disqus.ShortName) + vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey) + vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName) vals.Set("thread:ident", "post-"+slug) vals.Set("cursor", cursor) vals.Set("limit", "50") @@ -224,8 +224,8 @@ func PostApprove(post string) error { } vals := url.Values{} - vals.Set("api_key", config.Conf.BlogApp.Disqus.PublicKey) - vals.Set("access_token", config.Conf.BlogApp.Disqus.AccessToken) + vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey) + vals.Set("access_token", config.Conf.EiBlogApp.Disqus.AccessToken) vals.Set("post", post) header := http.Header{"Referer": {"https://disqus.com"}} @@ -263,13 +263,13 @@ func ThreadCreate(article *model.Article, btitle string) error { } vals := url.Values{} - vals.Set("api_key", config.Conf.BlogApp.Disqus.PublicKey) - vals.Set("access_token", config.Conf.BlogApp.Disqus.AccessToken) - vals.Set("forum", config.Conf.BlogApp.Disqus.ShortName) + vals.Set("api_key", config.Conf.EiBlogApp.Disqus.PublicKey) + vals.Set("access_token", config.Conf.EiBlogApp.Disqus.AccessToken) + vals.Set("forum", config.Conf.EiBlogApp.Disqus.ShortName) vals.Set("title", article.Title+" | "+btitle) vals.Set("identifier", "post-"+article.Slug) - urlPath := fmt.Sprintf("https://%s/post/%s.html", config.Conf.BlogApp.Host, article.Slug) + urlPath := fmt.Sprintf("https://%s/post/%s.html", config.Conf.EiBlogApp.Host, article.Slug) vals.Set("url", urlPath) resp, err := httpPost(apiThreadCreate, vals) diff --git a/pkg/internal/pinger.go b/pkg/internal/pinger.go index 5849067..bae3e4e 100644 --- a/pkg/internal/pinger.go +++ b/pkg/internal/pinger.go @@ -16,7 +16,7 @@ import ( // feedrPingFunc http://.superfeedr.com/ var feedrPingFunc = func(btitle, slug string) error { - feedrHost := config.Conf.BlogApp.FeedRPC.FeedrURL + feedrHost := config.Conf.EiBlogApp.FeedRPC.FeedrURL if feedrHost == "" { return nil } @@ -61,15 +61,15 @@ type rpcValue struct { // rpcPingFunc ping rpc var rpcPingFunc = func(btitle, slug string) error { - if len(config.Conf.BlogApp.FeedRPC.PingRPC) == 0 { + if len(config.Conf.EiBlogApp.FeedRPC.PingRPC) == 0 { return nil } param := rpcPingParam{MethodName: "weblogUpdates.extendedPing"} param.Params.Param = [4]rpcValue{ 0: rpcValue{Value: btitle}, - 1: rpcValue{Value: "https://" + config.Conf.BlogApp.Host}, - 2: rpcValue{Value: fmt.Sprintf("https://%s/post/%s.html", config.Conf.BlogApp.Host, slug)}, - 3: rpcValue{Value: "https://" + config.Conf.BlogApp.Host + "/rss.html"}, + 1: rpcValue{Value: "https://" + config.Conf.EiBlogApp.Host}, + 2: rpcValue{Value: fmt.Sprintf("https://%s/post/%s.html", config.Conf.EiBlogApp.Host, slug)}, + 3: rpcValue{Value: "https://" + config.Conf.EiBlogApp.Host + "/rss.html"}, } buf := bytes.Buffer{} buf.WriteString(xml.Header) @@ -80,7 +80,7 @@ var rpcPingFunc = func(btitle, slug string) error { data := buf.Bytes() header := http.Header{} header.Set("Content-Type", "text/xml") - for _, addr := range config.Conf.BlogApp.FeedRPC.PingRPC { + for _, addr := range config.Conf.EiBlogApp.FeedRPC.PingRPC { resp, err := httpPostHeader(addr, data, header) if err != nil { logrus.Error("rpcPingFunc.httpPostHeader: ", err) diff --git a/pkg/internal/qiniu.go b/pkg/internal/qiniu.go index 544de60..202c6ad 100644 --- a/pkg/internal/qiniu.go +++ b/pkg/internal/qiniu.go @@ -15,17 +15,17 @@ import ( // QiniuUpload 上传文件 func QiniuUpload(name string, size int64, data io.Reader) (string, error) { - if config.Conf.BlogApp.Qiniu.AccessKey == "" || - config.Conf.BlogApp.Qiniu.SecretKey == "" { + if config.Conf.EiBlogApp.Qiniu.AccessKey == "" || + config.Conf.EiBlogApp.Qiniu.SecretKey == "" { return "", errors.New("qiniu config error") } key := completeQiniuKey(name) - mac := qbox.NewMac(config.Conf.BlogApp.Qiniu.AccessKey, - config.Conf.BlogApp.Qiniu.SecretKey) + mac := qbox.NewMac(config.Conf.EiBlogApp.Qiniu.AccessKey, + config.Conf.EiBlogApp.Qiniu.SecretKey) // 设置上传策略 putPolicy := &storage.PutPolicy{ - Scope: config.Conf.BlogApp.Qiniu.Bucket, + Scope: config.Conf.EiBlogApp.Qiniu.Bucket, Expires: 3600, InsertOnly: 1, } @@ -46,7 +46,7 @@ func QiniuUpload(name string, size int64, data io.Reader) (string, error) { if err != nil { return "", err } - url := "https://" + config.Conf.BlogApp.Qiniu.Domain + "/" + key + url := "https://" + config.Conf.EiBlogApp.Qiniu.Domain + "/" + key return url, nil } @@ -54,8 +54,8 @@ func QiniuUpload(name string, size int64, data io.Reader) (string, error) { func QiniuDelete(name string) error { key := completeQiniuKey(name) - mac := qbox.NewMac(config.Conf.BlogApp.Qiniu.AccessKey, - config.Conf.BlogApp.Qiniu.SecretKey) + mac := qbox.NewMac(config.Conf.EiBlogApp.Qiniu.AccessKey, + config.Conf.EiBlogApp.Qiniu.SecretKey) // 上传配置 cfg := &storage.Config{ Zone: &storage.ZoneHuadong, @@ -64,7 +64,7 @@ func QiniuDelete(name string) error { // manager bucketManager := storage.NewBucketManager(mac, cfg) // Delete - return bucketManager.Delete(config.Conf.BlogApp.Qiniu.Bucket, key) + return bucketManager.Delete(config.Conf.EiBlogApp.Qiniu.Bucket, key) } // completeQiniuKey 修复路径 diff --git a/scripts/dist_tar.sh b/scripts/dist_tar.sh index ef54042..239603f 100755 --- a/scripts/dist_tar.sh +++ b/scripts/dist_tar.sh @@ -15,7 +15,7 @@ for file in pkg/core/*; do _target="$app-$_tag.$os-$_arch.tar.gz" CGO_ENABLED=0 GOOS=$os GOARCH=$_arch \ go build -o bin/backend "./cmd/$app" - if [ "$app" == "blog" ]; then + if [ "$app" = "eiblog" ]; then tar czf $_target conf website assets bin/backend else tar czf $_target conf bin/backend