Skip to content

Commit 816a73a

Browse files
committed
Manual inlines
1 parent 72fb7db commit 816a73a

9 files changed

Lines changed: 12 additions & 45 deletions

File tree

dev-tools/mage/build.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ func DefaultBuildArgs() BuildArgs {
128128
// The list of supported platforms is compiled based on the Go release notes: https://golang.org/doc/devel/release.html
129129
// The list has been updated according to the Go version: 1.16
130130
func positionIndependentCodeSupported() bool {
131-
return oneOf(Platform.GOOS, "darwin") ||
132-
(Platform.GOOS == "linux" && oneOf(Platform.GOARCH, "riscv64", "amd64", "arm", "arm64", "ppc64le", "386")) ||
131+
return slices.Contains([]string{"darwin"}, Platform.GOOS) ||
132+
(Platform.GOOS == "linux" && slices.Contains([]string{"riscv64", "amd64", "arm", "arm64", "ppc64le", "386"}, Platform.GOARCH)) ||
133133
(Platform.GOOS == "aix" && Platform.GOARCH == "ppc64") ||
134134

135135
// Windows 32bit supports ASLR, but Windows Server 2003 and earlier do not.
@@ -138,10 +138,6 @@ func positionIndependentCodeSupported() bool {
138138
(Platform.GOOS == "windows")
139139
}
140140

141-
func oneOf(value string, lst ...string) bool {
142-
return slices.Contains(lst, value)
143-
}
144-
145141
// DefaultGolangCrossBuildArgs returns the default BuildArgs for use in
146142
// cross-builds.
147143
func DefaultGolangCrossBuildArgs() BuildArgs {

filebeat/input/container/config.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,13 @@ type config struct {
3838

3939
// Validate validates the config.
4040
func (c *config) Validate() error {
41-
if !stringInSlice(c.Stream, []string{"all", "stdout", "stderr"}) {
41+
if !slices.Contains([]string{"all", "stdout", "stderr"}, c.Stream) {
4242
return fmt.Errorf("invalid value for stream: %s, supported values are: all, stdout, stderr", c.Stream)
4343
}
4444

45-
if !stringInSlice(strings.ToLower(c.Format), []string{"auto", "docker", "cri"}) {
45+
if !slices.Contains([]string{"auto", "docker", "cri"}, strings.ToLower(c.Format)) {
4646
return fmt.Errorf("invalid value for format: %s, supported values are: auto, docker, cri", c.Format)
4747
}
4848

4949
return nil
5050
}
51-
52-
func stringInSlice(str string, list []string) bool {
53-
return slices.Contains(list, str)
54-
}

filebeat/input/kafka/input.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (input *kafkaInput) Test(ctx input.TestContext) error {
9595

9696
var missingTopics []string
9797
for _, neededTopic := range input.config.Topics {
98-
if !contains(topics, neededTopic) {
98+
if !slices.Contains(topics, neededTopic) {
9999
missingTopics = append(missingTopics, neededTopic)
100100
}
101101
}
@@ -469,7 +469,3 @@ func composeMessage(timestamp time.Time, content []byte, kafkaFields mapstr.M, a
469469
},
470470
}
471471
}
472-
473-
func contains(elements []string, element string) bool {
474-
return slices.Contains(elements, element)
475-
}

libbeat/mapping/field.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func validateAllowedValue(fieldName string, propertyName string, propertyValue s
222222
if len(allowedPropertyValues) == 0 {
223223
return fmt.Errorf("no %s expected for field '%s', found: %s", propertyName, fieldName, propertyValue)
224224
}
225-
if !stringsContains(allowedPropertyValues, propertyValue) {
225+
if !slices.Contains(allowedPropertyValues, propertyValue) {
226226
return fmt.Errorf(
227227
"unexpected %s '%s' for field '%s', expected one of: %s",
228228
propertyName, propertyValue, fieldName, strings.Join(allowedPropertyValues, ", "),
@@ -231,10 +231,6 @@ func validateAllowedValue(fieldName string, propertyName string, propertyValue s
231231
return nil
232232
}
233233

234-
func stringsContains(haystack []string, needle string) bool {
235-
return slices.Contains(haystack, needle)
236-
}
237-
238234
func LoadFieldsYaml(path string) (Fields, error) {
239235
var keys []Field
240236

libbeat/outputs/elasticsearch/config_presets.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func ApplyPreset(preset string, userConfig *config.C) ([]string, *config.C, erro
103103
for _, key := range userKeys {
104104
if strings.HasPrefix(key, "queue.") && presetConfiguresQueue {
105105
overridden = append(overridden, key)
106-
} else if listContainsStr(presetKeys, key) {
106+
} else if slices.Contains(presetKeys, key) {
107107
overridden = append(overridden, key)
108108
}
109109
}
@@ -119,11 +119,6 @@ func ApplyPreset(preset string, userConfig *config.C) ([]string, *config.C, erro
119119
return overridden, presetConfig, nil
120120
}
121121

122-
// TODO: Replace this with slices.Contains once we hit Go 1.21.
123-
func listContainsStr(list []string, str string) bool {
124-
return slices.Contains(list, str)
125-
}
126-
127122
func listContainsPrefix(list []string, prefix string) bool {
128123
for _, s := range list {
129124
if strings.HasPrefix(s, prefix) {

libbeat/tests/compose/project.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"fmt"
2626
"os"
2727
"path/filepath"
28-
"slices"
2928
"syscall"
3029
"time"
3130

@@ -373,7 +372,3 @@ type containerServiceInfo struct {
373372
func (i *containerServiceInfo) Name() string {
374373
return i.ServiceName()
375374
}
376-
377-
func contains(list []string, item string) bool {
378-
return slices.Contains(list, item)
379-
}

libbeat/tests/compose/wrapper.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"path/filepath"
3333
"regexp"
3434
"runtime"
35+
"slices"
3536
"strconv"
3637
"strings"
3738
"time"
@@ -374,7 +375,7 @@ func (d *wrapperDriver) containers(ctx context.Context, projectFilter Filter, fi
374375
}
375376
for _, container := range listResult.Items {
376377
serviceName, ok := container.Labels[labelComposeService]
377-
if !ok || !contains(serviceNames, serviceName) {
378+
if !ok || !slices.Contains(serviceNames, serviceName) {
378379
// Service is not defined in current docker compose file, ignore it
379380
continue
380381
}
@@ -403,7 +404,7 @@ func (d *wrapperDriver) KillOld(ctx context.Context, except []string) error {
403404
for _, c := range listResult.Items {
404405
container := wrapperContainer{info: c}
405406
serviceName, ok := container.info.Labels[labelComposeService]
406-
if !ok || contains(except, serviceName) {
407+
if !ok || slices.Contains(except, serviceName) {
407408
continue
408409
}
409410

metricbeat/module/docker/diskio/helper.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func getNewStats(skip []uint64, time time.Time, blkioEntry []container.BlkioStat
166166

167167
// certain devices, like software raid and device-mapper devices, will just control and re-report the disks
168168
// under them in the hierarchy. We want to skip them, lest we merely duplicate the metrics.
169-
if skipDev(myEntry.Major, skip) {
169+
if slices.Contains(skip, myEntry.Major) {
170170
continue
171171
}
172172
// These op value strings can either be Capitalized or lowercase, depending on the platform.
@@ -183,10 +183,6 @@ func getNewStats(skip []uint64, time time.Time, blkioEntry []container.BlkioStat
183183
return stats
184184
}
185185

186-
func skipDev(major uint64, skipList []uint64) bool {
187-
return slices.Contains(skipList, major)
188-
}
189-
190186
func (io *BlkioService) getReadPs(old *BlkioRaw, new *BlkioRaw) float64 {
191187
duration := new.Time.Sub(old.Time)
192188
return calculatePerSecond(duration, old.reads, new.reads)

x-pack/libbeat/common/cloudfoundry/config.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@ func (c *Config) InitDefaults() {
5656

5757
func (c *Config) Validate() error {
5858
supportedVersions := []string{ConsumerVersionV1, ConsumerVersionV2}
59-
if !anyOf(supportedVersions, c.Version) {
59+
if !slices.Contains(supportedVersions, c.Version) {
6060
return fmt.Errorf("not supported version %v, expected one of %s", c.Version, strings.Join(supportedVersions, ", "))
6161
}
6262
return nil
6363
}
64-
65-
func anyOf(elems []string, s string) bool {
66-
return slices.Contains(elems, s)
67-
}

0 commit comments

Comments
 (0)