@marcel91200 / caddy Mirror · read-only / commits / 7dfd69cd
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 14, 05:15 UTC

chore: make the linter happier (#3245)

* chore: make the linter happier * chore: remove reference to maligned linter in .golangci.yml

Mohammed Al Sahaf committed Apr 9, 2020 at 00:31 UTC 7dfd69cdc5966ae454e35cd6e976686131bfda8d
19 files changed +28 -26
.golangci.yml
+2
@@ -8,6 +8,8 @@ linters-settings:
8 linters:
9 enable:
10 - bodyclose
11 + - prealloc
12 + - unconvert
13 - errcheck
14 - gofmt
15 - goimports
admin.go
+1 -1
@@ -149,7 +149,7 @@ func (admin AdminConfig) allowedOrigins(listen string) []string {
149 if admin.Origins == nil {
150 uniqueOrigins[listen] = struct{}{}
151 }
152 - var allowed []string
152 + allowed := make([]string, 0, len(uniqueOrigins))
153 for origin := range uniqueOrigins {
154 allowed = append(allowed, origin)
155 }
caddyconfig/httpcaddyfile/addresses.go
+3 -3
@@ -138,7 +138,7 @@ func (st *ServerType) mapAddressToServerBlocks(originalServerBlocks []serverBloc
138 // association from multiple addresses to multiple server blocks; i.e. each element of
139 // the returned slice) becomes a server definition in the output JSON.
140 func (st *ServerType) consolidateAddrMappings(addrToServerBlocks map[string][]serverBlock) []sbAddrAssociation {
141 - var sbaddrs []sbAddrAssociation
141 + sbaddrs := make([]sbAddrAssociation, 0, len(addrToServerBlocks))
142 for addr, sblocks := range addrToServerBlocks {
143 // we start with knowing that at least this address
144 // maps to these server blocks
@@ -199,7 +199,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
199 }
200
201 // the bind directive specifies hosts, but is optional
202 - var lnHosts []string
202 + lnHosts := make([]string, 0, len(sblock.pile))
203 for _, cfgVal := range sblock.pile["bind"] {
204 lnHosts = append(lnHosts, cfgVal.Value.([]string)...)
205 }
@@ -219,7 +219,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
219 }
220
221 // now turn map into list
222 - var listenersList []string
222 + listenersList := make([]string, 0, len(listeners))
223 for lnStr := range listeners {
224 listenersList = append(listenersList, lnStr)
225 }
caddyconfig/httpcaddyfile/httptype.go
+2 -2
@@ -50,7 +50,7 @@ func (st ServerType) Setup(originalServerBlocks []caddyfile.ServerBlock,
50 // chosen to handle a request - we actually will make each
51 // server block's route terminal so that only one will run
52 sbKeys := make(map[string]struct{})
53 - var serverBlocks []serverBlock
53 + serverBlocks := make([]serverBlock, 0, len(originalServerBlocks))
54 for i, sblock := range originalServerBlocks {
55 for j, k := range sblock.Keys {
56 if _, ok := sbKeys[k]; ok {
@@ -939,7 +939,7 @@ func (st *ServerType) compileEncodedMatcherSets(sblock serverBlock) ([]caddy.Mod
939 }
940
941 // finally, encode each of the matcher sets
942 - var matcherSetsEnc []caddy.ModuleMap
942 + matcherSetsEnc := make([]caddy.ModuleMap, 0, len(matcherSets))
943 for _, ms := range matcherSets {
944 msEncoded, err := encodeMatcherSet(ms)
945 if err != nil {
caddyconfig/httpcaddyfile/tlsapp.go
+1 -1
@@ -246,7 +246,7 @@ func (st ServerType) buildTLSApp(
246 }
247 clVal := reflect.ValueOf(cl)
248 for i := 0; i < clVal.Len(); i++ {
249 - combined = reflect.Append(reflect.Value(combined), clVal.Index(i))
249 + combined = reflect.Append(combined, clVal.Index(i))
250 }
251 loadersByName[name] = combined.Interface().(caddytls.CertificateLoader)
252 }
caddytest/caddytest.go
+1 -1
@@ -255,7 +255,7 @@ func AssertGetResponse(t *testing.T, requestURI string, statusCode int, expected
255 if !strings.Contains(body, expectedBody) {
256 t.Errorf("requesting \"%s\" expected response body \"%s\" but got \"%s\"", requestURI, expectedBody, body)
257 }
258 - return resp, string(body)
258 + return resp, body
259 }
260
261 // AssertGetResponseBody request a URI and assert the status code matches
logging.go
+2 -2
@@ -217,7 +217,7 @@ func (logging *Logging) Logger(mod Module) *zap.Logger {
217
218 multiCore := zapcore.NewTee(cores...)
219
220 - return zap.New(multiCore).Named(string(modID))
220 + return zap.New(multiCore).Named(modID)
221 }
222
223 // openWriter opens a writer using opener, and returns true if
@@ -464,7 +464,7 @@ func (cl *CustomLog) buildCore() {
464 }
465
466 func (cl *CustomLog) matchesModule(moduleID string) bool {
467 - return cl.loggerAllowed(string(moduleID), true)
467 + return cl.loggerAllowed(moduleID, true)
468 }
469
470 // loggerAllowed returns true if name is allowed to emit
modules.go
+3 -3
@@ -210,7 +210,7 @@ func GetModules(scope string) []ModuleInfo {
210 var mods []ModuleInfo
211 iterateModules:
212 for id, m := range modules {
213 - modParts := strings.Split(string(id), ".")
213 + modParts := strings.Split(id, ".")
214
215 // match only the next level of nesting
216 if len(modParts) != len(scopeParts)+1 {
@@ -241,9 +241,9 @@ func Modules() []string {
241 modulesMu.RLock()
242 defer modulesMu.RUnlock()
243
244 - var names []string
244 + names := make([]string, 0, len(modules))
245 for name := range modules {
246 - names = append(names, string(name))
246 + names = append(names, name)
247 }
248
249 sort.Strings(names)
modules/caddyhttp/caddyauth/basicauth.go
+2 -2
@@ -77,8 +77,8 @@ func (hba *HTTPBasicAuth) Provision(ctx caddy.Context) error {
77 }
78
79 acct.Username = repl.ReplaceAll(acct.Username, "")
80 - acct.Password = repl.ReplaceAll(string(acct.Password), "")
81 - acct.Salt = repl.ReplaceAll(string(acct.Salt), "")
80 + acct.Password = repl.ReplaceAll(acct.Password, "")
81 + acct.Salt = repl.ReplaceAll(acct.Salt, "")
82
83 if acct.Username == "" || acct.Password == "" {
84 return fmt.Errorf("account %d: username and password are required", i)
modules/caddyhttp/caddyauth/command.go
+1 -1
@@ -76,7 +76,7 @@ func cmdHashPassword(fs caddycmd.Flags) (int, error) {
76 return caddy.ExitCodeFailedStartup, err
77 }
78
79 - hashBase64 := base64.StdEncoding.EncodeToString([]byte(hash))
79 + hashBase64 := base64.StdEncoding.EncodeToString(hash)
80
81 fmt.Println(hashBase64)
82
modules/caddyhttp/fileserver/caddyfile.go
+1 -1
@@ -146,7 +146,7 @@ func parseTryFiles(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
146 // if there are query strings in the list, we have to split into
147 // a separate route for each item with a query string, because
148 // the rewrite is different for that item
149 - var try []string
149 + try := make([]string, 0, len(tryFiles))
150 for _, item := range tryFiles {
151 if idx := strings.Index(item, "?"); idx >= 0 {
152 if len(try) > 0 {
modules/caddyhttp/replacer.go
+1 -1
@@ -188,7 +188,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
188 if strings.HasPrefix(key, varsReplPrefix) {
189 varName := key[len(varsReplPrefix):]
190 tbl := req.Context().Value(VarsCtxKey).(map[string]interface{})
191 - raw, _ := tbl[varName]
191 + raw := tbl[varName]
192 // variables can be dynamic, so always return true
193 // even when it may not be set; treat as empty then
194 return raw, true
modules/caddyhttp/responsewriter.go
+2 -2
@@ -76,13 +76,13 @@ var ErrNotImplemented = fmt.Errorf("method not implemented")
76
77 type responseRecorder struct {
78 *ResponseWriterWrapper
79 - wroteHeader bool
79 statusCode int
80 buf *bytes.Buffer
81 shouldBuffer ShouldBufferFunc
83 - stream bool
82 size int
83 header http.Header
84 + wroteHeader bool
85 + stream bool
86 }
87
88 // NewResponseRecorder returns a new ResponseRecorder that can be
modules/caddyhttp/routes.go
+1 -1
@@ -167,7 +167,7 @@ func (routes RouteList) ProvisionHandlers(ctx caddy.Context) error {
167 // This should only be done once: after all the routes have
168 // been provisioned, and before serving requests.
169 func (routes RouteList) Compile(next Handler) Handler {
170 - var mid []Middleware
170 + mid := make([]Middleware, 0, len(routes))
171 for _, route := range routes {
172 mid = append(mid, wrapRoute(route))
173 }
modules/caddyhttp/templates/frontmatter.go
+1 -1
@@ -33,7 +33,7 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) {
33 // see what kind of front matter there is, if any
34 var closingFence string
35 var fmParser func([]byte) (map[string]interface{}, error)
36 - switch string(firstLine) {
36 + switch firstLine {
37 case yamlFrontMatterFenceOpen:
38 fmParser = yamlFrontMatter
39 closingFence = yamlFrontMatterFenceClose
modules/caddytls/automation.go
+1 -1
@@ -150,7 +150,7 @@ func (ap *AutomationPolicy) Provision(tlsApp *TLS) error {
150 // none of the subjects qualify for a public certificate,
151 // set the issuer to internal so that these names can all
152 // get certificates; critically, we can only do this if an
153 - // issuer is not explictly configured (IssuerRaw, vs. just
153 + // issuer is not explicitly configured (IssuerRaw, vs. just
154 // Issuer) AND if the list of subjects is non-empty
155 if ap.IssuerRaw == nil && len(ap.Subjects) > 0 {
156 var anyPublic bool
modules/caddytls/fileloader.go
+1 -1
@@ -57,7 +57,7 @@ type CertKeyFilePair struct {
57
58 // LoadCertificates returns the certificates to be loaded by fl.
59 func (fl FileLoader) LoadCertificates() ([]Certificate, error) {
60 - var certs []Certificate
60 + certs := make([]Certificate, 0, len(fl))
61 for _, pair := range fl {
62 certData, err := ioutil.ReadFile(pair.Certificate)
63 if err != nil {
modules/caddytls/pemloader.go
+1 -1
@@ -54,7 +54,7 @@ type CertKeyPEMPair struct {
54
55 // LoadCertificates returns the certificates contained in pl.
56 func (pl PEMLoader) LoadCertificates() ([]Certificate, error) {
57 - var certs []Certificate
57 + certs := make([]Certificate, 0, len(pl))
58 for i, pair := range pl {
59 cert, err := tls.X509KeyPair([]byte(pair.CertificatePEM), []byte(pair.KeyPEM))
60 if err != nil {
modules/caddytls/tls.go
+1 -1
@@ -471,7 +471,7 @@ func (t *TLS) moveCertificates() error {
471 }
472
473 // get list of used CAs
474 - var oldCANames []string
474 + oldCANames := make([]string, 0, len(oldAcmeCas))
475 for _, fi := range oldAcmeCas {
476 if !fi.IsDir() {
477 continue