@marcel91200 / caddy Mirror · read-only / commits / b32f265e
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 00:30 UTC

ci: Use gofumpt to format code (#5707)

Jacob Gadikian committed Aug 8, 2023 at 03:40 UTC b32f265ecad60404c3818cc9d42e367a8e4eb7d4
33 files changed +60 -64
.golangci.yml
+1 -2
@@ -8,8 +8,7 @@ linters:
8 enable:
9 - bodyclose
10 - errcheck
11 - - gofmt
12 - - goimports
11 + - gofumpt
12 - gosec
13 - gosimple
14 - govet
admin.go
+1 -1
@@ -1346,7 +1346,7 @@ var (
1346 // will get deleted before the process gracefully exits.
1347 func PIDFile(filename string) error {
1348 pid := []byte(strconv.Itoa(os.Getpid()) + "\n")
1349 - err := os.WriteFile(filename, pid, 0600)
1349 + err := os.WriteFile(filename, pid, 0o600)
1350 if err != nil {
1351 return err
1352 }
caddy.go
+3 -3
@@ -356,13 +356,13 @@ func unsyncedDecodeAndRun(cfgJSON []byte, allowPersist bool) error {
356 newCfg.Admin.Config.Persist == nil ||
357 *newCfg.Admin.Config.Persist) {
358 dir := filepath.Dir(ConfigAutosavePath)
359 - err := os.MkdirAll(dir, 0700)
359 + err := os.MkdirAll(dir, 0o700)
360 if err != nil {
361 Log().Error("unable to create folder for config autosave",
362 zap.String("dir", dir),
363 zap.Error(err))
364 } else {
365 - err := os.WriteFile(ConfigAutosavePath, cfgJSON, 0600)
365 + err := os.WriteFile(ConfigAutosavePath, cfgJSON, 0o600)
366 if err == nil {
367 Log().Info("autosaved config (load with --resume flag)", zap.String("file", ConfigAutosavePath))
368 } else {
@@ -831,7 +831,7 @@ func InstanceID() (uuid.UUID, error) {
831 if err != nil {
832 return uuid, err
833 }
834 - err = os.WriteFile(uuidFilePath, []byte(uuid.String()), 0600)
834 + err = os.WriteFile(uuidFilePath, []byte(uuid.String()), 0o600)
835 return uuid, err
836 } else if err != nil {
837 return [16]byte{}, err
caddyconfig/caddyfile/importgraph.go
+3
@@ -34,6 +34,7 @@ func (i *importGraph) addNode(name string) {
34 }
35 i.nodes[name] = true
36 }
37 +
38 func (i *importGraph) addNodes(names []string) {
39 for _, name := range names {
40 i.addNode(name)
@@ -43,6 +44,7 @@ func (i *importGraph) addNodes(names []string) {
44 func (i *importGraph) removeNode(name string) {
45 delete(i.nodes, name)
46 }
47 +
48 func (i *importGraph) removeNodes(names []string) {
49 for _, name := range names {
50 i.removeNode(name)
@@ -73,6 +75,7 @@ func (i *importGraph) addEdge(from, to string) error {
75 i.edges[from] = append(i.edges[from], to)
76 return nil
77 }
78 +
79 func (i *importGraph) addEdges(from string, tos []string) error {
80 for _, to := range tos {
81 err := i.addEdge(from, to)
caddyconfig/caddyfile/parse.go
-1
@@ -565,7 +565,6 @@ func (p *parser) doSingleImport(importFile string) ([]Token, error) {
565 // are loaded into the current server block for later use
566 // by directive setup functions.
567 func (p *parser) directive() error {
568 -
568 // a segment is a list of tokens associated with this directive
569 var segment Segment
570
caddyconfig/httpcaddyfile/addresses.go
+4 -2
@@ -77,7 +77,8 @@ import (
77 // multiple addresses to the same lists of server blocks (a many:many mapping).
78 // (Doing this is essentially a map-reduce technique.)
79 func (st *ServerType) mapAddressToServerBlocks(originalServerBlocks []serverBlock,
80 - options map[string]any) (map[string][]serverBlock, error) {
80 + options map[string]any,
81 +) (map[string][]serverBlock, error) {
82 sbmap := make(map[string][]serverBlock)
83
84 for i, sblock := range originalServerBlocks {
@@ -187,7 +188,8 @@ func (st *ServerType) consolidateAddrMappings(addrToServerBlocks map[string][]se
188 // listenerAddrsForServerBlockKey essentially converts the Caddyfile
189 // site addresses to Caddy listener addresses for each server block.
190 func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key string,
190 - options map[string]any) ([]string, error) {
191 + options map[string]any,
192 +) ([]string, error) {
193 addr, err := ParseAddress(key)
194 if err != nil {
195 return nil, fmt.Errorf("parsing key: %v", err)
caddyconfig/httpcaddyfile/directives.go
+2 -1
@@ -217,7 +217,8 @@ func (h Helper) ExtractMatcherSet() (caddy.ModuleMap, error) {
217
218 // NewRoute returns config values relevant to creating a new HTTP route.
219 func (h Helper) NewRoute(matcherSet caddy.ModuleMap,
220 - handler caddyhttp.MiddlewareHandler) []ConfigValue {
220 + handler caddyhttp.MiddlewareHandler,
221 +) []ConfigValue {
222 mod, err := caddy.GetModule(caddy.GetModuleID(handler))
223 if err != nil {
224 *h.warnings = append(*h.warnings, caddyconfig.Warning{
caddyconfig/httpcaddyfile/httptype.go
+7 -6
@@ -49,8 +49,7 @@ type App struct {
49 }
50
51 // ServerType can set up a config from an HTTP Caddyfile.
52 -type ServerType struct {
53 -}
52 +type ServerType struct{}
53
54 // Setup makes a config from the tokens.
55 func (st ServerType) Setup(
@@ -1059,8 +1058,8 @@ func appendSubrouteToRouteList(routeList caddyhttp.RouteList,
1058 subroute *caddyhttp.Subroute,
1059 matcherSetsEnc []caddy.ModuleMap,
1060 p sbAddrAssociation,
1062 - warnings *[]caddyconfig.Warning) caddyhttp.RouteList {
1063 -
1061 + warnings *[]caddyconfig.Warning,
1062 +) caddyhttp.RouteList {
1063 // nothing to do if... there's nothing to do
1064 if len(matcherSetsEnc) == 0 && len(subroute.Routes) == 0 && subroute.Errors == nil {
1065 return routeList
@@ -1608,8 +1607,10 @@ type sbAddrAssociation struct {
1607 serverBlocks []serverBlock
1608 }
1609
1611 -const matcherPrefix = "@"
1612 -const namedRouteKey = "named_route"
1610 +const (
1611 + matcherPrefix = "@"
1612 + namedRouteKey = "named_route"
1613 +)
1614
1615 // Interface guard
1616 var _ caddyfile.ServerType = (*ServerType)(nil)
caddyconfig/httpcaddyfile/pkiapp.go
-1
@@ -174,7 +174,6 @@ func (st ServerType) buildPKIApp(
174 options map[string]any,
175 warnings []caddyconfig.Warning,
176 ) (*caddypki.PKI, []caddyconfig.Warning, error) {
177 -
177 skipInstallTrust := false
178 if _, ok := options["skip_install_trust"]; ok {
179 skipInstallTrust = true
caddyconfig/httpcaddyfile/tlsapp.go
-1
@@ -36,7 +36,6 @@ func (st ServerType) buildTLSApp(
36 options map[string]any,
37 warnings []caddyconfig.Warning,
38 ) (*caddytls.TLS, []caddyconfig.Warning, error) {
39 -
39 tlsApp := &caddytls.TLS{CertificatesRaw: make(caddy.ModuleMap)}
40 var certLoaders []caddytls.CertificateLoader
41
caddytest/caddytest.go
-16
@@ -63,7 +63,6 @@ type Tester struct {
63
64 // NewTester will create a new testing client with an attached cookie jar
65 func NewTester(t *testing.T) *Tester {
66 -
66 jar, err := cookiejar.New(nil)
67 if err != nil {
68 t.Fatalf("failed to create cookiejar: %s", err)
@@ -94,7 +93,6 @@ func timeElapsed(start time.Time, name string) {
93 // InitServer this will configure the server with a configurion of a specific
94 // type. The configType must be either "json" or the adapter type.
95 func (tc *Tester) InitServer(rawConfig string, configType string) {
97 -
96 if err := tc.initServer(rawConfig, configType); err != nil {
97 tc.t.Logf("failed to load config: %s", err)
98 tc.t.Fail()
@@ -108,7 +106,6 @@ func (tc *Tester) InitServer(rawConfig string, configType string) {
106 // InitServer this will configure the server with a configurion of a specific
107 // type. The configType must be either "json" or the adapter type.
108 func (tc *Tester) initServer(rawConfig string, configType string) error {
111 -
109 if testing.Short() {
110 tc.t.SkipNow()
111 return nil
@@ -232,7 +229,6 @@ const initConfig = `{
229 // validateTestPrerequisites ensures the certificates are available in the
230 // designated path and Caddy sub-process is running.
231 func validateTestPrerequisites(t *testing.T) error {
235 -
232 // check certificates are found
233 for _, certName := range Default.Certifcates {
234 if _, err := os.Stat(getIntegrationDir() + certName); os.IsNotExist(err) {
@@ -284,7 +280,6 @@ func isCaddyAdminRunning() error {
280 }
281
282 func getIntegrationDir() string {
287 -
283 _, filename, _, ok := runtime.Caller(1)
284 if !ok {
285 panic("unable to determine the current file path")
@@ -304,7 +299,6 @@ func prependCaddyFilePath(rawConfig string) string {
299
300 // CreateTestingTransport creates a testing transport that forces call dialing connections to happen locally
301 func CreateTestingTransport() *http.Transport {
307 -
302 dialer := net.Dialer{
303 Timeout: 5 * time.Second,
304 KeepAlive: 5 * time.Second,
@@ -332,7 +326,6 @@ func CreateTestingTransport() *http.Transport {
326
327 // AssertLoadError will load a config and expect an error
328 func AssertLoadError(t *testing.T, rawConfig string, configType string, expectedError string) {
335 -
329 tc := NewTester(t)
330
331 err := tc.initServer(rawConfig, configType)
@@ -343,7 +336,6 @@ func AssertLoadError(t *testing.T, rawConfig string, configType string, expected
336
337 // AssertRedirect makes a request and asserts the redirection happens
338 func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, expectedStatusCode int) *http.Response {
346 -
339 redirectPolicyFunc := func(req *http.Request, via []*http.Request) error {
340 return http.ErrUseLastResponse
341 }
@@ -381,7 +373,6 @@ func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, e
373
374 // CompareAdapt adapts a config and then compares it against an expected result
375 func CompareAdapt(t *testing.T, filename, rawConfig string, adapterName string, expectedResponse string) bool {
384 -
376 cfgAdapter := caddyconfig.GetAdapter(adapterName)
377 if cfgAdapter == nil {
378 t.Logf("unrecognized config adapter '%s'", adapterName)
@@ -469,7 +460,6 @@ func applyHeaders(t *testing.T, req *http.Request, requestHeaders []string) {
460
461 // AssertResponseCode will execute the request and verify the status code, returns a response for additional assertions
462 func (tc *Tester) AssertResponseCode(req *http.Request, expectedStatusCode int) *http.Response {
472 -
463 resp, err := tc.Client.Do(req)
464 if err != nil {
465 tc.t.Fatalf("failed to call server %s", err)
@@ -484,7 +474,6 @@ func (tc *Tester) AssertResponseCode(req *http.Request, expectedStatusCode int)
474
475 // AssertResponse request a URI and assert the status code and the body contains a string
476 func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expectedBody string) (*http.Response, string) {
487 -
477 resp := tc.AssertResponseCode(req, expectedStatusCode)
478
479 defer resp.Body.Close()
@@ -506,7 +495,6 @@ func (tc *Tester) AssertResponse(req *http.Request, expectedStatusCode int, expe
495
496 // AssertGetResponse GET a URI and expect a statusCode and body text
497 func (tc *Tester) AssertGetResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string) {
509 -
498 req, err := http.NewRequest("GET", requestURI, nil)
499 if err != nil {
500 tc.t.Fatalf("unable to create request %s", err)
@@ -517,7 +505,6 @@ func (tc *Tester) AssertGetResponse(requestURI string, expectedStatusCode int, e
505
506 // AssertDeleteResponse request a URI and expect a statusCode and body text
507 func (tc *Tester) AssertDeleteResponse(requestURI string, expectedStatusCode int, expectedBody string) (*http.Response, string) {
520 -
508 req, err := http.NewRequest("DELETE", requestURI, nil)
509 if err != nil {
510 tc.t.Fatalf("unable to create request %s", err)
@@ -528,7 +515,6 @@ func (tc *Tester) AssertDeleteResponse(requestURI string, expectedStatusCode int
515
516 // AssertPostResponseBody POST to a URI and assert the response code and body
517 func (tc *Tester) AssertPostResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
531 -
518 req, err := http.NewRequest("POST", requestURI, requestBody)
519 if err != nil {
520 tc.t.Errorf("failed to create request %s", err)
@@ -542,7 +528,6 @@ func (tc *Tester) AssertPostResponseBody(requestURI string, requestHeaders []str
528
529 // AssertPutResponseBody PUT to a URI and assert the response code and body
530 func (tc *Tester) AssertPutResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
545 -
531 req, err := http.NewRequest("PUT", requestURI, requestBody)
532 if err != nil {
533 tc.t.Errorf("failed to create request %s", err)
@@ -556,7 +541,6 @@ func (tc *Tester) AssertPutResponseBody(requestURI string, requestHeaders []stri
541
542 // AssertPatchResponseBody PATCH to a URI and assert the response code and body
543 func (tc *Tester) AssertPatchResponseBody(requestURI string, requestHeaders []string, requestBody *bytes.Buffer, expectedStatusCode int, expectedBody string) (*http.Response, string) {
559 -
544 req, err := http.NewRequest("PATCH", requestURI, requestBody)
545 if err != nil {
546 tc.t.Errorf("failed to create request %s", err)
cmd/commandfuncs.go
+1 -1
@@ -565,7 +565,7 @@ func cmdFmt(fl Flags) (int, error) {
565 output := caddyfile.Format(input)
566
567 if fl.Bool("overwrite") {
568 - if err := os.WriteFile(formatCmdConfigFile, output, 0600); err != nil {
568 + if err := os.WriteFile(formatCmdConfigFile, output, 0o600); err != nil {
569 return caddy.ExitCodeFailedStartup, fmt.Errorf("overwriting formatted file: %v", err)
570 }
571 return caddy.ExitCodeSuccess, nil
cmd/commands.go
+1 -1
@@ -444,7 +444,7 @@ argument of --directory. If the directory does not exist, it will be created.
444 if dir == "" {
445 return caddy.ExitCodeFailedQuit, fmt.Errorf("designated output directory and specified section are required")
446 }
447 - if err := os.MkdirAll(dir, 0755); err != nil {
447 + if err := os.MkdirAll(dir, 0o755); err != nil {
448 return caddy.ExitCodeFailedQuit, err
449 }
450 if err := doc.GenManTree(rootCmd, &doc.GenManHeader{
cmd/storagefuncs.go
+1 -1
@@ -200,7 +200,7 @@ func cmdExportStorage(fl Flags) (int, error) {
200
201 hdr := &tar.Header{
202 Name: k,
203 - Mode: 0600,
203 + Mode: 0o600,
204 Size: int64(len(v)),
205 }
206
internal/sockets.go
+1 -1
@@ -52,5 +52,5 @@ func SplitUnixSocketPermissionsBits(addr string) (path string, fileMode fs.FileM
52
53 // default to 0200 (symbolic: `u=w,g=,o=`)
54 // if no permission bits are specified
55 - return addr, 0200, nil
55 + return addr, 0o200, nil
56 }
listeners.go
-1
@@ -174,7 +174,6 @@ func (na NetworkAddress) listen(ctx context.Context, portOffset uint, config net
174 if err := os.Chmod(address, unixFileMode); err != nil {
175 return nil, fmt.Errorf("unable to set permissions (%s) on %s: %v", unixFileMode, address, err)
176 }
177 -
177 }
178 return socket, err
179 }
modules/caddyhttp/caddyhttp.go
+4 -2
@@ -307,5 +307,7 @@ const (
307 const separator = string(filepath.Separator)
308
309 // Interface guard
310 -var _ caddy.ListenerWrapper = (*tlsPlaceholderWrapper)(nil)
311 -var _ caddyfile.Unmarshaler = (*tlsPlaceholderWrapper)(nil)
310 +var (
311 + _ caddy.ListenerWrapper = (*tlsPlaceholderWrapper)(nil)
312 + _ caddyfile.Unmarshaler = (*tlsPlaceholderWrapper)(nil)
313 +)
modules/caddyhttp/celmatcher.go
+4
@@ -234,9 +234,11 @@ func (cr celHTTPRequest) Parent() interpreter.Activation {
234 func (cr celHTTPRequest) ConvertToNative(typeDesc reflect.Type) (any, error) {
235 return cr.Request, nil
236 }
237 +
238 func (celHTTPRequest) ConvertToType(typeVal ref.Type) ref.Val {
239 panic("not implemented")
240 }
241 +
242 func (cr celHTTPRequest) Equal(other ref.Val) ref.Val {
243 if o, ok := other.Value().(celHTTPRequest); ok {
244 return types.Bool(o.Request == cr.Request)
@@ -255,12 +257,14 @@ type celPkixName struct{ *pkix.Name }
257 func (pn celPkixName) ConvertToNative(typeDesc reflect.Type) (any, error) {
258 return pn.Name, nil
259 }
260 +
261 func (pn celPkixName) ConvertToType(typeVal ref.Type) ref.Val {
262 if typeVal.TypeName() == "string" {
263 return types.String(pn.Name.String())
264 }
265 panic("not implemented")
266 }
267 +
268 func (pn celPkixName) Equal(other ref.Val) ref.Val {
269 if o, ok := other.Value().(string); ok {
270 return types.Bool(pn.Name.String() == o)
modules/caddyhttp/fileserver/browse.go
+1 -1
@@ -113,7 +113,7 @@ func (fsrv *FileServer) serveBrowse(root, dirPath string, w http.ResponseWriter,
113 fs = http.Dir(repl.ReplaceAll(fsrv.Root, "."))
114 }
115
116 - var tplCtx = &templateContext{
116 + tplCtx := &templateContext{
117 TemplateContext: templates.TemplateContext{
118 Root: fs,
119 Req: r,
modules/caddyhttp/matchers.go
+1 -3
@@ -1392,9 +1392,7 @@ func ParseCaddyfileNestedMatcherSet(d *caddyfile.Dispenser) (caddy.ModuleMap, er
1392 return matcherSet, nil
1393 }
1394
1395 -var (
1396 - wordRE = regexp.MustCompile(`\w+`)
1397 -)
1395 +var wordRE = regexp.MustCompile(`\w+`)
1396
1397 const regexpPlaceholderPrefix = "http.regexp"
1398
modules/caddyhttp/reverseproxy/addresses.go
+3
@@ -45,12 +45,15 @@ func (p parsedAddr) dialAddr() string {
45 }
46 return net.JoinHostPort(p.host, p.port)
47 }
48 +
49 func (p parsedAddr) rangedPort() bool {
50 return strings.Contains(p.port, "-")
51 }
52 +
53 func (p parsedAddr) replaceablePort() bool {
54 return strings.Contains(p.port, "{") && strings.Contains(p.port, "}")
55 }
56 +
57 func (p parsedAddr) isUnix() bool {
58 return caddy.IsUnixNetwork(p.network)
59 }
modules/caddyhttp/reverseproxy/caddyfile.go
-1
@@ -549,7 +549,6 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
549 h.RequestBuffers = int64(size)
550 } else if subdir == "response_buffers" {
551 h.ResponseBuffers = int64(size)
552 -
552 }
553
554 // TODO: These three properties are deprecated; remove them sometime after v2.6.4
modules/caddyhttp/reverseproxy/command.go
+2 -1
@@ -284,7 +284,8 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
284
285 var false bool
286 cfg := &caddy.Config{
287 - Admin: &caddy.AdminConfig{Disabled: true,
287 + Admin: &caddy.AdminConfig{
288 + Disabled: true,
289 Config: &caddy.ConfigSettings{
290 Persist: &false,
291 },
modules/caddyhttp/reverseproxy/fastcgi/client.go
-3
@@ -251,7 +251,6 @@ func (c *client) Request(p map[string]string, req io.Reader) (resp *http.Respons
251
252 // Get issues a GET request to the fcgi responder.
253 func (c *client) Get(p map[string]string, body io.Reader, l int64) (resp *http.Response, err error) {
254 -
254 p["REQUEST_METHOD"] = "GET"
255 p["CONTENT_LENGTH"] = strconv.FormatInt(l, 10)
256
@@ -260,7 +259,6 @@ func (c *client) Get(p map[string]string, body io.Reader, l int64) (resp *http.R
259
260 // Head issues a HEAD request to the fcgi responder.
261 func (c *client) Head(p map[string]string) (resp *http.Response, err error) {
263 -
262 p["REQUEST_METHOD"] = "HEAD"
263 p["CONTENT_LENGTH"] = "0"
264
@@ -269,7 +267,6 @@ func (c *client) Head(p map[string]string) (resp *http.Response, err error) {
267
268 // Options issues an OPTIONS request to the fcgi responder.
269 func (c *client) Options(p map[string]string) (resp *http.Response, err error) {
272 -
270 p["REQUEST_METHOD"] = "OPTIONS"
271 p["CONTENT_LENGTH"] = "0"
272
modules/caddyhttp/reverseproxy/reverseproxy.go
+2 -1
@@ -450,7 +450,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
450 // It returns true when the loop is done and should break; false otherwise. The error value returned should
451 // be assigned to the proxyErr value for the next iteration of the loop (or the error handled after break).
452 func (h *Handler) proxyLoopIteration(r *http.Request, origReq *http.Request, w http.ResponseWriter, proxyErr error, start time.Time, retries int,
453 - repl *caddy.Replacer, reqHeader http.Header, reqHost string, next caddyhttp.Handler) (bool, error) {
453 + repl *caddy.Replacer, reqHeader http.Header, reqHost string, next caddyhttp.Handler,
454 +) (bool, error) {
455 // get the updated list of upstreams
456 upstreams := h.Upstreams
457 if h.DynamicUpstreams != nil {
modules/caddyhttp/reverseproxy/streaming.go
+4 -2
@@ -522,5 +522,7 @@ var streamingBufPool = sync.Pool{
522 },
523 }
524
525 -const defaultBufferSize = 32 * 1024
526 -const wordSize = int(unsafe.Sizeof(uintptr(0)))
525 +const (
526 + defaultBufferSize = 32 * 1024
527 + wordSize = int(unsafe.Sizeof(uintptr(0)))
528 +)
modules/caddyhttp/templates/tplcontext.go
-3
@@ -103,13 +103,11 @@ func (c TemplateContext) OriginalReq() http.Request {
103 // trusted files. If it is not trusted, be sure to use escaping functions
104 // in your template.
105 func (c TemplateContext) funcInclude(filename string, args ...any) (string, error) {
106 -
106 bodyBuf := bufPool.Get().(*bytes.Buffer)
107 bodyBuf.Reset()
108 defer bufPool.Put(bodyBuf)
109
110 err := c.readFileToBuffer(filename, bodyBuf)
112 -
111 if err != nil {
112 return "", err
113 }
@@ -215,7 +213,6 @@ func (c TemplateContext) funcHTTPInclude(uri string) (string, error) {
213 // {{ template }} from the standard template library. If the imported file has
214 // no {{ define }} blocks, the name of the import will be the path
215 func (c *TemplateContext) funcImport(filename string) (string, error) {
218 -
216 bodyBuf := bufPool.Get().(*bytes.Buffer)
217 bodyBuf.Reset()
218 defer bufPool.Put(bodyBuf)
modules/caddypki/acmeserver/acmeserver.go
+5 -3
@@ -239,7 +239,7 @@ func (ash Handler) openDatabase() (*db.AuthDB, error) {
239 dbFolder := filepath.Join(caddy.AppDataDir(), "acme_server", key)
240 dbPath := filepath.Join(dbFolder, "db")
241
242 - err := os.MkdirAll(dbFolder, 0755)
242 + err := os.MkdirAll(dbFolder, 0o755)
243 if err != nil {
244 return nil, fmt.Errorf("making folder for CA database: %v", err)
245 }
@@ -310,8 +310,10 @@ func (c resolverClient) LookupTxt(name string) ([]string, error) {
310
311 const defaultPathPrefix = "/acme/"
312
313 -var keyCleaner = regexp.MustCompile(`[^\w.-_]`)
314 -var databasePool = caddy.NewUsagePool()
313 +var (
314 + keyCleaner = regexp.MustCompile(`[^\w.-_]`)
315 + databasePool = caddy.NewUsagePool()
316 +)
317
318 type databaseCloser struct {
319 DB *db.AuthDB
modules/caddypki/ca.go
+4
@@ -376,15 +376,19 @@ func (ca CA) genIntermediate(rootCert *x509.Certificate, rootKey crypto.Signer)
376 func (ca CA) storageKeyCAPrefix() string {
377 return path.Join("pki", "authorities", certmagic.StorageKeys.Safe(ca.ID))
378 }
379 +
380 func (ca CA) storageKeyRootCert() string {
381 return path.Join(ca.storageKeyCAPrefix(), "root.crt")
382 }
383 +
384 func (ca CA) storageKeyRootKey() string {
385 return path.Join(ca.storageKeyCAPrefix(), "root.key")
386 }
387 +
388 func (ca CA) storageKeyIntermediateCert() string {
389 return path.Join(ca.storageKeyCAPrefix(), "intermediate.crt")
390 }
391 +
392 func (ca CA) storageKeyIntermediateKey() string {
393 return path.Join(ca.storageKeyCAPrefix(), "intermediate.key")
394 }
modules/caddytls/connpolicy.go
+1 -1
@@ -316,7 +316,7 @@ func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy.Context) error {
316 return err
317 }
318 logFile, _, err := secretsLogPool.LoadOrNew(filename, func() (caddy.Destructor, error) {
319 - w, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
319 + w, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600)
320 return destructableWriter{w}, err
321 })
322 if err != nil {
modules/logging/filewriter.go
+1 -1
@@ -126,7 +126,7 @@ func (fw FileWriter) OpenWriter() (io.WriteCloser, error) {
126 }
127
128 // otherwise just open a regular file
129 - return os.OpenFile(fw.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
129 + return os.OpenFile(fw.Filename, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o666)
130 }
131
132 // UnmarshalCaddyfile sets up the module from Caddyfile tokens. Syntax:
modules/logging/filters.go
+1 -2
@@ -81,8 +81,7 @@ func hash(s string) string {
81 // of the SHA-256 hash of the content. Operates
82 // on string fields, or on arrays of strings
83 // where each string is hashed.
84 -type HashFilter struct {
85 -}
84 +type HashFilter struct{}
85
86 // CaddyModule returns the Caddy module information.
87 func (HashFilter) CaddyModule() caddy.ModuleInfo {
replacer.go
+2 -1
@@ -131,7 +131,8 @@ func (r *Replacer) ReplaceFunc(input string, f ReplacementFunc) (string, error)
131
132 func (r *Replacer) replace(input, empty string,
133 treatUnknownAsEmpty, errOnEmpty, errOnUnknown bool,
134 - f ReplacementFunc) (string, error) {
134 + f ReplacementFunc,
135 +) (string, error) {
136 if !strings.Contains(input, string(phOpen)) {
137 return input, nil
138 }