mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
chore: make the linter happier (#3245)
* chore: make the linter happier * chore: remove reference to maligned linter in .golangci.yml
This commit is contained in:
parent
28fdf64dc5
commit
7dfd69cdc5
19 changed files with 28 additions and 26 deletions
|
@ -8,6 +8,8 @@ linters-settings:
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
- bodyclose
|
||||||
|
- prealloc
|
||||||
|
- unconvert
|
||||||
- errcheck
|
- errcheck
|
||||||
- gofmt
|
- gofmt
|
||||||
- goimports
|
- goimports
|
||||||
|
|
2
admin.go
2
admin.go
|
@ -149,7 +149,7 @@ func (admin AdminConfig) allowedOrigins(listen string) []string {
|
||||||
if admin.Origins == nil {
|
if admin.Origins == nil {
|
||||||
uniqueOrigins[listen] = struct{}{}
|
uniqueOrigins[listen] = struct{}{}
|
||||||
}
|
}
|
||||||
var allowed []string
|
allowed := make([]string, 0, len(uniqueOrigins))
|
||||||
for origin := range uniqueOrigins {
|
for origin := range uniqueOrigins {
|
||||||
allowed = append(allowed, origin)
|
allowed = append(allowed, origin)
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ func (st *ServerType) mapAddressToServerBlocks(originalServerBlocks []serverBloc
|
||||||
// association from multiple addresses to multiple server blocks; i.e. each element of
|
// association from multiple addresses to multiple server blocks; i.e. each element of
|
||||||
// the returned slice) becomes a server definition in the output JSON.
|
// the returned slice) becomes a server definition in the output JSON.
|
||||||
func (st *ServerType) consolidateAddrMappings(addrToServerBlocks map[string][]serverBlock) []sbAddrAssociation {
|
func (st *ServerType) consolidateAddrMappings(addrToServerBlocks map[string][]serverBlock) []sbAddrAssociation {
|
||||||
var sbaddrs []sbAddrAssociation
|
sbaddrs := make([]sbAddrAssociation, 0, len(addrToServerBlocks))
|
||||||
for addr, sblocks := range addrToServerBlocks {
|
for addr, sblocks := range addrToServerBlocks {
|
||||||
// we start with knowing that at least this address
|
// we start with knowing that at least this address
|
||||||
// maps to these server blocks
|
// maps to these server blocks
|
||||||
|
@ -199,7 +199,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
|
||||||
}
|
}
|
||||||
|
|
||||||
// the bind directive specifies hosts, but is optional
|
// the bind directive specifies hosts, but is optional
|
||||||
var lnHosts []string
|
lnHosts := make([]string, 0, len(sblock.pile))
|
||||||
for _, cfgVal := range sblock.pile["bind"] {
|
for _, cfgVal := range sblock.pile["bind"] {
|
||||||
lnHosts = append(lnHosts, cfgVal.Value.([]string)...)
|
lnHosts = append(lnHosts, cfgVal.Value.([]string)...)
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
|
||||||
}
|
}
|
||||||
|
|
||||||
// now turn map into list
|
// now turn map into list
|
||||||
var listenersList []string
|
listenersList := make([]string, 0, len(listeners))
|
||||||
for lnStr := range listeners {
|
for lnStr := range listeners {
|
||||||
listenersList = append(listenersList, lnStr)
|
listenersList = append(listenersList, lnStr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ func (st ServerType) Setup(originalServerBlocks []caddyfile.ServerBlock,
|
||||||
// chosen to handle a request - we actually will make each
|
// chosen to handle a request - we actually will make each
|
||||||
// server block's route terminal so that only one will run
|
// server block's route terminal so that only one will run
|
||||||
sbKeys := make(map[string]struct{})
|
sbKeys := make(map[string]struct{})
|
||||||
var serverBlocks []serverBlock
|
serverBlocks := make([]serverBlock, 0, len(originalServerBlocks))
|
||||||
for i, sblock := range originalServerBlocks {
|
for i, sblock := range originalServerBlocks {
|
||||||
for j, k := range sblock.Keys {
|
for j, k := range sblock.Keys {
|
||||||
if _, ok := sbKeys[k]; ok {
|
if _, ok := sbKeys[k]; ok {
|
||||||
|
@ -939,7 +939,7 @@ func (st *ServerType) compileEncodedMatcherSets(sblock serverBlock) ([]caddy.Mod
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally, encode each of the matcher sets
|
// finally, encode each of the matcher sets
|
||||||
var matcherSetsEnc []caddy.ModuleMap
|
matcherSetsEnc := make([]caddy.ModuleMap, 0, len(matcherSets))
|
||||||
for _, ms := range matcherSets {
|
for _, ms := range matcherSets {
|
||||||
msEncoded, err := encodeMatcherSet(ms)
|
msEncoded, err := encodeMatcherSet(ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -246,7 +246,7 @@ func (st ServerType) buildTLSApp(
|
||||||
}
|
}
|
||||||
clVal := reflect.ValueOf(cl)
|
clVal := reflect.ValueOf(cl)
|
||||||
for i := 0; i < clVal.Len(); i++ {
|
for i := 0; i < clVal.Len(); i++ {
|
||||||
combined = reflect.Append(reflect.Value(combined), clVal.Index(i))
|
combined = reflect.Append(combined, clVal.Index(i))
|
||||||
}
|
}
|
||||||
loadersByName[name] = combined.Interface().(caddytls.CertificateLoader)
|
loadersByName[name] = combined.Interface().(caddytls.CertificateLoader)
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ func AssertGetResponse(t *testing.T, requestURI string, statusCode int, expected
|
||||||
if !strings.Contains(body, expectedBody) {
|
if !strings.Contains(body, expectedBody) {
|
||||||
t.Errorf("requesting \"%s\" expected response body \"%s\" but got \"%s\"", requestURI, expectedBody, body)
|
t.Errorf("requesting \"%s\" expected response body \"%s\" but got \"%s\"", requestURI, expectedBody, body)
|
||||||
}
|
}
|
||||||
return resp, string(body)
|
return resp, body
|
||||||
}
|
}
|
||||||
|
|
||||||
// AssertGetResponseBody request a URI and assert the status code matches
|
// AssertGetResponseBody request a URI and assert the status code matches
|
||||||
|
|
|
@ -217,7 +217,7 @@ func (logging *Logging) Logger(mod Module) *zap.Logger {
|
||||||
|
|
||||||
multiCore := zapcore.NewTee(cores...)
|
multiCore := zapcore.NewTee(cores...)
|
||||||
|
|
||||||
return zap.New(multiCore).Named(string(modID))
|
return zap.New(multiCore).Named(modID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// openWriter opens a writer using opener, and returns true if
|
// openWriter opens a writer using opener, and returns true if
|
||||||
|
@ -464,7 +464,7 @@ func (cl *CustomLog) buildCore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cl *CustomLog) matchesModule(moduleID string) bool {
|
func (cl *CustomLog) matchesModule(moduleID string) bool {
|
||||||
return cl.loggerAllowed(string(moduleID), true)
|
return cl.loggerAllowed(moduleID, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// loggerAllowed returns true if name is allowed to emit
|
// loggerAllowed returns true if name is allowed to emit
|
||||||
|
|
|
@ -210,7 +210,7 @@ func GetModules(scope string) []ModuleInfo {
|
||||||
var mods []ModuleInfo
|
var mods []ModuleInfo
|
||||||
iterateModules:
|
iterateModules:
|
||||||
for id, m := range modules {
|
for id, m := range modules {
|
||||||
modParts := strings.Split(string(id), ".")
|
modParts := strings.Split(id, ".")
|
||||||
|
|
||||||
// match only the next level of nesting
|
// match only the next level of nesting
|
||||||
if len(modParts) != len(scopeParts)+1 {
|
if len(modParts) != len(scopeParts)+1 {
|
||||||
|
@ -241,9 +241,9 @@ func Modules() []string {
|
||||||
modulesMu.RLock()
|
modulesMu.RLock()
|
||||||
defer modulesMu.RUnlock()
|
defer modulesMu.RUnlock()
|
||||||
|
|
||||||
var names []string
|
names := make([]string, 0, len(modules))
|
||||||
for name := range modules {
|
for name := range modules {
|
||||||
names = append(names, string(name))
|
names = append(names, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(names)
|
sort.Strings(names)
|
||||||
|
|
|
@ -77,8 +77,8 @@ func (hba *HTTPBasicAuth) Provision(ctx caddy.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
acct.Username = repl.ReplaceAll(acct.Username, "")
|
acct.Username = repl.ReplaceAll(acct.Username, "")
|
||||||
acct.Password = repl.ReplaceAll(string(acct.Password), "")
|
acct.Password = repl.ReplaceAll(acct.Password, "")
|
||||||
acct.Salt = repl.ReplaceAll(string(acct.Salt), "")
|
acct.Salt = repl.ReplaceAll(acct.Salt, "")
|
||||||
|
|
||||||
if acct.Username == "" || acct.Password == "" {
|
if acct.Username == "" || acct.Password == "" {
|
||||||
return fmt.Errorf("account %d: username and password are required", i)
|
return fmt.Errorf("account %d: username and password are required", i)
|
||||||
|
|
|
@ -76,7 +76,7 @@ func cmdHashPassword(fs caddycmd.Flags) (int, error) {
|
||||||
return caddy.ExitCodeFailedStartup, err
|
return caddy.ExitCodeFailedStartup, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hashBase64 := base64.StdEncoding.EncodeToString([]byte(hash))
|
hashBase64 := base64.StdEncoding.EncodeToString(hash)
|
||||||
|
|
||||||
fmt.Println(hashBase64)
|
fmt.Println(hashBase64)
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ func parseTryFiles(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error)
|
||||||
// if there are query strings in the list, we have to split into
|
// if there are query strings in the list, we have to split into
|
||||||
// a separate route for each item with a query string, because
|
// a separate route for each item with a query string, because
|
||||||
// the rewrite is different for that item
|
// the rewrite is different for that item
|
||||||
var try []string
|
try := make([]string, 0, len(tryFiles))
|
||||||
for _, item := range tryFiles {
|
for _, item := range tryFiles {
|
||||||
if idx := strings.Index(item, "?"); idx >= 0 {
|
if idx := strings.Index(item, "?"); idx >= 0 {
|
||||||
if len(try) > 0 {
|
if len(try) > 0 {
|
||||||
|
|
|
@ -188,7 +188,7 @@ func addHTTPVarsToReplacer(repl *caddy.Replacer, req *http.Request, w http.Respo
|
||||||
if strings.HasPrefix(key, varsReplPrefix) {
|
if strings.HasPrefix(key, varsReplPrefix) {
|
||||||
varName := key[len(varsReplPrefix):]
|
varName := key[len(varsReplPrefix):]
|
||||||
tbl := req.Context().Value(VarsCtxKey).(map[string]interface{})
|
tbl := req.Context().Value(VarsCtxKey).(map[string]interface{})
|
||||||
raw, _ := tbl[varName]
|
raw := tbl[varName]
|
||||||
// variables can be dynamic, so always return true
|
// variables can be dynamic, so always return true
|
||||||
// even when it may not be set; treat as empty then
|
// even when it may not be set; treat as empty then
|
||||||
return raw, true
|
return raw, true
|
||||||
|
|
|
@ -76,13 +76,13 @@ var ErrNotImplemented = fmt.Errorf("method not implemented")
|
||||||
|
|
||||||
type responseRecorder struct {
|
type responseRecorder struct {
|
||||||
*ResponseWriterWrapper
|
*ResponseWriterWrapper
|
||||||
wroteHeader bool
|
|
||||||
statusCode int
|
statusCode int
|
||||||
buf *bytes.Buffer
|
buf *bytes.Buffer
|
||||||
shouldBuffer ShouldBufferFunc
|
shouldBuffer ShouldBufferFunc
|
||||||
stream bool
|
|
||||||
size int
|
size int
|
||||||
header http.Header
|
header http.Header
|
||||||
|
wroteHeader bool
|
||||||
|
stream bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewResponseRecorder returns a new ResponseRecorder that can be
|
// NewResponseRecorder returns a new ResponseRecorder that can be
|
||||||
|
|
|
@ -167,7 +167,7 @@ func (routes RouteList) ProvisionHandlers(ctx caddy.Context) error {
|
||||||
// This should only be done once: after all the routes have
|
// This should only be done once: after all the routes have
|
||||||
// been provisioned, and before serving requests.
|
// been provisioned, and before serving requests.
|
||||||
func (routes RouteList) Compile(next Handler) Handler {
|
func (routes RouteList) Compile(next Handler) Handler {
|
||||||
var mid []Middleware
|
mid := make([]Middleware, 0, len(routes))
|
||||||
for _, route := range routes {
|
for _, route := range routes {
|
||||||
mid = append(mid, wrapRoute(route))
|
mid = append(mid, wrapRoute(route))
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ func extractFrontMatter(input string) (map[string]interface{}, string, error) {
|
||||||
// see what kind of front matter there is, if any
|
// see what kind of front matter there is, if any
|
||||||
var closingFence string
|
var closingFence string
|
||||||
var fmParser func([]byte) (map[string]interface{}, error)
|
var fmParser func([]byte) (map[string]interface{}, error)
|
||||||
switch string(firstLine) {
|
switch firstLine {
|
||||||
case yamlFrontMatterFenceOpen:
|
case yamlFrontMatterFenceOpen:
|
||||||
fmParser = yamlFrontMatter
|
fmParser = yamlFrontMatter
|
||||||
closingFence = yamlFrontMatterFenceClose
|
closingFence = yamlFrontMatterFenceClose
|
||||||
|
|
|
@ -150,7 +150,7 @@ func (ap *AutomationPolicy) Provision(tlsApp *TLS) error {
|
||||||
// none of the subjects qualify for a public certificate,
|
// none of the subjects qualify for a public certificate,
|
||||||
// set the issuer to internal so that these names can all
|
// set the issuer to internal so that these names can all
|
||||||
// get certificates; critically, we can only do this if an
|
// get certificates; critically, we can only do this if an
|
||||||
// issuer is not explictly configured (IssuerRaw, vs. just
|
// issuer is not explicitly configured (IssuerRaw, vs. just
|
||||||
// Issuer) AND if the list of subjects is non-empty
|
// Issuer) AND if the list of subjects is non-empty
|
||||||
if ap.IssuerRaw == nil && len(ap.Subjects) > 0 {
|
if ap.IssuerRaw == nil && len(ap.Subjects) > 0 {
|
||||||
var anyPublic bool
|
var anyPublic bool
|
||||||
|
|
|
@ -57,7 +57,7 @@ type CertKeyFilePair struct {
|
||||||
|
|
||||||
// LoadCertificates returns the certificates to be loaded by fl.
|
// LoadCertificates returns the certificates to be loaded by fl.
|
||||||
func (fl FileLoader) LoadCertificates() ([]Certificate, error) {
|
func (fl FileLoader) LoadCertificates() ([]Certificate, error) {
|
||||||
var certs []Certificate
|
certs := make([]Certificate, 0, len(fl))
|
||||||
for _, pair := range fl {
|
for _, pair := range fl {
|
||||||
certData, err := ioutil.ReadFile(pair.Certificate)
|
certData, err := ioutil.ReadFile(pair.Certificate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -54,7 +54,7 @@ type CertKeyPEMPair struct {
|
||||||
|
|
||||||
// LoadCertificates returns the certificates contained in pl.
|
// LoadCertificates returns the certificates contained in pl.
|
||||||
func (pl PEMLoader) LoadCertificates() ([]Certificate, error) {
|
func (pl PEMLoader) LoadCertificates() ([]Certificate, error) {
|
||||||
var certs []Certificate
|
certs := make([]Certificate, 0, len(pl))
|
||||||
for i, pair := range pl {
|
for i, pair := range pl {
|
||||||
cert, err := tls.X509KeyPair([]byte(pair.CertificatePEM), []byte(pair.KeyPEM))
|
cert, err := tls.X509KeyPair([]byte(pair.CertificatePEM), []byte(pair.KeyPEM))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -471,7 +471,7 @@ func (t *TLS) moveCertificates() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// get list of used CAs
|
// get list of used CAs
|
||||||
var oldCANames []string
|
oldCANames := make([]string, 0, len(oldAcmeCas))
|
||||||
for _, fi := range oldAcmeCas {
|
for _, fi := range oldAcmeCas {
|
||||||
if !fi.IsDir() {
|
if !fi.IsDir() {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue