mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-06 12:08:20 +08:00
Compare commits
3 Commits
382671bed4
...
5d72a531eb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d72a531eb | ||
|
|
5f4f964325 | ||
|
|
a41520ecbf |
2
.github/workflows/gin.yml
vendored
2
.github/workflows/gin.yml
vendored
@ -78,6 +78,6 @@ jobs:
|
||||
run: make test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v5
|
||||
uses: codecov/codecov-action@v6
|
||||
with:
|
||||
flags: ${{ matrix.os }},go-${{ matrix.go }},${{ matrix.test-tags }}
|
||||
|
||||
4
.github/workflows/trivy-scan.yml
vendored
4
.github/workflows/trivy-scan.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run Trivy vulnerability scanner (source code)
|
||||
uses: aquasecurity/trivy-action@0.35.0
|
||||
uses: aquasecurity/trivy-action@v0.36.0
|
||||
with:
|
||||
scan-type: "fs"
|
||||
scan-ref: "."
|
||||
@ -44,7 +44,7 @@ jobs:
|
||||
sarif_file: "trivy-results.sarif"
|
||||
|
||||
- name: Run Trivy scanner (table output for logs)
|
||||
uses: aquasecurity/trivy-action@0.35.0
|
||||
uses: aquasecurity/trivy-action@v0.36.0
|
||||
if: always()
|
||||
with:
|
||||
scan-type: "fs"
|
||||
|
||||
22
engine_test.go
Normal file
22
engine_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package gin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRoutesConcurrent(t *testing.T) {
|
||||
r := New()
|
||||
|
||||
done := make(chan bool)
|
||||
|
||||
// Concurrently read routes
|
||||
go func() {
|
||||
_ = r.Routes()
|
||||
done <- true
|
||||
}()
|
||||
|
||||
// Register a route at the same time
|
||||
r.GET("/", func(c *Context) { c.String(200, "OK") })
|
||||
|
||||
<-done
|
||||
}
|
||||
5
gin.go
5
gin.go
@ -182,6 +182,7 @@ type Engine struct {
|
||||
noMethod HandlersChain
|
||||
pool sync.Pool
|
||||
trees methodTrees
|
||||
treesMu sync.RWMutex
|
||||
maxParams uint16
|
||||
maxSections uint16
|
||||
trustedProxies []string
|
||||
@ -362,6 +363,8 @@ func (engine *Engine) rebuild405Handlers() {
|
||||
}
|
||||
|
||||
func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
||||
engine.treesMu.Lock()
|
||||
defer engine.treesMu.Unlock()
|
||||
assert1(path[0] == '/', "path must begin with '/'")
|
||||
assert1(method != "", "HTTP method can not be empty")
|
||||
assert1(len(handlers) > 0, "there must be at least one handler")
|
||||
@ -388,6 +391,8 @@ func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
|
||||
// Routes returns a slice of registered routes, including some useful information, such as:
|
||||
// the http method, path, and the handler name.
|
||||
func (engine *Engine) Routes() (routes RoutesInfo) {
|
||||
engine.treesMu.RLock()
|
||||
defer engine.treesMu.RUnlock()
|
||||
for _, tree := range engine.trees {
|
||||
routes = iterate("", tree.method, routes, tree.root)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user