Compare commits
No commits in common. "main" and "v1.9.4" have entirely different histories.
8 changed files with 23 additions and 117 deletions
|
|
@ -54,11 +54,7 @@ func (c *Context) Next() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) prepare(ctx *Context) {
|
func (c *Context) prepare(ctx *Context) {
|
||||||
// Only parse multipart form if it hasn't been parsed already
|
ctx.Request.httpRequest.ParseMultipartForm(int64(app.Config.Request.MaxUploadFileSize))
|
||||||
// This prevents race conditions when multiple goroutines might access the same request
|
|
||||||
if ctx.Request.httpRequest.MultipartForm == nil {
|
|
||||||
ctx.Request.httpRequest.ParseMultipartForm(int64(app.Config.Request.MaxUploadFileSize))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) GetPathParam(key string) interface{} {
|
func (c *Context) GetPathParam(key string) interface{} {
|
||||||
|
|
|
||||||
103
core.go
103
core.go
|
|
@ -6,7 +6,6 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
@ -52,18 +51,12 @@ type configContainer struct {
|
||||||
|
|
||||||
// App is a struct representing the main application container and its core components.
|
// App is a struct representing the main application container and its core components.
|
||||||
type App struct {
|
type App struct {
|
||||||
t int // for tracking hooks (deprecated - maintained for backward compatibility)
|
t int // for tracking hooks
|
||||||
chain *chain
|
chain *chain
|
||||||
hooks *Hooks
|
hooks *Hooks
|
||||||
Config *configContainer
|
Config *configContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestContext holds request-specific chain execution state
|
|
||||||
type requestContext struct {
|
|
||||||
chainIndex int
|
|
||||||
chainNodes []interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// app is a global instance of the App structure used to manage application configuration and lifecycle.
|
// app is a global instance of the App structure used to manage application configuration and lifecycle.
|
||||||
var app *App
|
var app *App
|
||||||
|
|
||||||
|
|
@ -120,26 +113,6 @@ func (app *App) Run(router *httprouter.Router) {
|
||||||
router.ServeFiles("/public/*filepath", http.Dir("storage/public"))
|
router.ServeFiles("/public/*filepath", http.Dir("storage/public"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if app engine is enable
|
|
||||||
AppEnableStr := os.Getenv("APP_ENABLE")
|
|
||||||
if "" == AppEnableStr {
|
|
||||||
AppEnableStr = "false"
|
|
||||||
}
|
|
||||||
AppEnable, _ := strconv.ParseBool(AppEnableStr)
|
|
||||||
if AppEnable {
|
|
||||||
router.ServeFiles("/app/*filepath", http.Dir("storage/app"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if app engine is enable
|
|
||||||
CDNEnableStr := os.Getenv("CDN_ENABLE")
|
|
||||||
if "" == CDNEnableStr {
|
|
||||||
CDNEnableStr = "false"
|
|
||||||
}
|
|
||||||
CDNEnable, _ := strconv.ParseBool(CDNEnableStr)
|
|
||||||
if CDNEnable {
|
|
||||||
router.ServeFiles("/cdn/*filepath", http.Dir("storage/cdn"))
|
|
||||||
}
|
|
||||||
|
|
||||||
useHttpsStr := os.Getenv("App_USE_HTTPS")
|
useHttpsStr := os.Getenv("App_USE_HTTPS")
|
||||||
if useHttpsStr == "" {
|
if useHttpsStr == "" {
|
||||||
useHttpsStr = "false"
|
useHttpsStr = "false"
|
||||||
|
|
@ -238,25 +211,10 @@ func (app *App) RegisterRoutes(routes []Route, router *httprouter.Router) *httpr
|
||||||
// makeHTTPRouterHandlerFunc creates an httprouter.Handle that handles HTTP requests with the specified controller and hooks.
|
// makeHTTPRouterHandlerFunc creates an httprouter.Handle that handles HTTP requests with the specified controller and hooks.
|
||||||
func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Handle {
|
func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Handle {
|
||||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||||
// Create request-specific chain state
|
|
||||||
reqCtx := &requestContext{
|
|
||||||
chainIndex: 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepare the chain nodes for this request
|
|
||||||
mw := app.hooks.GetHooks()
|
|
||||||
for _, v := range mw {
|
|
||||||
reqCtx.chainNodes = append(reqCtx.chainNodes, v)
|
|
||||||
}
|
|
||||||
rhs := app.combHandlers(h, ms)
|
|
||||||
for _, v := range rhs {
|
|
||||||
reqCtx.chainNodes = append(reqCtx.chainNodes, v)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store chain state in request context
|
|
||||||
ctx := &Context{
|
ctx := &Context{
|
||||||
Request: &Request{
|
Request: &Request{
|
||||||
httpRequest: r.WithContext(context.WithValue(r.Context(), "goffeeChain", reqCtx)),
|
httpRequest: r,
|
||||||
httpPathParams: ps,
|
httpPathParams: ps,
|
||||||
},
|
},
|
||||||
Response: &Response{
|
Response: &Response{
|
||||||
|
|
@ -279,16 +237,10 @@ func (app *App) makeHTTPRouterHandlerFunc(h Controller, ms []Hook) httprouter.Ha
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.prepare(ctx)
|
ctx.prepare(ctx)
|
||||||
|
rhs := app.combHandlers(h, ms)
|
||||||
// Execute the first handler in the chain
|
app.prepareChain(rhs)
|
||||||
if len(reqCtx.chainNodes) > 0 {
|
app.t = 0
|
||||||
n := reqCtx.chainNodes[0]
|
app.chain.execute(ctx)
|
||||||
if f, ok := n.(Hook); ok {
|
|
||||||
f(ctx)
|
|
||||||
} else if ff, ok := n.(Controller); ok {
|
|
||||||
ff(ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, header := range ctx.Response.headers {
|
for _, header := range ctx.Response.headers {
|
||||||
w.Header().Add(header.key, header.val)
|
w.Header().Add(header.key, header.val)
|
||||||
|
|
@ -391,30 +343,16 @@ func UseHook(mw Hook) {
|
||||||
|
|
||||||
// Next advances to the next middleware or controller in the chain and invokes it with the given context if available.
|
// Next advances to the next middleware or controller in the chain and invokes it with the given context if available.
|
||||||
func (app *App) Next(c *Context) {
|
func (app *App) Next(c *Context) {
|
||||||
// Get request-specific chain state from context
|
app.t = app.t + 1
|
||||||
if reqCtx, ok := c.Request.httpRequest.Context().Value("goffeeChain").(*requestContext); ok {
|
n := app.chain.getByIndex(app.t)
|
||||||
reqCtx.chainIndex++
|
if n != nil {
|
||||||
if reqCtx.chainIndex < len(reqCtx.chainNodes) {
|
f, ok := n.(Hook)
|
||||||
n := reqCtx.chainNodes[reqCtx.chainIndex]
|
if ok {
|
||||||
if f, ok := n.(Hook); ok {
|
f(c)
|
||||||
f(c)
|
} else {
|
||||||
} else if ff, ok := n.(Controller); ok {
|
ff, ok := n.(Controller)
|
||||||
ff(c)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Fallback to old behavior (not thread-safe)
|
|
||||||
app.t = app.t + 1
|
|
||||||
n := app.chain.getByIndex(app.t)
|
|
||||||
if n != nil {
|
|
||||||
f, ok := n.(Hook)
|
|
||||||
if ok {
|
if ok {
|
||||||
f(c)
|
ff(c)
|
||||||
} else {
|
|
||||||
ff, ok := n.(Controller)
|
|
||||||
if ok {
|
|
||||||
ff(c)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -452,17 +390,6 @@ func (app *App) prepareChain(hs []interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareRequestChain prepares a request-specific chain to avoid race conditions
|
|
||||||
func (app *App) prepareRequestChain(requestChain *chain, hs []interface{}) {
|
|
||||||
mw := app.hooks.GetHooks()
|
|
||||||
for _, v := range mw {
|
|
||||||
requestChain.nodes = append(requestChain.nodes, v)
|
|
||||||
}
|
|
||||||
for _, v := range hs {
|
|
||||||
requestChain.nodes = append(requestChain.nodes, v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// execute executes the first node in the chain, invoking it as either a Hook or Controller if applicable.
|
// execute executes the first node in the chain, invoking it as either a Hook or Controller if applicable.
|
||||||
func (cn *chain) execute(ctx *Context) {
|
func (cn *chain) execute(ctx *Context) {
|
||||||
i := cn.getByIndex(0)
|
i := cn.getByIndex(0)
|
||||||
|
|
|
||||||
4
go.mod
4
go.mod
|
|
@ -4,7 +4,7 @@ replace git.smarteching.com/goffee/core/logger => ./logger
|
||||||
|
|
||||||
replace git.smarteching.com/goffee/core/env => ./env
|
replace git.smarteching.com/goffee/core/env => ./env
|
||||||
|
|
||||||
go 1.24.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.smarteching.com/zeni/go-chart/v2 v2.1.4
|
git.smarteching.com/zeni/go-chart/v2 v2.1.4
|
||||||
|
|
@ -23,10 +23,8 @@ require (
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.smarteching.com/zeni/go-charts/v2 v2.6.11 // indirect
|
|
||||||
github.com/SparkPost/gosparkpost v0.2.0 // indirect
|
github.com/SparkPost/gosparkpost v0.2.0 // indirect
|
||||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
|
||||||
github.com/dustin/go-humanize v1.0.1 // indirect
|
|
||||||
github.com/go-chi/chi/v5 v5.0.8 // indirect
|
github.com/go-chi/chi/v5 v5.0.8 // indirect
|
||||||
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
github.com/go-sql-driver/mysql v1.7.0 // indirect
|
||||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||||
|
|
|
||||||
5
go.sum
5
go.sum
|
|
@ -1,7 +1,5 @@
|
||||||
git.smarteching.com/zeni/go-chart/v2 v2.1.4 h1:pF06+F6eqJLIG8uMiTVPR5TygPGMjM/FHMzTxmu5V/Q=
|
git.smarteching.com/zeni/go-chart/v2 v2.1.4 h1:pF06+F6eqJLIG8uMiTVPR5TygPGMjM/FHMzTxmu5V/Q=
|
||||||
git.smarteching.com/zeni/go-chart/v2 v2.1.4/go.mod h1:b3ueW9h3pGGXyhkormZAvilHaG4+mQti+bMNPdQBeOQ=
|
git.smarteching.com/zeni/go-chart/v2 v2.1.4/go.mod h1:b3ueW9h3pGGXyhkormZAvilHaG4+mQti+bMNPdQBeOQ=
|
||||||
git.smarteching.com/zeni/go-charts/v2 v2.6.11 h1:9udzlv3uxGXszpplfkL5IaTUrgkNj++KwhbaN1vVEqI=
|
|
||||||
git.smarteching.com/zeni/go-charts/v2 v2.6.11/go.mod h1:3OpRPSXg7Qx4zcgsmwsC9ZFB9/wAkGSbnXf1wIbHYCg=
|
|
||||||
github.com/SparkPost/gosparkpost v0.2.0 h1:yzhHQT7cE+rqzd5tANNC74j+2x3lrPznqPJrxC1yR8s=
|
github.com/SparkPost/gosparkpost v0.2.0 h1:yzhHQT7cE+rqzd5tANNC74j+2x3lrPznqPJrxC1yR8s=
|
||||||
github.com/SparkPost/gosparkpost v0.2.0/go.mod h1:S9WKcGeou7cbPpx0kTIgo8Q69WZvUmVeVzbD+djalJ4=
|
github.com/SparkPost/gosparkpost v0.2.0/go.mod h1:S9WKcGeou7cbPpx0kTIgo8Q69WZvUmVeVzbD+djalJ4=
|
||||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||||
|
|
@ -21,8 +19,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
|
||||||
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
|
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51 h1:0JZ+dUmQeA8IIVUMzysrX4/AKuQwWhV2dYQuPZdvdSQ=
|
||||||
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
|
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
|
||||||
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
|
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
|
||||||
|
|
@ -104,7 +100,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
package components
|
package components
|
||||||
|
|
||||||
type ContentList struct {
|
type ContentList struct {
|
||||||
ID string
|
|
||||||
Items []ContentListItem
|
Items []ContentListItem
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContentListItem struct {
|
type ContentListItem struct {
|
||||||
ID string
|
|
||||||
Text string
|
Text string
|
||||||
Description string
|
Description string
|
||||||
EndElement string
|
EndElement string
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
{{define "content_list"}}
|
{{define "content_list"}}
|
||||||
<ul class="list-group" {{ if .ID }}id="{{.ID}}"{{end}}>
|
<ul class="list-group">
|
||||||
{{ range .Items}}
|
{{ range .Items}}
|
||||||
<li class="list-group-item text-wrap {{if eq .IsDisabled true}}disabled{{end}}
|
<li class="list-group-item text-wrap {{if eq .IsDisabled true}}disabled{{end}} {{if .TypeClass}}list-group-item-{{.TypeClass}}{{end}}"
|
||||||
{{if .TypeClass}}list-group-item-{{.TypeClass}}{{end}}"
|
{{if eq .IsDisabled true}}aria-disabled="true"{{end}}
|
||||||
{{if eq .IsDisabled true}}aria-disabled="true"{{end}}
|
|
||||||
{{ if .ID }}id="{{.ID}}"{{end}}
|
|
||||||
><div class="d-flex justify-content-between lh-sm"><p class="mb-1">{{.Text}}</p><span class="text-body-secondary ms-5">{{.EndElement}}</span></div>
|
><div class="d-flex justify-content-between lh-sm"><p class="mb-1">{{.Text}}</p><span class="text-body-secondary ms-5">{{.EndElement}}</span></div>
|
||||||
<small>{{.Description}}</small>
|
<small>{{.Description}}</small>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ type PageNav struct {
|
||||||
type PageNavItem struct {
|
type PageNavItem struct {
|
||||||
Text string
|
Text string
|
||||||
Link string
|
Link string
|
||||||
ID string
|
|
||||||
IsDisabled bool
|
IsDisabled bool
|
||||||
IsActive bool
|
IsActive bool
|
||||||
ChildItems []PageNavItem
|
ChildItems []PageNavItem
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
{{define "page_nav"}}
|
{{define "page_nav"}}
|
||||||
<ul class="nav justify-content-center {{.NavClass}} {{if eq .IsVertical true}}flex-column{{end}}{{if eq .IsTab true}}nav-tabs{{end}}" {{if eq .IsTab true}}role="tablist"{{end}}>
|
<ul class="nav justify-content-center {{.NavClass}} {{if eq .IsVertical true}}flex-column{{end}}{{if eq .IsTab true}}nav-tabs{{end}}" {{if eq .IsTab true}}role="tablist"{{end}}>
|
||||||
{{range $item := .NavItems}}
|
{{range $item := .NavItems}}
|
||||||
|
|
||||||
{{if gt (len $item.ChildItems) 0}}
|
{{if gt (len $item.ChildItems) 0}}
|
||||||
{{ $hasActiveChild := false }}
|
|
||||||
{{range $child := $item.ChildItems}}
|
|
||||||
{{if $child.IsActive}}
|
|
||||||
{{ $hasActiveChild = true }}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
<a href="{{$item.Link}}" {{if eq .IsDisabled true}}disabled{{end}} data-bs-toggle="dropdown"
|
<a href="{{$item.Link}}" {{if eq .IsDisabled true}}disabled{{end}} data-bs-toggle="dropdown"
|
||||||
class="nav-link dropdown-toggle {{if or $item.IsActive $hasActiveChild}}active{{end}} {{if eq .IsDisabled true}}disabled{{end}}">{{$item.Text}}</a>
|
class="nav-link dropdown-toggle {{if eq .IsActive true}}active{{end}} {{if eq .IsDisabled true}}disabled{{end}}">{{$item.Text}}</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
{{ range $item.ChildItems}}
|
{{ range $item.ChildItems}}
|
||||||
{{template "content_dropdown_item" .}}
|
{{template "content_dropdown_item" .}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue