mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 13:52:26 +08:00
refactor: eiblog
This commit is contained in:
7
cmd/README.md
Normal file
7
cmd/README.md
Normal 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
61
cmd/blog/main.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user