refactor: eiblog

This commit is contained in:
deepzz0
2021-04-26 15:51:16 +08:00
parent bd69c62254
commit 68e01cdf1f
843 changed files with 3606 additions and 1007377 deletions

7
cmd/README.md Normal file
View File

@@ -0,0 +1,7 @@
Main applications for this project.
The directory name for each application should match the name of the executable you want to have (e.g., `/cmd/myapp`).
Don't put a lot of code in the application directory. If you think the code can be imported and used in other projects, then it should live in the `/pkg` directory. If the code is not reusable or if you don't want others to reuse it, put that code in the `/internal` directory. You'll be surprised what others will do, so be explicit about your intentions!
It's common to have a small `main` function that imports and invokes the code from the `/internal` and `/pkg` directories and nothing else.

61
cmd/blog/main.go Normal file
View File

@@ -0,0 +1,61 @@
// Package main provides ...
package main
import (
"fmt"
"path/filepath"
"github.com/eiblog/eiblog/v2/pkg/config"
"github.com/eiblog/eiblog/v2/pkg/core/blog/file"
"github.com/eiblog/eiblog/v2/pkg/core/blog/page"
"github.com/eiblog/eiblog/v2/pkg/core/blog/swag"
"github.com/eiblog/eiblog/v2/pkg/mid"
"github.com/gin-gonic/gin"
)
func main() {
fmt.Println("Hi, it's App Demo")
endRun := make(chan bool, 1)
runHTTPServer(endRun)
<-endRun
}
func runHTTPServer(endRun chan bool) {
if !config.Conf.BlogApp.EnableHTTP {
return
}
if config.Conf.RunMode == config.ModeProd {
gin.SetMode(gin.ReleaseMode)
}
e := gin.Default()
// middleware
e.Use(mid.UserMiddleware())
e.Use(mid.SessionMiddleware(mid.SessionOpts{
Name: "su",
Secure: config.Conf.RunMode == config.ModeProd,
Secret: []byte("ZGlzvcmUoMTAsICI="),
}))
// swag
swag.RegisterRoutes(e)
// static files, page
root := filepath.Join(config.WorkDir, "assets")
e.Static("/static", root)
// frontend pages
page.RegisterRoutes(e)
// static files
file.RegisterRoutes(e)
// api router
// start
address := fmt.Sprintf(":%d", config.Conf.BlogApp.HTTPPort)
go e.Run(address)
fmt.Println("HTTP server running on: " + address)
}