FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cache-handler/admin.go at master · caddyserver/cache-handler · GitHub
caddyserver
cache-handler
Repository navigation
Code
Issues
22
(22)
Pull requests
2
(2)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cache-handler
/
admin.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (77 loc) · 2.05 KB
Breadcrumbs
cache-handler
/
admin.go
Copy path
File metadata and controls
92 lines (77 loc) · 2.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package
httpcache
import
(
"fmt"
"net/http"
"strings"
"time"
"github.com/caddyserver/caddy/v2"
"github.com/darkweak/souin/configurationtypes"
"github.com/darkweak/souin/pkg/api"
"github.com/darkweak/storages/core"
)
func
init
() {
caddy
.
RegisterModule
(
new
(
adminAPI
))
}
// adminAPI is a module that serves PKI endpoints to retrieve
// information about the CAs being managed by Caddy.
type
adminAPI
struct
{
ctx
caddy.
Context
logger
core.
Logger
InternalEndpointHandlers
*
api.
MapHandler
}
// CaddyModule returns the Caddy module information.
func
(
adminAPI
)
CaddyModule
() caddy.
ModuleInfo
{
return
caddy.
ModuleInfo
{
ID
:
"admin.api.souin"
,
New
:
func
() caddy.
Module
{
return
new
(
adminAPI
) },
}
}
func
(
a
*
adminAPI
)
handleAPIEndpoints
(
writer
http.
ResponseWriter
,
request
*
http.
Request
)
error
{
if
a
.
InternalEndpointHandlers
!=
nil
{
for
k
,
handler
:=
range
*
a
.
InternalEndpointHandlers
.
Handlers
{
if
strings
.
Contains
(
request
.
RequestURI
,
k
) {
handler
(
writer
,
request
)
return
nil
}
}
}
return
caddy.
APIError
{
HTTPStatus
:
http
.
StatusNotFound
,
Err
:
fmt
.
Errorf
(
"resource not found: %v"
,
request
.
URL
.
Path
),
}
}
// Provision sets up the adminAPI module.
func
(
a
*
adminAPI
)
Provision
(
ctx
caddy.
Context
)
error
{
a
.
ctx
=
ctx
a
.
logger
=
ctx
.
Logger
(
a
).
Sugar
()
app
,
err
:=
ctx
.
App
(
moduleName
)
if
err
!=
nil
{
return
err
}
go
func
() {
currentApp
:=
app
.(
*
SouinApp
)
item
:=
<-
currentApp
.
onMiddlewareLoaded
()
config
:=
Configuration
{
API
:
item
.
API
,
DefaultCache
:
DefaultCache
{
TTL
: configurationtypes.
Duration
{
Duration
:
120
*
time
.
Second
,
},
MappingEvictionInterval
: configurationtypes.
Duration
{
Duration
:
time
.
Hour
,
},
},
}
a
.
InternalEndpointHandlers
=
api
.
GenerateHandlerMap
(
&
config
,
currentApp
.
Storers
,
item
.
SurrogateStorage
)
}()
return
nil
}
// Routes returns the admin routes.
func
(
a
*
adminAPI
)
Routes
() []caddy.
AdminRoute
{
return
[]caddy.
AdminRoute
{
{
Pattern
:
"/{params...}"
,
Handler
:
caddy
.
AdminHandlerFunc
(
a
.
handleAPIEndpoints
),
},
}
}
Back
|
FazBrowse Home
|
New Git URL