├── .github └── workflows │ ├── build.yml │ └── codeql-analysis.yml ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── client.go ├── client_test.go ├── config.go ├── config_test.go ├── go.mod ├── go.sum ├── sysctl.go ├── sysctl_linux_test.go ├── testdata ├── client │ ├── config-empty.conf │ ├── config-missing-keys.conf │ ├── config-ok.conf │ ├── nok │ │ └── f │ └── ok │ │ ├── d │ │ ├── d │ │ │ ├── f1 │ │ │ └── f2 │ │ └── f │ │ └── f └── config │ ├── sysctl-a.conf │ ├── sysctl-b.conf │ ├── sysctl-correct.conf │ ├── sysctl-empty.conf │ ├── sysctl-error.conf │ └── sysctl-only-comments.conf ├── tools.go └── vendor ├── github.com ├── BurntSushi │ └── toml │ │ ├── .gitignore │ │ ├── COPYING │ │ ├── README.md │ │ ├── decode.go │ │ ├── decode_go116.go │ │ ├── deprecated.go │ │ ├── doc.go │ │ ├── encode.go │ │ ├── error.go │ │ ├── internal │ │ └── tz.go │ │ ├── lex.go │ │ ├── meta.go │ │ ├── parse.go │ │ ├── type_fields.go │ │ └── type_toml.go └── google │ └── go-cmp │ ├── LICENSE │ └── cmp │ ├── compare.go │ ├── export_panic.go │ ├── export_unsafe.go │ ├── internal │ ├── diff │ │ ├── debug_disable.go │ │ ├── debug_enable.go │ │ └── diff.go │ ├── flags │ │ └── flags.go │ ├── function │ │ └── func.go │ └── value │ │ ├── name.go │ │ ├── pointer_purego.go │ │ ├── pointer_unsafe.go │ │ └── sort.go │ ├── options.go │ ├── path.go │ ├── report.go │ ├── report_compare.go │ ├── report_references.go │ ├── report_reflect.go │ ├── report_slices.go │ ├── report_text.go │ └── report_value.go ├── golang.org └── x │ ├── exp │ └── typeparams │ │ ├── LICENSE │ │ ├── common.go │ │ ├── normalize.go │ │ ├── termlist.go │ │ ├── typeparams_go117.go │ │ ├── typeparams_go118.go │ │ └── typeterm.go │ ├── mod │ ├── LICENSE │ ├── PATENTS │ ├── internal │ │ └── lazyregexp │ │ │ └── lazyre.go │ ├── module │ │ ├── module.go │ │ └── pseudo.go │ └── semver │ │ └── semver.go │ ├── sync │ ├── LICENSE │ ├── PATENTS │ └── errgroup │ │ └── errgroup.go │ ├── sys │ ├── LICENSE │ ├── PATENTS │ └── execabs │ │ ├── execabs.go │ │ ├── execabs_go118.go │ │ └── execabs_go119.go │ ├── tools │ ├── LICENSE │ ├── PATENTS │ ├── go │ │ ├── analysis │ │ │ ├── analysis.go │ │ │ ├── diagnostic.go │ │ │ ├── doc.go │ │ │ ├── internal │ │ │ │ ├── analysisflags │ │ │ │ │ ├── flags.go │ │ │ │ │ └── help.go │ │ │ │ └── checker │ │ │ │ │ └── checker.go │ │ │ ├── passes │ │ │ │ ├── buildssa │ │ │ │ │ └── buildssa.go │ │ │ │ ├── inspect │ │ │ │ │ └── inspect.go │ │ │ │ ├── internal │ │ │ │ │ └── analysisutil │ │ │ │ │ │ ├── extractdoc.go │ │ │ │ │ │ └── util.go │ │ │ │ └── nilness │ │ │ │ │ ├── cmd │ │ │ │ │ └── nilness │ │ │ │ │ │ └── main.go │ │ │ │ │ ├── doc.go │ │ │ │ │ └── nilness.go │ │ │ ├── singlechecker │ │ │ │ └── singlechecker.go │ │ │ ├── unitchecker │ │ │ │ ├── unitchecker.go │ │ │ │ └── unitchecker112.go │ │ │ └── validate.go │ │ ├── ast │ │ │ ├── astutil │ │ │ │ ├── enclosing.go │ │ │ │ ├── imports.go │ │ │ │ ├── rewrite.go │ │ │ │ └── util.go │ │ │ └── inspector │ │ │ │ ├── inspector.go │ │ │ │ └── typeof.go │ │ ├── buildutil │ │ │ ├── allpackages.go │ │ │ ├── fakecontext.go │ │ │ ├── overlay.go │ │ │ ├── tags.go │ │ │ └── util.go │ │ ├── callgraph │ │ │ ├── callgraph.go │ │ │ ├── cha │ │ │ │ └── cha.go │ │ │ ├── util.go │ │ │ └── vta │ │ │ │ ├── graph.go │ │ │ │ ├── internal │ │ │ │ └── trie │ │ │ │ │ ├── bits.go │ │ │ │ │ ├── builder.go │ │ │ │ │ ├── scope.go │ │ │ │ │ └── trie.go │ │ │ │ ├── propagation.go │ │ │ │ ├── utils.go │ │ │ │ └── vta.go │ │ ├── gcexportdata │ │ │ ├── gcexportdata.go │ │ │ └── importer.go │ │ ├── internal │ │ │ ├── cgo │ │ │ │ ├── cgo.go │ │ │ │ └── cgo_pkgconfig.go │ │ │ └── packagesdriver │ │ │ │ └── sizes.go │ │ ├── loader │ │ │ ├── doc.go │ │ │ ├── loader.go │ │ │ └── util.go │ │ ├── packages │ │ │ ├── doc.go │ │ │ ├── external.go │ │ │ ├── golist.go │ │ │ ├── golist_overlay.go │ │ │ ├── loadmode_string.go │ │ │ ├── packages.go │ │ │ └── visit.go │ │ ├── ssa │ │ │ ├── TODO │ │ │ ├── block.go │ │ │ ├── blockopt.go │ │ │ ├── builder.go │ │ │ ├── const.go │ │ │ ├── coretype.go │ │ │ ├── create.go │ │ │ ├── doc.go │ │ │ ├── dom.go │ │ │ ├── emit.go │ │ │ ├── func.go │ │ │ ├── identical.go │ │ │ ├── identical_17.go │ │ │ ├── instantiate.go │ │ │ ├── lift.go │ │ │ ├── lvalue.go │ │ │ ├── methods.go │ │ │ ├── mode.go │ │ │ ├── parameterized.go │ │ │ ├── print.go │ │ │ ├── sanity.go │ │ │ ├── source.go │ │ │ ├── ssa.go │ │ │ ├── ssautil │ │ │ │ ├── load.go │ │ │ │ ├── switch.go │ │ │ │ └── visit.go │ │ │ ├── subst.go │ │ │ ├── util.go │ │ │ └── wrappers.go │ │ └── types │ │ │ ├── objectpath │ │ │ └── objectpath.go │ │ │ └── typeutil │ │ │ ├── callee.go │ │ │ ├── imports.go │ │ │ ├── map.go │ │ │ ├── methodsetcache.go │ │ │ └── ui.go │ └── internal │ │ ├── diff │ │ ├── diff.go │ │ ├── lcs │ │ │ ├── common.go │ │ │ ├── doc.go │ │ │ ├── git.sh │ │ │ ├── labels.go │ │ │ ├── old.go │ │ │ └── sequence.go │ │ ├── ndiff.go │ │ └── unified.go │ │ ├── event │ │ ├── core │ │ │ ├── event.go │ │ │ ├── export.go │ │ │ └── fast.go │ │ ├── doc.go │ │ ├── event.go │ │ ├── keys │ │ │ ├── keys.go │ │ │ └── standard.go │ │ └── label │ │ │ └── label.go │ │ ├── facts │ │ ├── facts.go │ │ └── imports.go │ │ ├── gcimporter │ │ ├── bexport.go │ │ ├── bimport.go │ │ ├── exportdata.go │ │ ├── gcimporter.go │ │ ├── iexport.go │ │ ├── iimport.go │ │ ├── newInterface10.go │ │ ├── newInterface11.go │ │ ├── support_go117.go │ │ ├── support_go118.go │ │ ├── unified_no.go │ │ ├── unified_yes.go │ │ ├── ureader_no.go │ │ └── ureader_yes.go │ │ ├── gocommand │ │ ├── invoke.go │ │ ├── vendor.go │ │ └── version.go │ │ ├── packagesinternal │ │ └── packages.go │ │ ├── pkgbits │ │ ├── codes.go │ │ ├── decoder.go │ │ ├── doc.go │ │ ├── encoder.go │ │ ├── flags.go │ │ ├── frames_go1.go │ │ ├── frames_go17.go │ │ ├── reloc.go │ │ ├── support.go │ │ ├── sync.go │ │ └── syncmarker_string.go │ │ ├── robustio │ │ ├── gopls_windows.go │ │ ├── robustio.go │ │ ├── robustio_darwin.go │ │ ├── robustio_flaky.go │ │ ├── robustio_other.go │ │ ├── robustio_plan9.go │ │ ├── robustio_posix.go │ │ └── robustio_windows.go │ │ ├── tokeninternal │ │ └── tokeninternal.go │ │ ├── typeparams │ │ ├── common.go │ │ ├── coretype.go │ │ ├── enabled_go117.go │ │ ├── enabled_go118.go │ │ ├── normalize.go │ │ ├── termlist.go │ │ ├── typeparams_go117.go │ │ ├── typeparams_go118.go │ │ └── typeterm.go │ │ └── typesinternal │ │ ├── errorcode.go │ │ ├── errorcode_string.go │ │ ├── types.go │ │ └── types_118.go │ └── vuln │ ├── LICENSE │ ├── PATENTS │ ├── cmd │ └── govulncheck │ │ ├── doc.go │ │ └── main.go │ └── internal │ ├── client │ ├── client.go │ ├── legacy.go │ ├── schema.go │ └── source.go │ ├── derrors │ └── derrors.go │ ├── goenv.go │ ├── goenv_testmode.go │ ├── govulncheck │ ├── handler.go │ ├── json.go │ └── result.go │ ├── internal.go │ ├── osv │ └── osv.go │ ├── scan │ ├── binary.go │ ├── binary_118.go │ ├── binary_not118.go │ ├── errors.go │ ├── filepath.go │ ├── flag.go │ ├── flag_testmode.go │ ├── flags.go │ ├── result.go │ ├── run.go │ ├── scan.go │ ├── source.go │ ├── stdlib.go │ ├── template.go │ ├── template │ │ ├── config.tmpl │ │ └── output.tmpl │ ├── text.go │ └── util.go │ ├── semver │ └── semver.go │ ├── vulncheck │ ├── binary.go │ ├── doc.go │ ├── entries.go │ ├── fetch.go │ ├── internal │ │ ├── buildinfo │ │ │ ├── README.md │ │ │ ├── additions_buildinfo.go │ │ │ ├── additions_scan.go │ │ │ └── buildinfo.go │ │ └── gosym │ │ │ ├── README.md │ │ │ ├── additions.go │ │ │ ├── pclntab.go │ │ │ └── symtab.go │ ├── semver.go │ ├── slicing.go │ ├── source.go │ ├── utils.go │ ├── vulncheck.go │ └── witness.go │ └── web │ └── url.go ├── honnef.co └── go │ └── tools │ ├── LICENSE │ ├── LICENSE-THIRD-PARTY │ ├── analysis │ ├── code │ │ ├── code.go │ │ └── visit.go │ ├── edit │ │ └── edit.go │ ├── facts │ │ ├── deprecated │ │ │ └── deprecated.go │ │ ├── directives │ │ │ └── directives.go │ │ ├── generated │ │ │ └── generated.go │ │ ├── nilness │ │ │ └── nilness.go │ │ ├── purity │ │ │ └── purity.go │ │ ├── tokenfile │ │ │ └── token.go │ │ └── typedness │ │ │ └── typedness.go │ ├── lint │ │ └── lint.go │ └── report │ │ └── report.go │ ├── cmd │ └── staticcheck │ │ ├── README.md │ │ └── staticcheck.go │ ├── config │ ├── config.go │ └── example.conf │ ├── go │ ├── ast │ │ └── astutil │ │ │ ├── upstream.go │ │ │ └── util.go │ ├── buildid │ │ ├── UPSTREAM │ │ ├── buildid.go │ │ └── note.go │ ├── ir │ │ ├── LICENSE │ │ ├── UPSTREAM │ │ ├── blockopt.go │ │ ├── builder.go │ │ ├── const.go │ │ ├── create.go │ │ ├── doc.go │ │ ├── dom.go │ │ ├── emit.go │ │ ├── exits.go │ │ ├── func.go │ │ ├── html.go │ │ ├── irutil │ │ │ ├── load.go │ │ │ ├── loops.go │ │ │ ├── stub.go │ │ │ ├── switch.go │ │ │ ├── terminates.go │ │ │ ├── util.go │ │ │ └── visit.go │ │ ├── lift.go │ │ ├── lvalue.go │ │ ├── methods.go │ │ ├── mode.go │ │ ├── print.go │ │ ├── sanity.go │ │ ├── source.go │ │ ├── ssa.go │ │ ├── util.go │ │ ├── wrappers.go │ │ └── write.go │ ├── loader │ │ ├── hash.go │ │ └── loader.go │ └── types │ │ └── typeutil │ │ ├── ext.go │ │ ├── typeparams.go │ │ ├── upstream.go │ │ └── util.go │ ├── internal │ ├── passes │ │ └── buildir │ │ │ └── buildir.go │ ├── renameio │ │ ├── UPSTREAM │ │ └── renameio.go │ ├── robustio │ │ ├── UPSTREAM │ │ ├── robustio.go │ │ ├── robustio_darwin.go │ │ ├── robustio_flaky.go │ │ ├── robustio_other.go │ │ └── robustio_windows.go │ ├── sharedcheck │ │ └── lint.go │ └── sync │ │ └── sync.go │ ├── knowledge │ ├── arg.go │ ├── deprecated.go │ ├── doc.go │ └── signatures.go │ ├── lintcmd │ ├── cache │ │ ├── UPSTREAM │ │ ├── cache.go │ │ ├── default.go │ │ └── hash.go │ ├── cmd.go │ ├── config.go │ ├── directives.go │ ├── format.go │ ├── lint.go │ ├── runner │ │ ├── runner.go │ │ └── stats.go │ ├── sarif.go │ ├── stats.go │ ├── stats_bsd.go │ ├── stats_posix.go │ └── version │ │ ├── buildinfo.go │ │ └── version.go │ ├── pattern │ ├── convert.go │ ├── doc.go │ ├── lexer.go │ ├── match.go │ ├── parser.go │ └── pattern.go │ ├── printf │ ├── fuzz.go │ └── printf.go │ ├── quickfix │ ├── analysis.go │ ├── doc.go │ └── lint.go │ ├── sarif │ └── sarif.go │ ├── simple │ ├── analysis.go │ ├── doc.go │ └── lint.go │ ├── staticcheck │ ├── analysis.go │ ├── buildtag.go │ ├── doc.go │ ├── fakejson │ │ └── encode.go │ ├── fakereflect │ │ └── fakereflect.go │ ├── fakexml │ │ ├── marshal.go │ │ ├── typeinfo.go │ │ └── xml.go │ ├── lint.go │ ├── rules.go │ └── structtag.go │ ├── stylecheck │ ├── analysis.go │ ├── doc.go │ ├── lint.go │ └── names.go │ └── unused │ ├── implements.go │ ├── runtime.go │ ├── serialize.go │ └── unused.go └── modules.txt /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: 3 | push: 4 | pull_request: 5 | schedule: 6 | - cron: 0 3 * * 6 # Every Saturday at 3:00 AM 7 | jobs: 8 | test: 9 | strategy: 10 | matrix: 11 | go-version: [oldstable, stable, tip] 12 | platform: [ubuntu-latest] 13 | fail-fast: false 14 | runs-on: ${{ matrix.platform }} 15 | steps: 16 | - name: Install Go 17 | if: matrix.go-version != 'tip' 18 | uses: actions/setup-go@v3 19 | with: 20 | go-version: ${{ matrix.go-version }} 21 | - name: Install Go tip 22 | if: matrix.go-version == 'tip' 23 | run: | 24 | git clone --depth=1 https://go.googlesource.com/go $HOME/gotip 25 | cd $HOME/gotip/src 26 | ./make.bash 27 | echo "GOROOT=$HOME/gotip" >> $GITHUB_ENV 28 | echo "$HOME/gotip/bin" >> $GITHUB_PATH 29 | echo "`$HOME/gotip/bin/go env GOPATH`/bin" >> $GITHUB_PATH 30 | - name: Checkout code 31 | uses: actions/checkout@v3 32 | - name: Check go fmt compliance 33 | run: make fmt-check 34 | - name: Run go vet 35 | run: make vet 36 | - name: Run nilness 37 | run: make nilness 38 | - name: Run staticcheck 39 | run: make staticcheck 40 | - name: Run tests 41 | run: make test 42 | - name: Run govulncheck 43 | run: make govulncheck 44 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: CodeQL 2 | on: 3 | push: 4 | pull_request: 5 | schedule: 6 | - cron: 0 3 * * 6 # Every Saturday at 3:00 AM 7 | jobs: 8 | analyze: 9 | name: Analyze 10 | runs-on: ubuntu-latest 11 | strategy: 12 | fail-fast: false 13 | matrix: 14 | language: [go] 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v3 18 | - name: Initialize CodeQL 19 | uses: github/codeql-action/init@v2 20 | with: 21 | languages: ${{ matrix.language }} 22 | - name: Autobuild 23 | uses: github/codeql-action/autobuild@v2 24 | - name: Perform CodeQL Analysis 25 | uses: github/codeql-action/analyze@v2 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.dll 4 | *.so 5 | *.dylib 6 | 7 | # Test binary, build with `go test -c` 8 | *.test 9 | 10 | # Output of the go coverage tool, specifically when used with LiteIDE 11 | *.out 12 | 13 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 14 | .glide/ 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG 2 | 3 | ## 0.3.1 4 | 5 | * Fix bug when invoking `GetAll()` with non-readable sysctls 6 | * Upgrade all vendored dependencies 7 | * Run nilness check in CI 8 | 9 | ## 0.3.0 10 | 11 | * Correctly evaluate which sysctl files are readable when running `GetPattern()` 12 | * Upgrade all vendored dependencies 13 | * Fix builds for Go 1.18 14 | * Code linting 15 | * Test improvements 16 | 17 | ## 0.2.0 18 | 19 | * Add `Client` type 20 | * Upgrade all dependencies 21 | * Improve test coverage 22 | 23 | ## 0.1.1 24 | 25 | * Fix configuration file parsing bug 26 | * Go modules support 27 | 28 | ## 0.1.0 29 | 30 | * Support for getting and setting sysctls 31 | * Support for loading sysctl from configuration files 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Lorenzo Saino 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL = /bin/bash -euo pipefail 2 | 3 | # Go binary to use in non-container targets 4 | GO ?= go 5 | 6 | # Variables for container targets 7 | GO_VERSION ?= latest 8 | CONTAINER ?= golang:$(GO_VERSION) 9 | PKG = github.com/lorenzosaino/go-sysctl 10 | DOCKER_RUN_FLAGS = --rm -it -v $$(pwd):/go/src/$(PKG) -w /go/src/$(PKG) 11 | 12 | export GO111MODULE=on 13 | 14 | all: fmt-check vet nilness staticcheck test ## Run all checks and tests 15 | 16 | .PHONY: mod-upgrade 17 | mod-upgrade: ## Upgrade all vendored dependencies 18 | $(GO) get -d -u -t ./... 19 | $(GO) mod tidy 20 | $(GO) mod vendor 21 | 22 | .PHONY: mod-update 23 | mod-update: ## Ensure all used dependencies are tracked in go.{mod|sum} and vendored 24 | $(GO) mod tidy 25 | $(GO) mod vendor 26 | 27 | .PHONY: fmt-check 28 | fmt-check: ## Validate that all source files pass "go fmt" 29 | exit $(shell $(GO) fmt ./... | wc -l) 30 | 31 | .PHONY: vet 32 | vet: ## Run go vet 33 | $(GO) vet ./... 34 | 35 | .PHONY: staticcheck 36 | staticcheck: ## Run staticcheck 37 | $(GO) install ./vendor/honnef.co/go/tools/cmd/staticcheck 2>/dev/null || @[ -x "$(shell which staticcheck)" ] || $(GO) install honnef.co/go/tools/cmd/staticcheck@latest 38 | staticcheck ./... 39 | 40 | .PHONY: nilness 41 | nilness: ## Run nilness 42 | $(GO) install ./vendor/golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness 2>/dev/null || [ -x "$(shell which nilness)" ] || $(GO) install golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness@latest 43 | nilness ./... 44 | 45 | .PHONY: govulncheck 46 | govulncheck: ## Run govulncheck 47 | $(GO) install ./vendor/golang.org/x/vuln/cmd/govulncheck 2>/dev/null || [ -x "$(shell which govulncheck)" ] || $(GO) install golang.org/x/vuln/cmd/govulncheck@latest 48 | govulncheck ./... 49 | 50 | .PHONY: test 51 | test: ## Run all tests 52 | $(GO) test -race ./... 53 | 54 | .PHONY: container-shell 55 | container-shell: ## Open a shell on a Docker container 56 | docker run $(DOCKER_RUN_FLAGS) $(CONTAINER) /bin/bash 57 | 58 | .PHONY: container-% 59 | container-%: ## Run any target of this Makefile in a Docker container 60 | docker run $(DOCKER_RUN_FLAGS) $(CONTAINER) make $* 61 | 62 | .PHONY: help 63 | help: ## Print help 64 | @(grep -E '^[a-zA-Z0-9_%-]+:.*?## .*$$' Makefile || true )| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Sysctl 2 | 3 | [![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/lorenzosaino/go-sysctl) 4 | [![Build](https://github.com/lorenzosaino/go-sysctl/workflows/Build/badge.svg)](https://github.com/lorenzosaino/go-sysctl/actions) 5 | [![Go Report Card](https://goreportcard.com/badge/github.com/lorenzosaino/go-sysctl)](https://goreportcard.com/report/github.com/lorenzosaino/go-sysctl) 6 | [![License](https://img.shields.io/github/license/lorenzosaino/go-sysctl.svg)](https://github.com/lorenzosaino/go-sysctl/blob/master/LICENSE) 7 | 8 | Go wrapper around the sysctl interface. 9 | 10 | ## Documentation 11 | 12 | See [Go doc](https://pkg.go.dev/github.com/lorenzosaino/go-sysctl?tab=doc). 13 | 14 | ## Usage 15 | 16 | ```go 17 | import sysctl "github.com/lorenzosaino/go-sysctl" 18 | 19 | var ( 20 | val string 21 | vals map[string]string 22 | err error 23 | ) 24 | 25 | // Get value of a single sysctl 26 | // This is equivalent to running "sysctl " 27 | val, err = sysctl.Get("net.ipv4.ip_forward") 28 | 29 | // Get the values of all sysctls matching a given pattern 30 | // This is equivalent to running "sysctl -a -r " 31 | vals, err = sysctl.GetPattern("net.ipv4.ipfrag") 32 | 33 | // Get the values of all sysctls 34 | // This is equivalent to running "sysctl -a" 35 | vals, err = sysctl.GetAll() 36 | 37 | // Set the value of a sysctl 38 | // This is equivalent to running "sysctl -w =" 39 | err = sysctl.Set("net.ipv4.ip_forward", "1") 40 | 41 | // Set sysctl values from configuration file 42 | // This is equivalent to running "sysctl -p " 43 | err = sysctl.LoadConfigAndApply("/etc/sysctl.conf") 44 | ``` 45 | 46 | ## License 47 | 48 | [BSD 3-clause](LICENSE) 49 | -------------------------------------------------------------------------------- /config.go: -------------------------------------------------------------------------------- 1 | package sysctl 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | const sysctlConfPath = "/etc/sysctl.conf" 11 | 12 | // parseConfig reads a sysctl configuration file and parses its content 13 | func parseConfig(path string, out map[string]string) error { 14 | file, err := os.Open(path) 15 | if err != nil { 16 | return fmt.Errorf("could not open file: %v", err) 17 | } 18 | defer file.Close() 19 | 20 | scanner := bufio.NewScanner(file) 21 | for scanner.Scan() { 22 | line := scanner.Text() 23 | parsed := strings.Split(line, "#")[0] 24 | parsed = strings.Split(parsed, ";")[0] 25 | parsed = strings.TrimSpace(parsed) 26 | if parsed == "" { 27 | continue 28 | } 29 | tokens := strings.Split(parsed, "=") 30 | if len(tokens) != 2 { 31 | return fmt.Errorf("could not parse line %s", line) 32 | } 33 | k := strings.TrimSpace(tokens[0]) 34 | v := strings.TrimSpace(tokens[1]) 35 | out[k] = v 36 | } 37 | 38 | if err := scanner.Err(); err != nil { 39 | return fmt.Errorf("error reading file: %v", err) 40 | } 41 | 42 | return nil 43 | } 44 | 45 | // LoadConfig gets sysctl values from a list of sysctl configuration files. 46 | // The values in the rightmost files take priority. 47 | // If no file is specified, values are read from /etc/sysctl.conf. 48 | func LoadConfig(files ...string) (map[string]string, error) { 49 | if len(files) == 0 { 50 | files = []string{sysctlConfPath} 51 | } 52 | out := make(map[string]string) 53 | for _, f := range files { 54 | if err := parseConfig(f, out); err != nil { 55 | return nil, fmt.Errorf("could not parse file %s: %v", f, err) 56 | } 57 | } 58 | return out, nil 59 | } 60 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/lorenzosaino/go-sysctl 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/BurntSushi/toml v1.2.1 // indirect 7 | github.com/google/go-cmp v0.5.9 8 | golang.org/x/mod v0.10.0 // indirect 9 | golang.org/x/sys v0.7.0 // indirect 10 | golang.org/x/tools v0.8.0 11 | honnef.co/go/tools v0.4.3 12 | ) 13 | 14 | require golang.org/x/vuln v0.0.0-20230407211851-ee3d87385065 15 | 16 | require ( 17 | golang.org/x/exp/typeparams v0.0.0-20230321023759-10a507213a29 // indirect 18 | golang.org/x/sync v0.1.0 // indirect 19 | ) 20 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= 2 | github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= 3 | github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= 4 | github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786 h1:rcv+Ippz6RAtvaGgKxc+8FQIpxHgsF+HBzPyYL2cyVU= 5 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 6 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 7 | github.com/google/renameio v0.1.0 h1:GOZbcHa3HfsPKPlmyPyN2KEohoMXOhdMbHrvbpl2QaA= 8 | golang.org/x/exp/typeparams v0.0.0-20230321023759-10a507213a29 h1:e7LhZmJ631l59keHP9ssC3sgSn3/oiEHKHKXDkimURY= 9 | golang.org/x/exp/typeparams v0.0.0-20230321023759-10a507213a29/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= 10 | golang.org/x/mod v0.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= 11 | golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 12 | golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= 13 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 14 | golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= 15 | golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 16 | golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y= 17 | golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4= 18 | golang.org/x/vuln v0.0.0-20230407211851-ee3d87385065 h1:JYdzMHSC+iRDBBweXNPlciS5UMfiTAmF4mQJoIfY4I8= 19 | golang.org/x/vuln v0.0.0-20230407211851-ee3d87385065/go.mod h1:64LpnL2PuSMzFYeCmJjYiRbroOUG9aCZYznINnF5PHE= 20 | honnef.co/go/tools v0.4.3 h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw= 21 | honnef.co/go/tools v0.4.3/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA= 22 | mvdan.cc/unparam v0.0.0-20230312165513-e84e2d14e3b8 h1:VuJo4Mt0EVPychre4fNlDWDuE5AjXtPJpRUWqZDQhaI= 23 | -------------------------------------------------------------------------------- /sysctl.go: -------------------------------------------------------------------------------- 1 | // Package sysctl provides functions wrapping the sysctl interface. 2 | package sysctl 3 | 4 | // DefaultPath is the default path to the sysctl virtual files. 5 | const DefaultPath = "/proc/sys/" 6 | 7 | var std *Client 8 | 9 | func init() { 10 | std = &Client{path: DefaultPath} 11 | } 12 | 13 | // Get returns a sysctl from a given key. 14 | func Get(key string) (string, error) { 15 | return std.Get(key) 16 | } 17 | 18 | // GetPattern returns a map of sysctls matching a given pattern 19 | // The pattern uses a POSIX extended regular expression syntax. 20 | // This function matches the same sysctls that the command 21 | // sysctl -a -r would return. 22 | func GetPattern(pattern string) (map[string]string, error) { 23 | return std.GetPattern(pattern) 24 | } 25 | 26 | // GetAll returns all sysctls. This is equivalent 27 | // to running the command sysctl -a. 28 | func GetAll() (map[string]string, error) { 29 | return std.GetAll() 30 | } 31 | 32 | // Set updates the value of a sysctl. 33 | func Set(key, value string) error { 34 | return std.Set(key, value) 35 | } 36 | 37 | // LoadConfigAndApply sets sysctl values from a list of sysctl configuration files. 38 | // The values in the rightmost files take priority. 39 | // If no file is specified, values are read from /etc/sysctl.conf. 40 | func LoadConfigAndApply(files ...string) error { 41 | return std.LoadConfigAndApply(files...) 42 | } 43 | -------------------------------------------------------------------------------- /sysctl_linux_test.go: -------------------------------------------------------------------------------- 1 | //go:build linux 2 | // +build linux 3 | 4 | package sysctl 5 | 6 | import ( 7 | "os/user" 8 | "testing" 9 | ) 10 | 11 | func TestGet(t *testing.T) { 12 | cases := []struct { 13 | name string 14 | skip bool 15 | }{ 16 | { 17 | name: "fs.protected_fifos", 18 | skip: !isUserRoot(), 19 | }, 20 | { 21 | name: "net.ipv4.ip_forward", 22 | }, 23 | } 24 | for _, c := range cases { 25 | t.Run(c.name, func(t *testing.T) { 26 | if c.skip { 27 | t.Skip("skipping test") 28 | } 29 | 30 | got, err := Get(c.name) 31 | if err != nil { 32 | t.Fatalf("Could not get sysctl value: %s", err.Error()) 33 | } 34 | if got != "0" && got != "1" { 35 | t.Fatalf("expected 0 or 1, got %s", got) 36 | } 37 | }) 38 | } 39 | } 40 | 41 | func TestGetPattern(t *testing.T) { 42 | cases := []struct { 43 | pattern string 44 | matches []string 45 | skip bool 46 | }{ 47 | { 48 | pattern: "^fs.protected_", 49 | matches: []string{ 50 | "fs.protected_fifos", 51 | "fs.protected_hardlinks", 52 | "fs.protected_regular", 53 | "fs.protected_symlinks", 54 | }, 55 | skip: !isUserRoot(), 56 | }, 57 | { 58 | pattern: "^net.ipv4.ipfrag", 59 | matches: []string{ 60 | "net.ipv4.ipfrag_high_thresh", 61 | "net.ipv4.ipfrag_low_thresh", 62 | "net.ipv4.ipfrag_max_dist", 63 | "net.ipv4.ipfrag_time", 64 | }, 65 | }, 66 | } 67 | for _, c := range cases { 68 | t.Run(c.pattern, func(t *testing.T) { 69 | if c.skip { 70 | t.Skip("skipping test") 71 | } 72 | 73 | got, err := GetPattern(c.pattern) 74 | if err != nil { 75 | t.Fatalf("could not get sysctl values for pattern %s: %v", c.pattern, err) 76 | } 77 | if len(got) < len(c.matches) { 78 | // We check if length is < than expected to prevent 79 | // breaking test cases if new sysctls are added 80 | t.Fatalf("expected at least %d matches, got %d. Matches: %+v", 81 | len(c.matches), len(got), got) 82 | } 83 | for _, k := range c.matches { 84 | if _, ok := got[k]; !ok { 85 | t.Fatalf("key %s not matched. Matches: %+v", k, got) 86 | } 87 | } 88 | }) 89 | } 90 | } 91 | 92 | func TestGetAll(t *testing.T) { 93 | if !isUserRoot() { 94 | t.Skip("user not root, skipping test") 95 | } 96 | 97 | got, err := GetAll() 98 | if err != nil { 99 | t.Fatalf("Could not get sysctl values: %s", err.Error()) 100 | } 101 | if len(got) == 0 { 102 | t.Fatal("no error returned but returned empty slice of sysctl values") 103 | } 104 | } 105 | 106 | func isUserRoot() bool { 107 | u, err := user.Current() 108 | if err != nil { 109 | return false 110 | } 111 | return u.Username == "root" 112 | } 113 | -------------------------------------------------------------------------------- /testdata/client/config-empty.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lorenzosaino/go-sysctl/f1dde0a7a4859d95ae07ecd6dbe40561e6929c12/testdata/client/config-empty.conf -------------------------------------------------------------------------------- /testdata/client/config-missing-keys.conf: -------------------------------------------------------------------------------- 1 | a = value of a 2 | b.a = value of b.a 3 | b.b.a = value of b.b.a 4 | key.missing = value of missing key 5 | -------------------------------------------------------------------------------- /testdata/client/config-ok.conf: -------------------------------------------------------------------------------- 1 | a = value of a 2 | b.a = value of b.a 3 | b.b.a = value of b.b.a 4 | -------------------------------------------------------------------------------- /testdata/client/nok/f: -------------------------------------------------------------------------------- 1 | value of f -------------------------------------------------------------------------------- /testdata/client/ok/d/d/f1: -------------------------------------------------------------------------------- 1 | value of d.d.f1 -------------------------------------------------------------------------------- /testdata/client/ok/d/d/f2: -------------------------------------------------------------------------------- 1 | value of d.d.f2 -------------------------------------------------------------------------------- /testdata/client/ok/d/f: -------------------------------------------------------------------------------- 1 | value of d.f -------------------------------------------------------------------------------- /testdata/client/ok/f: -------------------------------------------------------------------------------- 1 | value of f -------------------------------------------------------------------------------- /testdata/config/sysctl-a.conf: -------------------------------------------------------------------------------- 1 | kernel.domainname = a.com 2 | -------------------------------------------------------------------------------- /testdata/config/sysctl-b.conf: -------------------------------------------------------------------------------- 1 | kernel.domainname = b.com 2 | -------------------------------------------------------------------------------- /testdata/config/sysctl-correct.conf: -------------------------------------------------------------------------------- 1 | # sysctl.conf sample 2 | # 3 | kernel.domainname = example.com 4 | ; this one has a space which will be written to the sysctl! 5 | kernel.modprobe = /sbin/mod probe 6 | 7 | # No spaces around token and value, should be parsed correctly 8 | kernel.hostname=example.com 9 | -------------------------------------------------------------------------------- /testdata/config/sysctl-empty.conf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lorenzosaino/go-sysctl/f1dde0a7a4859d95ae07ecd6dbe40561e6929c12/testdata/config/sysctl-empty.conf -------------------------------------------------------------------------------- /testdata/config/sysctl-error.conf: -------------------------------------------------------------------------------- 1 | kernel.domainname.example.com 2 | -------------------------------------------------------------------------------- /testdata/config/sysctl-only-comments.conf: -------------------------------------------------------------------------------- 1 | ; this is a comment 2 | 3 | # this is a comment 4 | 5 | # 6 | # 7 | # 8 | 9 | ; 10 | ; 11 | ; 12 | -------------------------------------------------------------------------------- /tools.go: -------------------------------------------------------------------------------- 1 | //go:build tools 2 | // +build tools 3 | 4 | package sysctl 5 | 6 | import ( 7 | _ "golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness" 8 | _ "golang.org/x/vuln/cmd/govulncheck" 9 | _ "honnef.co/go/tools/cmd/staticcheck" 10 | ) 11 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/.gitignore: -------------------------------------------------------------------------------- 1 | /toml.test 2 | /toml-test 3 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/COPYING: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 TOML authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/decode_go116.go: -------------------------------------------------------------------------------- 1 | //go:build go1.16 2 | // +build go1.16 3 | 4 | package toml 5 | 6 | import ( 7 | "io/fs" 8 | ) 9 | 10 | // DecodeFS reads the contents of a file from [fs.FS] and decodes it with 11 | // [Decode]. 12 | func DecodeFS(fsys fs.FS, path string, v interface{}) (MetaData, error) { 13 | fp, err := fsys.Open(path) 14 | if err != nil { 15 | return MetaData{}, err 16 | } 17 | defer fp.Close() 18 | return NewDecoder(fp).Decode(v) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/deprecated.go: -------------------------------------------------------------------------------- 1 | package toml 2 | 3 | import ( 4 | "encoding" 5 | "io" 6 | ) 7 | 8 | // Deprecated: use encoding.TextMarshaler 9 | type TextMarshaler encoding.TextMarshaler 10 | 11 | // Deprecated: use encoding.TextUnmarshaler 12 | type TextUnmarshaler encoding.TextUnmarshaler 13 | 14 | // Deprecated: use MetaData.PrimitiveDecode. 15 | func PrimitiveDecode(primValue Primitive, v interface{}) error { 16 | md := MetaData{decoded: make(map[string]struct{})} 17 | return md.unify(primValue.undecoded, rvalue(v)) 18 | } 19 | 20 | // Deprecated: use NewDecoder(reader).Decode(&value). 21 | func DecodeReader(r io.Reader, v interface{}) (MetaData, error) { return NewDecoder(r).Decode(v) } 22 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/doc.go: -------------------------------------------------------------------------------- 1 | // Package toml implements decoding and encoding of TOML files. 2 | // 3 | // This package supports TOML v1.0.0, as specified at https://toml.io 4 | // 5 | // There is also support for delaying decoding with the Primitive type, and 6 | // querying the set of keys in a TOML document with the MetaData type. 7 | // 8 | // The github.com/BurntSushi/toml/cmd/tomlv package implements a TOML validator, 9 | // and can be used to verify if TOML document is valid. It can also be used to 10 | // print the type of each key. 11 | package toml 12 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/internal/tz.go: -------------------------------------------------------------------------------- 1 | package internal 2 | 3 | import "time" 4 | 5 | // Timezones used for local datetime, date, and time TOML types. 6 | // 7 | // The exact way times and dates without a timezone should be interpreted is not 8 | // well-defined in the TOML specification and left to the implementation. These 9 | // defaults to current local timezone offset of the computer, but this can be 10 | // changed by changing these variables before decoding. 11 | // 12 | // TODO: 13 | // Ideally we'd like to offer people the ability to configure the used timezone 14 | // by setting Decoder.Timezone and Encoder.Timezone; however, this is a bit 15 | // tricky: the reason we use three different variables for this is to support 16 | // round-tripping – without these specific TZ names we wouldn't know which 17 | // format to use. 18 | // 19 | // There isn't a good way to encode this right now though, and passing this sort 20 | // of information also ties in to various related issues such as string format 21 | // encoding, encoding of comments, etc. 22 | // 23 | // So, for the time being, just put this in internal until we can write a good 24 | // comprehensive API for doing all of this. 25 | // 26 | // The reason they're exported is because they're referred from in e.g. 27 | // internal/tag. 28 | // 29 | // Note that this behaviour is valid according to the TOML spec as the exact 30 | // behaviour is left up to implementations. 31 | var ( 32 | localOffset = func() int { _, o := time.Now().Zone(); return o }() 33 | LocalDatetime = time.FixedZone("datetime-local", localOffset) 34 | LocalDate = time.FixedZone("date-local", localOffset) 35 | LocalTime = time.FixedZone("time-local", localOffset) 36 | ) 37 | -------------------------------------------------------------------------------- /vendor/github.com/BurntSushi/toml/type_toml.go: -------------------------------------------------------------------------------- 1 | package toml 2 | 3 | // tomlType represents any Go type that corresponds to a TOML type. 4 | // While the first draft of the TOML spec has a simplistic type system that 5 | // probably doesn't need this level of sophistication, we seem to be militating 6 | // toward adding real composite types. 7 | type tomlType interface { 8 | typeString() string 9 | } 10 | 11 | // typeEqual accepts any two types and returns true if they are equal. 12 | func typeEqual(t1, t2 tomlType) bool { 13 | if t1 == nil || t2 == nil { 14 | return false 15 | } 16 | return t1.typeString() == t2.typeString() 17 | } 18 | 19 | func typeIsTable(t tomlType) bool { 20 | return typeEqual(t, tomlHash) || typeEqual(t, tomlArrayHash) 21 | } 22 | 23 | type tomlBaseType string 24 | 25 | func (btype tomlBaseType) typeString() string { 26 | return string(btype) 27 | } 28 | 29 | func (btype tomlBaseType) String() string { 30 | return btype.typeString() 31 | } 32 | 33 | var ( 34 | tomlInteger tomlBaseType = "Integer" 35 | tomlFloat tomlBaseType = "Float" 36 | tomlDatetime tomlBaseType = "Datetime" 37 | tomlString tomlBaseType = "String" 38 | tomlBool tomlBaseType = "Bool" 39 | tomlArray tomlBaseType = "Array" 40 | tomlHash tomlBaseType = "Hash" 41 | tomlArrayHash tomlBaseType = "ArrayHash" 42 | ) 43 | 44 | // typeOfPrimitive returns a tomlType of any primitive value in TOML. 45 | // Primitive values are: Integer, Float, Datetime, String and Bool. 46 | // 47 | // Passing a lexer item other than the following will cause a BUG message 48 | // to occur: itemString, itemBool, itemInteger, itemFloat, itemDatetime. 49 | func (p *parser) typeOfPrimitive(lexItem item) tomlType { 50 | switch lexItem.typ { 51 | case itemInteger: 52 | return tomlInteger 53 | case itemFloat: 54 | return tomlFloat 55 | case itemDatetime: 56 | return tomlDatetime 57 | case itemString: 58 | return tomlString 59 | case itemMultilineString: 60 | return tomlString 61 | case itemRawString: 62 | return tomlString 63 | case itemRawMultilineString: 64 | return tomlString 65 | case itemBool: 66 | return tomlBool 67 | } 68 | p.bug("Cannot infer primitive type of lex item '%s'.", lexItem) 69 | panic("unreachable") 70 | } 71 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/export_panic.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build purego 6 | // +build purego 7 | 8 | package cmp 9 | 10 | import "reflect" 11 | 12 | const supportExporters = false 13 | 14 | func retrieveUnexportedField(reflect.Value, reflect.StructField, bool) reflect.Value { 15 | panic("no support for forcibly accessing unexported fields") 16 | } 17 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/export_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !purego 6 | // +build !purego 7 | 8 | package cmp 9 | 10 | import ( 11 | "reflect" 12 | "unsafe" 13 | ) 14 | 15 | const supportExporters = true 16 | 17 | // retrieveUnexportedField uses unsafe to forcibly retrieve any field from 18 | // a struct such that the value has read-write permissions. 19 | // 20 | // The parent struct, v, must be addressable, while f must be a StructField 21 | // describing the field to retrieve. If addr is false, 22 | // then the returned value will be shallowed copied to be non-addressable. 23 | func retrieveUnexportedField(v reflect.Value, f reflect.StructField, addr bool) reflect.Value { 24 | ve := reflect.NewAt(f.Type, unsafe.Pointer(uintptr(unsafe.Pointer(v.UnsafeAddr()))+f.Offset)).Elem() 25 | if !addr { 26 | // A field is addressable if and only if the struct is addressable. 27 | // If the original parent value was not addressable, shallow copy the 28 | // value to make it non-addressable to avoid leaking an implementation 29 | // detail of how forcibly exporting a field works. 30 | if ve.Kind() == reflect.Interface && ve.IsNil() { 31 | return reflect.Zero(f.Type) 32 | } 33 | return reflect.ValueOf(ve.Interface()).Convert(f.Type) 34 | } 35 | return ve 36 | } 37 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/internal/diff/debug_disable.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !cmp_debug 6 | // +build !cmp_debug 7 | 8 | package diff 9 | 10 | var debug debugger 11 | 12 | type debugger struct{} 13 | 14 | func (debugger) Begin(_, _ int, f EqualFunc, _, _ *EditScript) EqualFunc { 15 | return f 16 | } 17 | func (debugger) Update() {} 18 | func (debugger) Finish() {} 19 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/internal/flags/flags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package flags 6 | 7 | // Deterministic controls whether the output of Diff should be deterministic. 8 | // This is only used for testing. 9 | var Deterministic bool 10 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/internal/value/pointer_purego.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build purego 6 | // +build purego 7 | 8 | package value 9 | 10 | import "reflect" 11 | 12 | // Pointer is an opaque typed pointer and is guaranteed to be comparable. 13 | type Pointer struct { 14 | p uintptr 15 | t reflect.Type 16 | } 17 | 18 | // PointerOf returns a Pointer from v, which must be a 19 | // reflect.Ptr, reflect.Slice, or reflect.Map. 20 | func PointerOf(v reflect.Value) Pointer { 21 | // NOTE: Storing a pointer as an uintptr is technically incorrect as it 22 | // assumes that the GC implementation does not use a moving collector. 23 | return Pointer{v.Pointer(), v.Type()} 24 | } 25 | 26 | // IsNil reports whether the pointer is nil. 27 | func (p Pointer) IsNil() bool { 28 | return p.p == 0 29 | } 30 | 31 | // Uintptr returns the pointer as a uintptr. 32 | func (p Pointer) Uintptr() uintptr { 33 | return p.p 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/internal/value/pointer_unsafe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !purego 6 | // +build !purego 7 | 8 | package value 9 | 10 | import ( 11 | "reflect" 12 | "unsafe" 13 | ) 14 | 15 | // Pointer is an opaque typed pointer and is guaranteed to be comparable. 16 | type Pointer struct { 17 | p unsafe.Pointer 18 | t reflect.Type 19 | } 20 | 21 | // PointerOf returns a Pointer from v, which must be a 22 | // reflect.Ptr, reflect.Slice, or reflect.Map. 23 | func PointerOf(v reflect.Value) Pointer { 24 | // The proper representation of a pointer is unsafe.Pointer, 25 | // which is necessary if the GC ever uses a moving collector. 26 | return Pointer{unsafe.Pointer(v.Pointer()), v.Type()} 27 | } 28 | 29 | // IsNil reports whether the pointer is nil. 30 | func (p Pointer) IsNil() bool { 31 | return p.p == nil 32 | } 33 | 34 | // Uintptr returns the pointer as a uintptr. 35 | func (p Pointer) Uintptr() uintptr { 36 | return uintptr(p.p) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/google/go-cmp/cmp/report.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017, The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cmp 6 | 7 | // defaultReporter implements the reporter interface. 8 | // 9 | // As Equal serially calls the PushStep, Report, and PopStep methods, the 10 | // defaultReporter constructs a tree-based representation of the compared value 11 | // and the result of each comparison (see valueNode). 12 | // 13 | // When the String method is called, the FormatDiff method transforms the 14 | // valueNode tree into a textNode tree, which is a tree-based representation 15 | // of the textual output (see textNode). 16 | // 17 | // Lastly, the textNode.String method produces the final report as a string. 18 | type defaultReporter struct { 19 | root *valueNode 20 | curr *valueNode 21 | } 22 | 23 | func (r *defaultReporter) PushStep(ps PathStep) { 24 | r.curr = r.curr.PushStep(ps) 25 | if r.root == nil { 26 | r.root = r.curr 27 | } 28 | } 29 | func (r *defaultReporter) Report(rs Result) { 30 | r.curr.Report(rs) 31 | } 32 | func (r *defaultReporter) PopStep() { 33 | r.curr = r.curr.PopStep() 34 | } 35 | 36 | // String provides a full report of the differences detected as a structured 37 | // literal in pseudo-Go syntax. String may only be called after the entire tree 38 | // has been traversed. 39 | func (r *defaultReporter) String() string { 40 | assert(r.root != nil && r.curr == nil) 41 | if r.root.NumDiff == 0 { 42 | return "" 43 | } 44 | ptrs := new(pointerReferences) 45 | text := formatOptions{}.FormatDiff(r.root, ptrs) 46 | resolveReferences(text) 47 | return text.String() 48 | } 49 | 50 | func assert(ok bool) { 51 | if !ok { 52 | panic("assertion failure") 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/typeparams/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mod/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mod/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mod/internal/lazyregexp/lazyre.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package lazyregexp is a thin wrapper over regexp, allowing the use of global 6 | // regexp variables without forcing them to be compiled at init. 7 | package lazyregexp 8 | 9 | import ( 10 | "os" 11 | "regexp" 12 | "strings" 13 | "sync" 14 | ) 15 | 16 | // Regexp is a wrapper around regexp.Regexp, where the underlying regexp will be 17 | // compiled the first time it is needed. 18 | type Regexp struct { 19 | str string 20 | once sync.Once 21 | rx *regexp.Regexp 22 | } 23 | 24 | func (r *Regexp) re() *regexp.Regexp { 25 | r.once.Do(r.build) 26 | return r.rx 27 | } 28 | 29 | func (r *Regexp) build() { 30 | r.rx = regexp.MustCompile(r.str) 31 | r.str = "" 32 | } 33 | 34 | func (r *Regexp) FindSubmatch(s []byte) [][]byte { 35 | return r.re().FindSubmatch(s) 36 | } 37 | 38 | func (r *Regexp) FindStringSubmatch(s string) []string { 39 | return r.re().FindStringSubmatch(s) 40 | } 41 | 42 | func (r *Regexp) FindStringSubmatchIndex(s string) []int { 43 | return r.re().FindStringSubmatchIndex(s) 44 | } 45 | 46 | func (r *Regexp) ReplaceAllString(src, repl string) string { 47 | return r.re().ReplaceAllString(src, repl) 48 | } 49 | 50 | func (r *Regexp) FindString(s string) string { 51 | return r.re().FindString(s) 52 | } 53 | 54 | func (r *Regexp) FindAllString(s string, n int) []string { 55 | return r.re().FindAllString(s, n) 56 | } 57 | 58 | func (r *Regexp) MatchString(s string) bool { 59 | return r.re().MatchString(s) 60 | } 61 | 62 | func (r *Regexp) SubexpNames() []string { 63 | return r.re().SubexpNames() 64 | } 65 | 66 | var inTest = len(os.Args) > 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") 67 | 68 | // New creates a new lazy regexp, delaying the compiling work until it is first 69 | // needed. If the code is being run as part of tests, the regexp compiling will 70 | // happen immediately. 71 | func New(str string) *Regexp { 72 | lr := &Regexp{str: str} 73 | if inTest { 74 | // In tests, always compile the regexps early. 75 | lr.re() 76 | } 77 | return lr 78 | } 79 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sync/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sync/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/execabs/execabs_go118.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.19 6 | // +build !go1.19 7 | 8 | package execabs 9 | 10 | import "os/exec" 11 | 12 | func isGo119ErrDot(err error) bool { 13 | return false 14 | } 15 | 16 | func isGo119ErrFieldSet(cmd *exec.Cmd) bool { 17 | return false 18 | } 19 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/execabs/execabs_go119.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.19 6 | // +build go1.19 7 | 8 | package execabs 9 | 10 | import ( 11 | "errors" 12 | "os/exec" 13 | ) 14 | 15 | func isGo119ErrDot(err error) bool { 16 | return errors.Is(err, exec.ErrDot) 17 | } 18 | 19 | func isGo119ErrFieldSet(cmd *exec.Cmd) bool { 20 | return cmd.Err != nil 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/analysis/passes/inspect/inspect.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package inspect defines an Analyzer that provides an AST inspector 6 | // (golang.org/x/tools/go/ast/inspector.Inspector) for the syntax trees 7 | // of a package. It is only a building block for other analyzers. 8 | // 9 | // Example of use in another analysis: 10 | // 11 | // import ( 12 | // "golang.org/x/tools/go/analysis" 13 | // "golang.org/x/tools/go/analysis/passes/inspect" 14 | // "golang.org/x/tools/go/ast/inspector" 15 | // ) 16 | // 17 | // var Analyzer = &analysis.Analyzer{ 18 | // ... 19 | // Requires: []*analysis.Analyzer{inspect.Analyzer}, 20 | // } 21 | // 22 | // func run(pass *analysis.Pass) (interface{}, error) { 23 | // inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) 24 | // inspect.Preorder(nil, func(n ast.Node) { 25 | // ... 26 | // }) 27 | // return nil, nil 28 | // } 29 | package inspect 30 | 31 | import ( 32 | "reflect" 33 | 34 | "golang.org/x/tools/go/analysis" 35 | "golang.org/x/tools/go/ast/inspector" 36 | ) 37 | 38 | var Analyzer = &analysis.Analyzer{ 39 | Name: "inspect", 40 | Doc: "optimize AST traversal for later passes", 41 | URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/inspect", 42 | Run: run, 43 | RunDespiteErrors: true, 44 | ResultType: reflect.TypeOf(new(inspector.Inspector)), 45 | } 46 | 47 | func run(pass *analysis.Pass) (interface{}, error) { 48 | return inspector.New(pass.Files), nil 49 | } 50 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/analysis/passes/nilness/cmd/nilness/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // The nilness command applies the golang.org/x/tools/go/analysis/passes/nilness 6 | // analysis to the specified packages of Go source code. 7 | package main 8 | 9 | import ( 10 | "golang.org/x/tools/go/analysis/passes/nilness" 11 | "golang.org/x/tools/go/analysis/singlechecker" 12 | ) 13 | 14 | func main() { singlechecker.Main(nilness.Analyzer) } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/analysis/passes/nilness/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package nilness inspects the control-flow graph of an SSA function 6 | // and reports errors such as nil pointer dereferences and degenerate 7 | // nil pointer comparisons. 8 | // 9 | // # Analyzer nilness 10 | // 11 | // nilness: check for redundant or impossible nil comparisons 12 | // 13 | // The nilness checker inspects the control-flow graph of each function in 14 | // a package and reports nil pointer dereferences, degenerate nil 15 | // pointers, and panics with nil values. A degenerate comparison is of the form 16 | // x==nil or x!=nil where x is statically known to be nil or non-nil. These are 17 | // often a mistake, especially in control flow related to errors. Panics with nil 18 | // values are checked because they are not detectable by 19 | // 20 | // if r := recover(); r != nil { 21 | // 22 | // This check reports conditions such as: 23 | // 24 | // if f == nil { // impossible condition (f is a function) 25 | // } 26 | // 27 | // and: 28 | // 29 | // p := &v 30 | // ... 31 | // if p != nil { // tautological condition 32 | // } 33 | // 34 | // and: 35 | // 36 | // if p == nil { 37 | // print(*p) // nil dereference 38 | // } 39 | // 40 | // and: 41 | // 42 | // if p == nil { 43 | // panic(p) 44 | // } 45 | package nilness 46 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/analysis/singlechecker/singlechecker.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package singlechecker defines the main function for an analysis 6 | // driver with only a single analysis. 7 | // This package makes it easy for a provider of an analysis package to 8 | // also provide a standalone tool that runs just that analysis. 9 | // 10 | // For example, if example.org/findbadness is an analysis package, 11 | // all that is needed to define a standalone tool is a file, 12 | // example.org/findbadness/cmd/findbadness/main.go, containing: 13 | // 14 | // // The findbadness command runs an analysis. 15 | // package main 16 | // 17 | // import ( 18 | // "example.org/findbadness" 19 | // "golang.org/x/tools/go/analysis/singlechecker" 20 | // ) 21 | // 22 | // func main() { singlechecker.Main(findbadness.Analyzer) } 23 | package singlechecker 24 | 25 | import ( 26 | "flag" 27 | "fmt" 28 | "log" 29 | "os" 30 | "strings" 31 | 32 | "golang.org/x/tools/go/analysis" 33 | "golang.org/x/tools/go/analysis/internal/analysisflags" 34 | "golang.org/x/tools/go/analysis/internal/checker" 35 | "golang.org/x/tools/go/analysis/unitchecker" 36 | ) 37 | 38 | // Main is the main function for a checker command for a single analysis. 39 | func Main(a *analysis.Analyzer) { 40 | log.SetFlags(0) 41 | log.SetPrefix(a.Name + ": ") 42 | 43 | analyzers := []*analysis.Analyzer{a} 44 | 45 | if err := analysis.Validate(analyzers); err != nil { 46 | log.Fatal(err) 47 | } 48 | 49 | checker.RegisterFlags() 50 | 51 | flag.Usage = func() { 52 | paras := strings.Split(a.Doc, "\n\n") 53 | fmt.Fprintf(os.Stderr, "%s: %s\n\n", a.Name, paras[0]) 54 | fmt.Fprintf(os.Stderr, "Usage: %s [-flag] [package]\n\n", a.Name) 55 | if len(paras) > 1 { 56 | fmt.Fprintln(os.Stderr, strings.Join(paras[1:], "\n\n")) 57 | } 58 | fmt.Fprintln(os.Stderr, "\nFlags:") 59 | flag.PrintDefaults() 60 | } 61 | 62 | analyzers = analysisflags.Parse(analyzers, false) 63 | 64 | args := flag.Args() 65 | if len(args) == 0 { 66 | flag.Usage() 67 | os.Exit(1) 68 | } 69 | 70 | if len(args) == 1 && strings.HasSuffix(args[0], ".cfg") { 71 | unitchecker.Run(args[0], analyzers) 72 | panic("unreachable") 73 | } 74 | 75 | os.Exit(checker.Run(args, analyzers)) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/analysis/unitchecker/unitchecker112.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.12 6 | // +build go1.12 7 | 8 | package unitchecker 9 | 10 | import "go/importer" 11 | 12 | func init() { 13 | importerForCompiler = importer.ForCompiler 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/ast/astutil/util.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package astutil 6 | 7 | import "go/ast" 8 | 9 | // Unparen returns e with any enclosing parentheses stripped. 10 | func Unparen(e ast.Expr) ast.Expr { 11 | for { 12 | p, ok := e.(*ast.ParenExpr) 13 | if !ok { 14 | return e 15 | } 16 | e = p.X 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/buildutil/tags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package buildutil 6 | 7 | // This logic was copied from stringsFlag from $GOROOT/src/cmd/go/build.go. 8 | 9 | import "fmt" 10 | 11 | const TagsFlagDoc = "a list of `build tags` to consider satisfied during the build. " + 12 | "For more information about build tags, see the description of " + 13 | "build constraints in the documentation for the go/build package" 14 | 15 | // TagsFlag is an implementation of the flag.Value and flag.Getter interfaces that parses 16 | // a flag value in the same manner as go build's -tags flag and 17 | // populates a []string slice. 18 | // 19 | // See $GOROOT/src/go/build/doc.go for description of build tags. 20 | // See $GOROOT/src/cmd/go/doc.go for description of 'go build -tags' flag. 21 | // 22 | // Example: 23 | // 24 | // flag.Var((*buildutil.TagsFlag)(&build.Default.BuildTags), "tags", buildutil.TagsFlagDoc) 25 | type TagsFlag []string 26 | 27 | func (v *TagsFlag) Set(s string) error { 28 | var err error 29 | *v, err = splitQuotedFields(s) 30 | if *v == nil { 31 | *v = []string{} 32 | } 33 | return err 34 | } 35 | 36 | func (v *TagsFlag) Get() interface{} { return *v } 37 | 38 | func splitQuotedFields(s string) ([]string, error) { 39 | // Split fields allowing '' or "" around elements. 40 | // Quotes further inside the string do not count. 41 | var f []string 42 | for len(s) > 0 { 43 | for len(s) > 0 && isSpaceByte(s[0]) { 44 | s = s[1:] 45 | } 46 | if len(s) == 0 { 47 | break 48 | } 49 | // Accepted quoted string. No unescaping inside. 50 | if s[0] == '"' || s[0] == '\'' { 51 | quote := s[0] 52 | s = s[1:] 53 | i := 0 54 | for i < len(s) && s[i] != quote { 55 | i++ 56 | } 57 | if i >= len(s) { 58 | return nil, fmt.Errorf("unterminated %c string", quote) 59 | } 60 | f = append(f, s[:i]) 61 | s = s[i+1:] 62 | continue 63 | } 64 | i := 0 65 | for i < len(s) && !isSpaceByte(s[i]) { 66 | i++ 67 | } 68 | f = append(f, s[:i]) 69 | s = s[i:] 70 | } 71 | return f, nil 72 | } 73 | 74 | func (v *TagsFlag) String() string { 75 | return "" 76 | } 77 | 78 | func isSpaceByte(c byte) bool { 79 | return c == ' ' || c == '\t' || c == '\n' || c == '\r' 80 | } 81 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/callgraph/vta/internal/trie/scope.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package trie 6 | 7 | import ( 8 | "strconv" 9 | "sync/atomic" 10 | ) 11 | 12 | // Scope represents a distinct collection of maps. 13 | // Maps with the same Scope can be equal. Maps in different scopes are distinct. 14 | // Each Builder creates maps within a unique Scope. 15 | type Scope struct { 16 | id int32 17 | } 18 | 19 | var nextScopeId int32 20 | 21 | func newScope() Scope { 22 | id := atomic.AddInt32(&nextScopeId, 1) 23 | return Scope{id: id} 24 | } 25 | 26 | func (s Scope) String() string { 27 | return strconv.Itoa(int(s.id)) 28 | } 29 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/gcexportdata/importer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gcexportdata 6 | 7 | import ( 8 | "fmt" 9 | "go/token" 10 | "go/types" 11 | "os" 12 | ) 13 | 14 | // NewImporter returns a new instance of the types.Importer interface 15 | // that reads type information from export data files written by gc. 16 | // The Importer also satisfies types.ImporterFrom. 17 | // 18 | // Export data files are located using "go build" workspace conventions 19 | // and the build.Default context. 20 | // 21 | // Use this importer instead of go/importer.For("gc", ...) to avoid the 22 | // version-skew problems described in the documentation of this package, 23 | // or to control the FileSet or access the imports map populated during 24 | // package loading. 25 | // 26 | // Deprecated: Use the higher-level API in golang.org/x/tools/go/packages, 27 | // which is more efficient. 28 | func NewImporter(fset *token.FileSet, imports map[string]*types.Package) types.ImporterFrom { 29 | return importer{fset, imports} 30 | } 31 | 32 | type importer struct { 33 | fset *token.FileSet 34 | imports map[string]*types.Package 35 | } 36 | 37 | func (imp importer) Import(importPath string) (*types.Package, error) { 38 | return imp.ImportFrom(importPath, "", 0) 39 | } 40 | 41 | func (imp importer) ImportFrom(importPath, srcDir string, mode types.ImportMode) (_ *types.Package, err error) { 42 | filename, path := Find(importPath, srcDir) 43 | if filename == "" { 44 | if importPath == "unsafe" { 45 | // Even for unsafe, call Find first in case 46 | // the package was vendored. 47 | return types.Unsafe, nil 48 | } 49 | return nil, fmt.Errorf("can't find import: %s", importPath) 50 | } 51 | 52 | if pkg, ok := imp.imports[path]; ok && pkg.Complete() { 53 | return pkg, nil // cache hit 54 | } 55 | 56 | // open file 57 | f, err := os.Open(filename) 58 | if err != nil { 59 | return nil, err 60 | } 61 | defer func() { 62 | f.Close() 63 | if err != nil { 64 | // add file name to error 65 | err = fmt.Errorf("reading export data: %s: %v", filename, err) 66 | } 67 | }() 68 | 69 | r, err := NewReader(f) 70 | if err != nil { 71 | return nil, err 72 | } 73 | 74 | return Read(r, imp.fset, imp.imports, path) 75 | } 76 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/internal/cgo/cgo_pkgconfig.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cgo 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | "go/build" 11 | exec "golang.org/x/sys/execabs" 12 | "strings" 13 | ) 14 | 15 | // pkgConfig runs pkg-config with the specified arguments and returns the flags it prints. 16 | func pkgConfig(mode string, pkgs []string) (flags []string, err error) { 17 | cmd := exec.Command("pkg-config", append([]string{mode}, pkgs...)...) 18 | out, err := cmd.CombinedOutput() 19 | if err != nil { 20 | s := fmt.Sprintf("%s failed: %v", strings.Join(cmd.Args, " "), err) 21 | if len(out) > 0 { 22 | s = fmt.Sprintf("%s: %s", s, out) 23 | } 24 | return nil, errors.New(s) 25 | } 26 | if len(out) > 0 { 27 | flags = strings.Fields(string(out)) 28 | } 29 | return 30 | } 31 | 32 | // pkgConfigFlags calls pkg-config if needed and returns the cflags 33 | // needed to build the package. 34 | func pkgConfigFlags(p *build.Package) (cflags []string, err error) { 35 | if len(p.CgoPkgConfig) == 0 { 36 | return nil, nil 37 | } 38 | return pkgConfig("--cflags", p.CgoPkgConfig) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/internal/packagesdriver/sizes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package packagesdriver fetches type sizes for go/packages and go/analysis. 6 | package packagesdriver 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "go/types" 12 | "strings" 13 | 14 | "golang.org/x/tools/internal/gocommand" 15 | ) 16 | 17 | var debug = false 18 | 19 | func GetSizesGolist(ctx context.Context, inv gocommand.Invocation, gocmdRunner *gocommand.Runner) (types.Sizes, error) { 20 | inv.Verb = "list" 21 | inv.Args = []string{"-f", "{{context.GOARCH}} {{context.Compiler}}", "--", "unsafe"} 22 | stdout, stderr, friendlyErr, rawErr := gocmdRunner.RunRaw(ctx, inv) 23 | var goarch, compiler string 24 | if rawErr != nil { 25 | if rawErrMsg := rawErr.Error(); strings.Contains(rawErrMsg, "cannot find main module") || strings.Contains(rawErrMsg, "go.mod file not found") { 26 | // User's running outside of a module. All bets are off. Get GOARCH and guess compiler is gc. 27 | // TODO(matloob): Is this a problem in practice? 28 | inv.Verb = "env" 29 | inv.Args = []string{"GOARCH"} 30 | envout, enverr := gocmdRunner.Run(ctx, inv) 31 | if enverr != nil { 32 | return nil, enverr 33 | } 34 | goarch = strings.TrimSpace(envout.String()) 35 | compiler = "gc" 36 | } else { 37 | return nil, friendlyErr 38 | } 39 | } else { 40 | fields := strings.Fields(stdout.String()) 41 | if len(fields) < 2 { 42 | return nil, fmt.Errorf("could not parse GOARCH and Go compiler in format \" \":\nstdout: <<%s>>\nstderr: <<%s>>", 43 | stdout.String(), stderr.String()) 44 | } 45 | goarch = fields[0] 46 | compiler = fields[1] 47 | } 48 | return types.SizesFor(compiler, goarch), nil 49 | } 50 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/packages/loadmode_string.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packages 6 | 7 | import ( 8 | "fmt" 9 | "strings" 10 | ) 11 | 12 | var allModes = []LoadMode{ 13 | NeedName, 14 | NeedFiles, 15 | NeedCompiledGoFiles, 16 | NeedImports, 17 | NeedDeps, 18 | NeedExportFile, 19 | NeedTypes, 20 | NeedSyntax, 21 | NeedTypesInfo, 22 | NeedTypesSizes, 23 | } 24 | 25 | var modeStrings = []string{ 26 | "NeedName", 27 | "NeedFiles", 28 | "NeedCompiledGoFiles", 29 | "NeedImports", 30 | "NeedDeps", 31 | "NeedExportFile", 32 | "NeedTypes", 33 | "NeedSyntax", 34 | "NeedTypesInfo", 35 | "NeedTypesSizes", 36 | } 37 | 38 | func (mod LoadMode) String() string { 39 | m := mod 40 | if m == 0 { 41 | return "LoadMode(0)" 42 | } 43 | var out []string 44 | for i, x := range allModes { 45 | if x > m { 46 | break 47 | } 48 | if (m & x) != 0 { 49 | out = append(out, modeStrings[i]) 50 | m = m ^ x 51 | } 52 | } 53 | if m != 0 { 54 | out = append(out, "Unknown") 55 | } 56 | return fmt.Sprintf("LoadMode(%s)", strings.Join(out, "|")) 57 | } 58 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/packages/visit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package packages 6 | 7 | import ( 8 | "fmt" 9 | "os" 10 | "sort" 11 | ) 12 | 13 | // Visit visits all the packages in the import graph whose roots are 14 | // pkgs, calling the optional pre function the first time each package 15 | // is encountered (preorder), and the optional post function after a 16 | // package's dependencies have been visited (postorder). 17 | // The boolean result of pre(pkg) determines whether 18 | // the imports of package pkg are visited. 19 | func Visit(pkgs []*Package, pre func(*Package) bool, post func(*Package)) { 20 | seen := make(map[*Package]bool) 21 | var visit func(*Package) 22 | visit = func(pkg *Package) { 23 | if !seen[pkg] { 24 | seen[pkg] = true 25 | 26 | if pre == nil || pre(pkg) { 27 | paths := make([]string, 0, len(pkg.Imports)) 28 | for path := range pkg.Imports { 29 | paths = append(paths, path) 30 | } 31 | sort.Strings(paths) // Imports is a map, this makes visit stable 32 | for _, path := range paths { 33 | visit(pkg.Imports[path]) 34 | } 35 | } 36 | 37 | if post != nil { 38 | post(pkg) 39 | } 40 | } 41 | } 42 | for _, pkg := range pkgs { 43 | visit(pkg) 44 | } 45 | } 46 | 47 | // PrintErrors prints to os.Stderr the accumulated errors of all 48 | // packages in the import graph rooted at pkgs, dependencies first. 49 | // PrintErrors returns the number of errors printed. 50 | func PrintErrors(pkgs []*Package) int { 51 | var n int 52 | Visit(pkgs, nil, func(pkg *Package) { 53 | for _, err := range pkg.Errors { 54 | fmt.Fprintln(os.Stderr, err) 55 | n++ 56 | } 57 | }) 58 | return n 59 | } 60 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/ssa/TODO: -------------------------------------------------------------------------------- 1 | -*- text -*- 2 | 3 | SSA Generics to-do list 4 | =========================== 5 | 6 | DOCUMENTATION: 7 | - Read me for internals 8 | 9 | TYPE PARAMETERIZED GENERIC FUNCTIONS: 10 | - sanity.go updates. 11 | - Check source functions going to generics. 12 | - Tests, tests, tests... 13 | 14 | USAGE: 15 | - Back fill users for handling ssa.InstantiateGenerics being off. 16 | 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/ssa/identical.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.8 6 | // +build go1.8 7 | 8 | package ssa 9 | 10 | import "go/types" 11 | 12 | var structTypesIdentical = types.IdenticalIgnoreTags 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/ssa/identical_17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.8 6 | // +build !go1.8 7 | 8 | package ssa 9 | 10 | import "go/types" 11 | 12 | var structTypesIdentical = types.Identical 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/ssa/ssautil/visit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package ssautil // import "golang.org/x/tools/go/ssa/ssautil" 6 | 7 | import "golang.org/x/tools/go/ssa" 8 | 9 | // This file defines utilities for visiting the SSA representation of 10 | // a Program. 11 | // 12 | // TODO(adonovan): test coverage. 13 | 14 | // AllFunctions finds and returns the set of functions potentially 15 | // needed by program prog, as determined by a simple linker-style 16 | // reachability algorithm starting from the members and method-sets of 17 | // each package. The result may include anonymous functions and 18 | // synthetic wrappers. 19 | // 20 | // Precondition: all packages are built. 21 | func AllFunctions(prog *ssa.Program) map[*ssa.Function]bool { 22 | visit := visitor{ 23 | prog: prog, 24 | seen: make(map[*ssa.Function]bool), 25 | } 26 | visit.program() 27 | return visit.seen 28 | } 29 | 30 | type visitor struct { 31 | prog *ssa.Program 32 | seen map[*ssa.Function]bool 33 | } 34 | 35 | func (visit *visitor) program() { 36 | for _, pkg := range visit.prog.AllPackages() { 37 | for _, mem := range pkg.Members { 38 | if fn, ok := mem.(*ssa.Function); ok { 39 | visit.function(fn) 40 | } 41 | } 42 | } 43 | for _, T := range visit.prog.RuntimeTypes() { 44 | mset := visit.prog.MethodSets.MethodSet(T) 45 | for i, n := 0, mset.Len(); i < n; i++ { 46 | visit.function(visit.prog.MethodValue(mset.At(i))) 47 | } 48 | } 49 | } 50 | 51 | func (visit *visitor) function(fn *ssa.Function) { 52 | if !visit.seen[fn] { 53 | visit.seen[fn] = true 54 | var buf [10]*ssa.Value // avoid alloc in common case 55 | for _, b := range fn.Blocks { 56 | for _, instr := range b.Instrs { 57 | for _, op := range instr.Operands(buf[:0]) { 58 | if fn, ok := (*op).(*ssa.Function); ok { 59 | visit.function(fn) 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | // MainPackages returns the subset of the specified packages 68 | // named "main" that define a main function. 69 | // The result may include synthetic "testmain" packages. 70 | func MainPackages(pkgs []*ssa.Package) []*ssa.Package { 71 | var mains []*ssa.Package 72 | for _, pkg := range pkgs { 73 | if pkg.Pkg.Name() == "main" && pkg.Func("main") != nil { 74 | mains = append(mains, pkg) 75 | } 76 | } 77 | return mains 78 | } 79 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/types/typeutil/callee.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package typeutil 6 | 7 | import ( 8 | "go/ast" 9 | "go/types" 10 | 11 | "golang.org/x/tools/go/ast/astutil" 12 | "golang.org/x/tools/internal/typeparams" 13 | ) 14 | 15 | // Callee returns the named target of a function call, if any: 16 | // a function, method, builtin, or variable. 17 | // 18 | // Functions and methods may potentially have type parameters. 19 | func Callee(info *types.Info, call *ast.CallExpr) types.Object { 20 | fun := astutil.Unparen(call.Fun) 21 | 22 | // Look through type instantiation if necessary. 23 | isInstance := false 24 | switch fun.(type) { 25 | case *ast.IndexExpr, *typeparams.IndexListExpr: 26 | // When extracting the callee from an *IndexExpr, we need to check that 27 | // it is a *types.Func and not a *types.Var. 28 | // Example: Don't match a slice m within the expression `m[0]()`. 29 | isInstance = true 30 | fun, _, _, _ = typeparams.UnpackIndexExpr(fun) 31 | } 32 | 33 | var obj types.Object 34 | switch fun := fun.(type) { 35 | case *ast.Ident: 36 | obj = info.Uses[fun] // type, var, builtin, or declared func 37 | case *ast.SelectorExpr: 38 | if sel, ok := info.Selections[fun]; ok { 39 | obj = sel.Obj() // method or field 40 | } else { 41 | obj = info.Uses[fun.Sel] // qualified identifier? 42 | } 43 | } 44 | if _, ok := obj.(*types.TypeName); ok { 45 | return nil // T(x) is a conversion, not a call 46 | } 47 | // A Func is required to match instantiations. 48 | if _, ok := obj.(*types.Func); isInstance && !ok { 49 | return nil // Was not a Func. 50 | } 51 | return obj 52 | } 53 | 54 | // StaticCallee returns the target (function or method) of a static function 55 | // call, if any. It returns nil for calls to builtins. 56 | // 57 | // Note: for calls of instantiated functions and methods, StaticCallee returns 58 | // the corresponding generic function or method on the generic type. 59 | func StaticCallee(info *types.Info, call *ast.CallExpr) *types.Func { 60 | if f, ok := Callee(info, call).(*types.Func); ok && !interfaceMethod(f) { 61 | return f 62 | } 63 | return nil 64 | } 65 | 66 | func interfaceMethod(f *types.Func) bool { 67 | recv := f.Type().(*types.Signature).Recv() 68 | return recv != nil && types.IsInterface(recv.Type()) 69 | } 70 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/types/typeutil/imports.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package typeutil 6 | 7 | import "go/types" 8 | 9 | // Dependencies returns all dependencies of the specified packages. 10 | // 11 | // Dependent packages appear in topological order: if package P imports 12 | // package Q, Q appears earlier than P in the result. 13 | // The algorithm follows import statements in the order they 14 | // appear in the source code, so the result is a total order. 15 | func Dependencies(pkgs ...*types.Package) []*types.Package { 16 | var result []*types.Package 17 | seen := make(map[*types.Package]bool) 18 | var visit func(pkgs []*types.Package) 19 | visit = func(pkgs []*types.Package) { 20 | for _, p := range pkgs { 21 | if !seen[p] { 22 | seen[p] = true 23 | visit(p.Imports()) 24 | result = append(result, p) 25 | } 26 | } 27 | } 28 | visit(pkgs) 29 | return result 30 | } 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/types/typeutil/methodsetcache.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // This file implements a cache of method sets. 6 | 7 | package typeutil 8 | 9 | import ( 10 | "go/types" 11 | "sync" 12 | ) 13 | 14 | // A MethodSetCache records the method set of each type T for which 15 | // MethodSet(T) is called so that repeat queries are fast. 16 | // The zero value is a ready-to-use cache instance. 17 | type MethodSetCache struct { 18 | mu sync.Mutex 19 | named map[*types.Named]struct{ value, pointer *types.MethodSet } // method sets for named N and *N 20 | others map[types.Type]*types.MethodSet // all other types 21 | } 22 | 23 | // MethodSet returns the method set of type T. It is thread-safe. 24 | // 25 | // If cache is nil, this function is equivalent to types.NewMethodSet(T). 26 | // Utility functions can thus expose an optional *MethodSetCache 27 | // parameter to clients that care about performance. 28 | func (cache *MethodSetCache) MethodSet(T types.Type) *types.MethodSet { 29 | if cache == nil { 30 | return types.NewMethodSet(T) 31 | } 32 | cache.mu.Lock() 33 | defer cache.mu.Unlock() 34 | 35 | switch T := T.(type) { 36 | case *types.Named: 37 | return cache.lookupNamed(T).value 38 | 39 | case *types.Pointer: 40 | if N, ok := T.Elem().(*types.Named); ok { 41 | return cache.lookupNamed(N).pointer 42 | } 43 | } 44 | 45 | // all other types 46 | // (The map uses pointer equivalence, not type identity.) 47 | mset := cache.others[T] 48 | if mset == nil { 49 | mset = types.NewMethodSet(T) 50 | if cache.others == nil { 51 | cache.others = make(map[types.Type]*types.MethodSet) 52 | } 53 | cache.others[T] = mset 54 | } 55 | return mset 56 | } 57 | 58 | func (cache *MethodSetCache) lookupNamed(named *types.Named) struct{ value, pointer *types.MethodSet } { 59 | if cache.named == nil { 60 | cache.named = make(map[*types.Named]struct{ value, pointer *types.MethodSet }) 61 | } 62 | // Avoid recomputing mset(*T) for each distinct Pointer 63 | // instance whose underlying type is a named type. 64 | msets, ok := cache.named[named] 65 | if !ok { 66 | msets.value = types.NewMethodSet(named) 67 | msets.pointer = types.NewMethodSet(types.NewPointer(named)) 68 | cache.named[named] = msets 69 | } 70 | return msets 71 | } 72 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/go/types/typeutil/ui.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package typeutil 6 | 7 | // This file defines utilities for user interfaces that display types. 8 | 9 | import "go/types" 10 | 11 | // IntuitiveMethodSet returns the intuitive method set of a type T, 12 | // which is the set of methods you can call on an addressable value of 13 | // that type. 14 | // 15 | // The result always contains MethodSet(T), and is exactly MethodSet(T) 16 | // for interface types and for pointer-to-concrete types. 17 | // For all other concrete types T, the result additionally 18 | // contains each method belonging to *T if there is no identically 19 | // named method on T itself. 20 | // 21 | // This corresponds to user intuition about method sets; 22 | // this function is intended only for user interfaces. 23 | // 24 | // The order of the result is as for types.MethodSet(T). 25 | func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection { 26 | isPointerToConcrete := func(T types.Type) bool { 27 | ptr, ok := T.(*types.Pointer) 28 | return ok && !types.IsInterface(ptr.Elem()) 29 | } 30 | 31 | var result []*types.Selection 32 | mset := msets.MethodSet(T) 33 | if types.IsInterface(T) || isPointerToConcrete(T) { 34 | for i, n := 0, mset.Len(); i < n; i++ { 35 | result = append(result, mset.At(i)) 36 | } 37 | } else { 38 | // T is some other concrete type. 39 | // Report methods of T and *T, preferring those of T. 40 | pmset := msets.MethodSet(types.NewPointer(T)) 41 | for i, n := 0, pmset.Len(); i < n; i++ { 42 | meth := pmset.At(i) 43 | if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil { 44 | meth = m 45 | } 46 | result = append(result, meth) 47 | } 48 | 49 | } 50 | return result 51 | } 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/diff/lcs/git.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2022 The Go Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE file. 6 | # 7 | # Creates a zip file containing all numbered versions 8 | # of the commit history of a large source file, for use 9 | # as input data for the tests of the diff algorithm. 10 | # 11 | # Run script from root of the x/tools repo. 12 | 13 | set -eu 14 | 15 | # WARNING: This script will install the latest version of $file 16 | # The largest real source file in the x/tools repo. 17 | # file=internal/lsp/source/completion/completion.go 18 | # file=internal/lsp/source/diagnostics.go 19 | file=internal/lsp/protocol/tsprotocol.go 20 | 21 | tmp=$(mktemp -d) 22 | git log $file | 23 | awk '/^commit / {print $2}' | 24 | nl -ba -nrz | 25 | while read n hash; do 26 | git checkout --quiet $hash $file 27 | cp -f $file $tmp/$n 28 | done 29 | (cd $tmp && zip -q - *) > testdata.zip 30 | rm -fr $tmp 31 | git restore --staged $file 32 | git restore $file 33 | echo "Created testdata.zip" 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/diff/lcs/labels.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package lcs 6 | 7 | import ( 8 | "fmt" 9 | ) 10 | 11 | // For each D, vec[D] has length D+1, 12 | // and the label for (D, k) is stored in vec[D][(D+k)/2]. 13 | type label struct { 14 | vec [][]int 15 | } 16 | 17 | // Temporary checking DO NOT COMMIT true TO PRODUCTION CODE 18 | const debug = false 19 | 20 | // debugging. check that the (d,k) pair is valid 21 | // (that is, -d<=k<=d and d+k even) 22 | func checkDK(D, k int) { 23 | if k >= -D && k <= D && (D+k)%2 == 0 { 24 | return 25 | } 26 | panic(fmt.Sprintf("out of range, d=%d,k=%d", D, k)) 27 | } 28 | 29 | func (t *label) set(D, k, x int) { 30 | if debug { 31 | checkDK(D, k) 32 | } 33 | for len(t.vec) <= D { 34 | t.vec = append(t.vec, nil) 35 | } 36 | if t.vec[D] == nil { 37 | t.vec[D] = make([]int, D+1) 38 | } 39 | t.vec[D][(D+k)/2] = x // known that D+k is even 40 | } 41 | 42 | func (t *label) get(d, k int) int { 43 | if debug { 44 | checkDK(d, k) 45 | } 46 | return int(t.vec[d][(d+k)/2]) 47 | } 48 | 49 | func newtriang(limit int) label { 50 | if limit < 100 { 51 | // Preallocate if limit is not large. 52 | return label{vec: make([][]int, limit)} 53 | } 54 | return label{} 55 | } 56 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/event/core/event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package core provides support for event based telemetry. 6 | package core 7 | 8 | import ( 9 | "fmt" 10 | "time" 11 | 12 | "golang.org/x/tools/internal/event/label" 13 | ) 14 | 15 | // Event holds the information about an event of note that occurred. 16 | type Event struct { 17 | at time.Time 18 | 19 | // As events are often on the stack, storing the first few labels directly 20 | // in the event can avoid an allocation at all for the very common cases of 21 | // simple events. 22 | // The length needs to be large enough to cope with the majority of events 23 | // but no so large as to cause undue stack pressure. 24 | // A log message with two values will use 3 labels (one for each value and 25 | // one for the message itself). 26 | 27 | static [3]label.Label // inline storage for the first few labels 28 | dynamic []label.Label // dynamically sized storage for remaining labels 29 | } 30 | 31 | // eventLabelMap implements label.Map for a the labels of an Event. 32 | type eventLabelMap struct { 33 | event Event 34 | } 35 | 36 | func (ev Event) At() time.Time { return ev.at } 37 | 38 | func (ev Event) Format(f fmt.State, r rune) { 39 | if !ev.at.IsZero() { 40 | fmt.Fprint(f, ev.at.Format("2006/01/02 15:04:05 ")) 41 | } 42 | for index := 0; ev.Valid(index); index++ { 43 | if l := ev.Label(index); l.Valid() { 44 | fmt.Fprintf(f, "\n\t%v", l) 45 | } 46 | } 47 | } 48 | 49 | func (ev Event) Valid(index int) bool { 50 | return index >= 0 && index < len(ev.static)+len(ev.dynamic) 51 | } 52 | 53 | func (ev Event) Label(index int) label.Label { 54 | if index < len(ev.static) { 55 | return ev.static[index] 56 | } 57 | return ev.dynamic[index-len(ev.static)] 58 | } 59 | 60 | func (ev Event) Find(key label.Key) label.Label { 61 | for _, l := range ev.static { 62 | if l.Key() == key { 63 | return l 64 | } 65 | } 66 | for _, l := range ev.dynamic { 67 | if l.Key() == key { 68 | return l 69 | } 70 | } 71 | return label.Label{} 72 | } 73 | 74 | func MakeEvent(static [3]label.Label, labels []label.Label) Event { 75 | return Event{ 76 | static: static, 77 | dynamic: labels, 78 | } 79 | } 80 | 81 | // CloneEvent event returns a copy of the event with the time adjusted to at. 82 | func CloneEvent(ev Event, at time.Time) Event { 83 | ev.at = at 84 | return ev 85 | } 86 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/event/core/export.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package core 6 | 7 | import ( 8 | "context" 9 | "sync/atomic" 10 | "time" 11 | "unsafe" 12 | 13 | "golang.org/x/tools/internal/event/label" 14 | ) 15 | 16 | // Exporter is a function that handles events. 17 | // It may return a modified context and event. 18 | type Exporter func(context.Context, Event, label.Map) context.Context 19 | 20 | var ( 21 | exporter unsafe.Pointer 22 | ) 23 | 24 | // SetExporter sets the global exporter function that handles all events. 25 | // The exporter is called synchronously from the event call site, so it should 26 | // return quickly so as not to hold up user code. 27 | func SetExporter(e Exporter) { 28 | p := unsafe.Pointer(&e) 29 | if e == nil { 30 | // &e is always valid, and so p is always valid, but for the early abort 31 | // of ProcessEvent to be efficient it needs to make the nil check on the 32 | // pointer without having to dereference it, so we make the nil function 33 | // also a nil pointer 34 | p = nil 35 | } 36 | atomic.StorePointer(&exporter, p) 37 | } 38 | 39 | // deliver is called to deliver an event to the supplied exporter. 40 | // it will fill in the time. 41 | func deliver(ctx context.Context, exporter Exporter, ev Event) context.Context { 42 | // add the current time to the event 43 | ev.at = time.Now() 44 | // hand the event off to the current exporter 45 | return exporter(ctx, ev, ev) 46 | } 47 | 48 | // Export is called to deliver an event to the global exporter if set. 49 | func Export(ctx context.Context, ev Event) context.Context { 50 | // get the global exporter and abort early if there is not one 51 | exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter)) 52 | if exporterPtr == nil { 53 | return ctx 54 | } 55 | return deliver(ctx, *exporterPtr, ev) 56 | } 57 | 58 | // ExportPair is called to deliver a start event to the supplied exporter. 59 | // It also returns a function that will deliver the end event to the same 60 | // exporter. 61 | // It will fill in the time. 62 | func ExportPair(ctx context.Context, begin, end Event) (context.Context, func()) { 63 | // get the global exporter and abort early if there is not one 64 | exporterPtr := (*Exporter)(atomic.LoadPointer(&exporter)) 65 | if exporterPtr == nil { 66 | return ctx, func() {} 67 | } 68 | ctx = deliver(ctx, *exporterPtr, begin) 69 | return ctx, func() { deliver(ctx, *exporterPtr, end) } 70 | } 71 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/event/core/fast.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package core 6 | 7 | import ( 8 | "context" 9 | 10 | "golang.org/x/tools/internal/event/keys" 11 | "golang.org/x/tools/internal/event/label" 12 | ) 13 | 14 | // Log1 takes a message and one label delivers a log event to the exporter. 15 | // It is a customized version of Print that is faster and does no allocation. 16 | func Log1(ctx context.Context, message string, t1 label.Label) { 17 | Export(ctx, MakeEvent([3]label.Label{ 18 | keys.Msg.Of(message), 19 | t1, 20 | }, nil)) 21 | } 22 | 23 | // Log2 takes a message and two labels and delivers a log event to the exporter. 24 | // It is a customized version of Print that is faster and does no allocation. 25 | func Log2(ctx context.Context, message string, t1 label.Label, t2 label.Label) { 26 | Export(ctx, MakeEvent([3]label.Label{ 27 | keys.Msg.Of(message), 28 | t1, 29 | t2, 30 | }, nil)) 31 | } 32 | 33 | // Metric1 sends a label event to the exporter with the supplied labels. 34 | func Metric1(ctx context.Context, t1 label.Label) context.Context { 35 | return Export(ctx, MakeEvent([3]label.Label{ 36 | keys.Metric.New(), 37 | t1, 38 | }, nil)) 39 | } 40 | 41 | // Metric2 sends a label event to the exporter with the supplied labels. 42 | func Metric2(ctx context.Context, t1, t2 label.Label) context.Context { 43 | return Export(ctx, MakeEvent([3]label.Label{ 44 | keys.Metric.New(), 45 | t1, 46 | t2, 47 | }, nil)) 48 | } 49 | 50 | // Start1 sends a span start event with the supplied label list to the exporter. 51 | // It also returns a function that will end the span, which should normally be 52 | // deferred. 53 | func Start1(ctx context.Context, name string, t1 label.Label) (context.Context, func()) { 54 | return ExportPair(ctx, 55 | MakeEvent([3]label.Label{ 56 | keys.Start.Of(name), 57 | t1, 58 | }, nil), 59 | MakeEvent([3]label.Label{ 60 | keys.End.New(), 61 | }, nil)) 62 | } 63 | 64 | // Start2 sends a span start event with the supplied label list to the exporter. 65 | // It also returns a function that will end the span, which should normally be 66 | // deferred. 67 | func Start2(ctx context.Context, name string, t1, t2 label.Label) (context.Context, func()) { 68 | return ExportPair(ctx, 69 | MakeEvent([3]label.Label{ 70 | keys.Start.Of(name), 71 | t1, 72 | t2, 73 | }, nil), 74 | MakeEvent([3]label.Label{ 75 | keys.End.New(), 76 | }, nil)) 77 | } 78 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/event/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package event provides a set of packages that cover the main 6 | // concepts of telemetry in an implementation agnostic way. 7 | package event 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/event/keys/standard.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package keys 6 | 7 | var ( 8 | // Msg is a key used to add message strings to label lists. 9 | Msg = NewString("message", "a readable message") 10 | // Label is a key used to indicate an event adds labels to the context. 11 | Label = NewTag("label", "a label context marker") 12 | // Start is used for things like traces that have a name. 13 | Start = NewString("start", "span start") 14 | // Metric is a key used to indicate an event records metrics. 15 | End = NewTag("end", "a span end marker") 16 | // Metric is a key used to indicate an event records metrics. 17 | Detach = NewTag("detach", "a span detach marker") 18 | // Err is a key used to add error values to label lists. 19 | Err = NewError("error", "an error that occurred") 20 | // Metric is a key used to indicate an event records metrics. 21 | Metric = NewTag("metric", "a metric event marker") 22 | ) 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/newInterface10.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.11 6 | // +build !go1.11 7 | 8 | package gcimporter 9 | 10 | import "go/types" 11 | 12 | func newInterface(methods []*types.Func, embeddeds []types.Type) *types.Interface { 13 | named := make([]*types.Named, len(embeddeds)) 14 | for i, e := range embeddeds { 15 | var ok bool 16 | named[i], ok = e.(*types.Named) 17 | if !ok { 18 | panic("embedding of non-defined interfaces in interfaces is not supported before Go 1.11") 19 | } 20 | } 21 | return types.NewInterface(methods, named) 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/newInterface11.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.11 6 | // +build go1.11 7 | 8 | package gcimporter 9 | 10 | import "go/types" 11 | 12 | func newInterface(methods []*types.Func, embeddeds []types.Type) *types.Interface { 13 | return types.NewInterfaceType(methods, embeddeds) 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/support_go117.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.18 6 | // +build !go1.18 7 | 8 | package gcimporter 9 | 10 | import "go/types" 11 | 12 | const iexportVersion = iexportVersionGo1_11 13 | 14 | func additionalPredeclared() []types.Type { 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/support_go118.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.18 6 | // +build go1.18 7 | 8 | package gcimporter 9 | 10 | import "go/types" 11 | 12 | const iexportVersion = iexportVersionGenerics 13 | 14 | // additionalPredeclared returns additional predeclared types in go.1.18. 15 | func additionalPredeclared() []types.Type { 16 | return []types.Type{ 17 | // comparable 18 | types.Universe.Lookup("comparable").Type(), 19 | 20 | // any 21 | types.Universe.Lookup("any").Type(), 22 | } 23 | } 24 | 25 | // See cmd/compile/internal/types.SplitVargenSuffix. 26 | func splitVargenSuffix(name string) (base, suffix string) { 27 | i := len(name) 28 | for i > 0 && name[i-1] >= '0' && name[i-1] <= '9' { 29 | i-- 30 | } 31 | const dot = "·" 32 | if i >= len(dot) && name[i-len(dot):i] == dot { 33 | i -= len(dot) 34 | return name[:i], name[i:] 35 | } 36 | return name, "" 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/unified_no.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !(go1.18 && goexperiment.unified) 6 | // +build !go1.18 !goexperiment.unified 7 | 8 | package gcimporter 9 | 10 | const unifiedIR = false 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/unified_yes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.18 && goexperiment.unified 6 | // +build go1.18,goexperiment.unified 7 | 8 | package gcimporter 9 | 10 | const unifiedIR = true 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/gcimporter/ureader_no.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.18 6 | // +build !go1.18 7 | 8 | package gcimporter 9 | 10 | import ( 11 | "fmt" 12 | "go/token" 13 | "go/types" 14 | ) 15 | 16 | func UImportData(fset *token.FileSet, imports map[string]*types.Package, data []byte, path string) (_ int, pkg *types.Package, err error) { 17 | err = fmt.Errorf("go/tools compiled with a Go version earlier than 1.18 cannot read unified IR export data") 18 | return 19 | } 20 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/packagesinternal/packages.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package packagesinternal exposes internal-only fields from go/packages. 6 | package packagesinternal 7 | 8 | import ( 9 | "golang.org/x/tools/internal/gocommand" 10 | ) 11 | 12 | var GetForTest = func(p interface{}) string { return "" } 13 | var GetDepsErrors = func(p interface{}) []*PackageError { return nil } 14 | 15 | type PackageError struct { 16 | ImportStack []string // shortest path from package named on command line to this one 17 | Pos string // position of error (if present, file:line:col) 18 | Err string // the error itself 19 | } 20 | 21 | var GetGoCmdRunner = func(config interface{}) *gocommand.Runner { return nil } 22 | 23 | var SetGoCmdRunner = func(config interface{}, runner *gocommand.Runner) {} 24 | 25 | var TypecheckCgo int 26 | var DepsErrors int // must be set as a LoadMode to call GetDepsErrors 27 | var ForTest int // must be set as a LoadMode to call GetForTest 28 | 29 | var SetModFlag = func(config interface{}, value string) {} 30 | var SetModFile = func(config interface{}, value string) {} 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/codes.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkgbits 6 | 7 | // A Code is an enum value that can be encoded into bitstreams. 8 | // 9 | // Code types are preferable for enum types, because they allow 10 | // Decoder to detect desyncs. 11 | type Code interface { 12 | // Marker returns the SyncMarker for the Code's dynamic type. 13 | Marker() SyncMarker 14 | 15 | // Value returns the Code's ordinal value. 16 | Value() int 17 | } 18 | 19 | // A CodeVal distinguishes among go/constant.Value encodings. 20 | type CodeVal int 21 | 22 | func (c CodeVal) Marker() SyncMarker { return SyncVal } 23 | func (c CodeVal) Value() int { return int(c) } 24 | 25 | // Note: These values are public and cannot be changed without 26 | // updating the go/types importers. 27 | 28 | const ( 29 | ValBool CodeVal = iota 30 | ValString 31 | ValInt64 32 | ValBigInt 33 | ValBigRat 34 | ValBigFloat 35 | ) 36 | 37 | // A CodeType distinguishes among go/types.Type encodings. 38 | type CodeType int 39 | 40 | func (c CodeType) Marker() SyncMarker { return SyncType } 41 | func (c CodeType) Value() int { return int(c) } 42 | 43 | // Note: These values are public and cannot be changed without 44 | // updating the go/types importers. 45 | 46 | const ( 47 | TypeBasic CodeType = iota 48 | TypeNamed 49 | TypePointer 50 | TypeSlice 51 | TypeArray 52 | TypeChan 53 | TypeMap 54 | TypeSignature 55 | TypeStruct 56 | TypeInterface 57 | TypeUnion 58 | TypeTypeParam 59 | ) 60 | 61 | // A CodeObj distinguishes among go/types.Object encodings. 62 | type CodeObj int 63 | 64 | func (c CodeObj) Marker() SyncMarker { return SyncCodeObj } 65 | func (c CodeObj) Value() int { return int(c) } 66 | 67 | // Note: These values are public and cannot be changed without 68 | // updating the go/types importers. 69 | 70 | const ( 71 | ObjAlias CodeObj = iota 72 | ObjConst 73 | ObjType 74 | ObjFunc 75 | ObjVar 76 | ObjStub 77 | ) 78 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package pkgbits implements low-level coding abstractions for 6 | // Unified IR's export data format. 7 | // 8 | // At a low-level, a package is a collection of bitstream elements. 9 | // Each element has a "kind" and a dense, non-negative index. 10 | // Elements can be randomly accessed given their kind and index. 11 | // 12 | // Individual elements are sequences of variable-length values (e.g., 13 | // integers, booleans, strings, go/constant values, cross-references 14 | // to other elements). Package pkgbits provides APIs for encoding and 15 | // decoding these low-level values, but the details of mapping 16 | // higher-level Go constructs into elements is left to higher-level 17 | // abstractions. 18 | // 19 | // Elements may cross-reference each other with "relocations." For 20 | // example, an element representing a pointer type has a relocation 21 | // referring to the element type. 22 | // 23 | // Go constructs may be composed as a constellation of multiple 24 | // elements. For example, a declared function may have one element to 25 | // describe the object (e.g., its name, type, position), and a 26 | // separate element to describe its function body. This allows readers 27 | // some flexibility in efficiently seeking or re-reading data (e.g., 28 | // inlining requires re-reading the function body for each inlined 29 | // call, without needing to re-read the object-level details). 30 | // 31 | // This is a copy of internal/pkgbits in the Go implementation. 32 | package pkgbits 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/flags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkgbits 6 | 7 | const ( 8 | flagSyncMarkers = 1 << iota // file format contains sync markers 9 | ) 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/frames_go1.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.7 6 | // +build !go1.7 7 | 8 | // TODO(mdempsky): Remove after #44505 is resolved 9 | 10 | package pkgbits 11 | 12 | import "runtime" 13 | 14 | func walkFrames(pcs []uintptr, visit frameVisitor) { 15 | for _, pc := range pcs { 16 | fn := runtime.FuncForPC(pc) 17 | file, line := fn.FileLine(pc) 18 | 19 | visit(file, line, fn.Name(), pc-fn.Entry()) 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/frames_go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.7 6 | // +build go1.7 7 | 8 | package pkgbits 9 | 10 | import "runtime" 11 | 12 | // walkFrames calls visit for each call frame represented by pcs. 13 | // 14 | // pcs should be a slice of PCs, as returned by runtime.Callers. 15 | func walkFrames(pcs []uintptr, visit frameVisitor) { 16 | if len(pcs) == 0 { 17 | return 18 | } 19 | 20 | frames := runtime.CallersFrames(pcs) 21 | for { 22 | frame, more := frames.Next() 23 | visit(frame.File, frame.Line, frame.Function, frame.PC-frame.Entry) 24 | if !more { 25 | return 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/reloc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkgbits 6 | 7 | // A RelocKind indicates a particular section within a unified IR export. 8 | type RelocKind int32 9 | 10 | // An Index represents a bitstream element index within a particular 11 | // section. 12 | type Index int32 13 | 14 | // A relocEnt (relocation entry) is an entry in an element's local 15 | // reference table. 16 | // 17 | // TODO(mdempsky): Rename this too. 18 | type RelocEnt struct { 19 | Kind RelocKind 20 | Idx Index 21 | } 22 | 23 | // Reserved indices within the meta relocation section. 24 | const ( 25 | PublicRootIdx Index = 0 26 | PrivateRootIdx Index = 1 27 | ) 28 | 29 | const ( 30 | RelocString RelocKind = iota 31 | RelocMeta 32 | RelocPosBase 33 | RelocPkg 34 | RelocName 35 | RelocType 36 | RelocObj 37 | RelocObjExt 38 | RelocObjDict 39 | RelocBody 40 | 41 | numRelocs = iota 42 | ) 43 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/support.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkgbits 6 | 7 | import "fmt" 8 | 9 | func assert(b bool) { 10 | if !b { 11 | panic("assertion failed") 12 | } 13 | } 14 | 15 | func errorf(format string, args ...interface{}) { 16 | panic(fmt.Errorf(format, args...)) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/pkgbits/sync.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package pkgbits 6 | 7 | import ( 8 | "fmt" 9 | "strings" 10 | ) 11 | 12 | // fmtFrames formats a backtrace for reporting reader/writer desyncs. 13 | func fmtFrames(pcs ...uintptr) []string { 14 | res := make([]string, 0, len(pcs)) 15 | walkFrames(pcs, func(file string, line int, name string, offset uintptr) { 16 | // Trim package from function name. It's just redundant noise. 17 | name = strings.TrimPrefix(name, "cmd/compile/internal/noder.") 18 | 19 | res = append(res, fmt.Sprintf("%s:%v: %s +0x%v", file, line, name, offset)) 20 | }) 21 | return res 22 | } 23 | 24 | type frameVisitor func(file string, line int, name string, offset uintptr) 25 | 26 | // SyncMarker is an enum type that represents markers that may be 27 | // written to export data to ensure the reader and writer stay 28 | // synchronized. 29 | type SyncMarker int 30 | 31 | //go:generate stringer -type=SyncMarker -trimprefix=Sync 32 | 33 | const ( 34 | _ SyncMarker = iota 35 | 36 | // Public markers (known to go/types importers). 37 | 38 | // Low-level coding markers. 39 | SyncEOF 40 | SyncBool 41 | SyncInt64 42 | SyncUint64 43 | SyncString 44 | SyncValue 45 | SyncVal 46 | SyncRelocs 47 | SyncReloc 48 | SyncUseReloc 49 | 50 | // Higher-level object and type markers. 51 | SyncPublic 52 | SyncPos 53 | SyncPosBase 54 | SyncObject 55 | SyncObject1 56 | SyncPkg 57 | SyncPkgDef 58 | SyncMethod 59 | SyncType 60 | SyncTypeIdx 61 | SyncTypeParamNames 62 | SyncSignature 63 | SyncParams 64 | SyncParam 65 | SyncCodeObj 66 | SyncSym 67 | SyncLocalIdent 68 | SyncSelector 69 | 70 | // Private markers (only known to cmd/compile). 71 | SyncPrivate 72 | 73 | SyncFuncExt 74 | SyncVarExt 75 | SyncTypeExt 76 | SyncPragma 77 | 78 | SyncExprList 79 | SyncExprs 80 | SyncExpr 81 | SyncExprType 82 | SyncAssign 83 | SyncOp 84 | SyncFuncLit 85 | SyncCompLit 86 | 87 | SyncDecl 88 | SyncFuncBody 89 | SyncOpenScope 90 | SyncCloseScope 91 | SyncCloseAnotherScope 92 | SyncDeclNames 93 | SyncDeclName 94 | 95 | SyncStmts 96 | SyncBlockStmt 97 | SyncIfStmt 98 | SyncForStmt 99 | SyncSwitchStmt 100 | SyncRangeStmt 101 | SyncCaseClause 102 | SyncCommClause 103 | SyncSelectStmt 104 | SyncDecls 105 | SyncLabeledStmt 106 | SyncUseObjLocal 107 | SyncAddLocal 108 | SyncLinkname 109 | SyncStmt1 110 | SyncStmtsEnd 111 | SyncLabel 112 | SyncOptLabel 113 | ) 114 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/robustio/gopls_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package robustio 6 | 7 | import "syscall" 8 | 9 | // The robustio package is copied from cmd/go/internal/robustio, a package used 10 | // by the go command to retry known flaky operations on certain operating systems. 11 | 12 | //go:generate go run copyfiles.go 13 | 14 | // Since the gopls module cannot access internal/syscall/windows, copy a 15 | // necessary constant. 16 | const ERROR_SHARING_VIOLATION syscall.Errno = 32 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/robustio/robustio_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package robustio 6 | 7 | import ( 8 | "errors" 9 | "syscall" 10 | ) 11 | 12 | const errFileNotFound = syscall.ENOENT 13 | 14 | // isEphemeralError returns true if err may be resolved by waiting. 15 | func isEphemeralError(err error) bool { 16 | var errno syscall.Errno 17 | if errors.As(err, &errno) { 18 | return errno == errFileNotFound 19 | } 20 | return false 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/robustio/robustio_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !windows && !darwin 6 | // +build !windows,!darwin 7 | 8 | package robustio 9 | 10 | import ( 11 | "io/ioutil" 12 | "os" 13 | ) 14 | 15 | func rename(oldpath, newpath string) error { 16 | return os.Rename(oldpath, newpath) 17 | } 18 | 19 | func readFile(filename string) ([]byte, error) { 20 | return ioutil.ReadFile(filename) 21 | } 22 | 23 | func removeAll(path string) error { 24 | return os.RemoveAll(path) 25 | } 26 | 27 | func isEphemeralError(err error) bool { 28 | return false 29 | } 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/robustio/robustio_plan9.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build plan9 6 | // +build plan9 7 | 8 | package robustio 9 | 10 | import ( 11 | "os" 12 | "syscall" 13 | "time" 14 | ) 15 | 16 | func getFileID(filename string) (FileID, time.Time, error) { 17 | fi, err := os.Stat(filename) 18 | if err != nil { 19 | return FileID{}, time.Time{}, err 20 | } 21 | dir := fi.Sys().(*syscall.Dir) 22 | return FileID{ 23 | device: uint64(dir.Type)<<32 | uint64(dir.Dev), 24 | inode: dir.Qid.Path, 25 | }, fi.ModTime(), nil 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/robustio/robustio_posix.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !windows && !plan9 6 | // +build !windows,!plan9 7 | 8 | // TODO(adonovan): use 'unix' tag when go1.19 can be assumed. 9 | 10 | package robustio 11 | 12 | import ( 13 | "os" 14 | "syscall" 15 | "time" 16 | ) 17 | 18 | func getFileID(filename string) (FileID, time.Time, error) { 19 | fi, err := os.Stat(filename) 20 | if err != nil { 21 | return FileID{}, time.Time{}, err 22 | } 23 | stat := fi.Sys().(*syscall.Stat_t) 24 | return FileID{ 25 | device: uint64(stat.Dev), // (int32 on darwin, uint64 on linux) 26 | inode: stat.Ino, 27 | }, fi.ModTime(), nil 28 | } 29 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/robustio/robustio_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package robustio 6 | 7 | import ( 8 | "errors" 9 | "syscall" 10 | "time" 11 | ) 12 | 13 | const errFileNotFound = syscall.ERROR_FILE_NOT_FOUND 14 | 15 | // isEphemeralError returns true if err may be resolved by waiting. 16 | func isEphemeralError(err error) bool { 17 | var errno syscall.Errno 18 | if errors.As(err, &errno) { 19 | switch errno { 20 | case syscall.ERROR_ACCESS_DENIED, 21 | syscall.ERROR_FILE_NOT_FOUND, 22 | ERROR_SHARING_VIOLATION: 23 | return true 24 | } 25 | } 26 | return false 27 | } 28 | 29 | // Note: it may be convenient to have this helper return fs.FileInfo, but 30 | // implementing this is actually quite involved on Windows. Since we only 31 | // currently use mtime, keep it simple. 32 | func getFileID(filename string) (FileID, time.Time, error) { 33 | filename16, err := syscall.UTF16PtrFromString(filename) 34 | if err != nil { 35 | return FileID{}, time.Time{}, err 36 | } 37 | h, err := syscall.CreateFile(filename16, 0, 0, nil, syscall.OPEN_EXISTING, uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS), 0) 38 | if err != nil { 39 | return FileID{}, time.Time{}, err 40 | } 41 | defer syscall.CloseHandle(h) 42 | var i syscall.ByHandleFileInformation 43 | if err := syscall.GetFileInformationByHandle(h, &i); err != nil { 44 | return FileID{}, time.Time{}, err 45 | } 46 | mtime := time.Unix(0, i.LastWriteTime.Nanoseconds()) 47 | return FileID{ 48 | device: uint64(i.VolumeSerialNumber), 49 | inode: uint64(i.FileIndexHigh)<<32 | uint64(i.FileIndexLow), 50 | }, mtime, nil 51 | } 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/typeparams/enabled_go117.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.18 6 | // +build !go1.18 7 | 8 | package typeparams 9 | 10 | // Enabled reports whether type parameters are enabled in the current build 11 | // environment. 12 | const Enabled = false 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/typeparams/enabled_go118.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.18 6 | // +build go1.18 7 | 8 | package typeparams 9 | 10 | // Note: this constant is in a separate file as this is the only acceptable 11 | // diff between the <1.18 API of this package and the 1.18 API. 12 | 13 | // Enabled reports whether type parameters are enabled in the current build 14 | // environment. 15 | const Enabled = true 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/typesinternal/types.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package typesinternal provides access to internal go/types APIs that are not 6 | // yet exported. 7 | package typesinternal 8 | 9 | import ( 10 | "go/token" 11 | "go/types" 12 | "reflect" 13 | "unsafe" 14 | 15 | "golang.org/x/tools/go/types/objectpath" 16 | ) 17 | 18 | func SetUsesCgo(conf *types.Config) bool { 19 | v := reflect.ValueOf(conf).Elem() 20 | 21 | f := v.FieldByName("go115UsesCgo") 22 | if !f.IsValid() { 23 | f = v.FieldByName("UsesCgo") 24 | if !f.IsValid() { 25 | return false 26 | } 27 | } 28 | 29 | addr := unsafe.Pointer(f.UnsafeAddr()) 30 | *(*bool)(addr) = true 31 | 32 | return true 33 | } 34 | 35 | // ReadGo116ErrorData extracts additional information from types.Error values 36 | // generated by Go version 1.16 and later: the error code, start position, and 37 | // end position. If all positions are valid, start <= err.Pos <= end. 38 | // 39 | // If the data could not be read, the final result parameter will be false. 40 | func ReadGo116ErrorData(err types.Error) (code ErrorCode, start, end token.Pos, ok bool) { 41 | var data [3]int 42 | // By coincidence all of these fields are ints, which simplifies things. 43 | v := reflect.ValueOf(err) 44 | for i, name := range []string{"go116code", "go116start", "go116end"} { 45 | f := v.FieldByName(name) 46 | if !f.IsValid() { 47 | return 0, 0, 0, false 48 | } 49 | data[i] = int(f.Int()) 50 | } 51 | return ErrorCode(data[0]), token.Pos(data[1]), token.Pos(data[2]), true 52 | } 53 | 54 | var SetGoVersion = func(conf *types.Config, version string) bool { return false } 55 | 56 | // NewObjectpathEncoder returns a function closure equivalent to 57 | // objectpath.For but amortized for multiple (sequential) calls. 58 | // It is a temporary workaround, pending the approval of proposal 58668. 59 | // 60 | //go:linkname NewObjectpathFunc golang.org/x/tools/go/types/objectpath.newEncoderFor 61 | func NewObjectpathFunc() func(types.Object) (objectpath.Path, error) 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/tools/internal/typesinternal/types_118.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.18 6 | // +build go1.18 7 | 8 | package typesinternal 9 | 10 | import ( 11 | "go/types" 12 | ) 13 | 14 | func init() { 15 | SetGoVersion = func(conf *types.Config, version string) bool { 16 | conf.GoVersion = version 17 | return true 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/cmd/govulncheck/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package main 6 | 7 | import ( 8 | "context" 9 | "flag" 10 | "fmt" 11 | "os" 12 | 13 | "golang.org/x/vuln/internal/scan" 14 | ) 15 | 16 | func main() { 17 | ctx := context.Background() 18 | err := scan.Command(ctx, os.Args[0], os.Args[1:]...).Run() 19 | if err != nil { 20 | switch err { 21 | case flag.ErrHelp: 22 | os.Exit(0) 23 | case scan.ErrMissingArgPatterns: 24 | os.Exit(1) 25 | case scan.ErrVulnerabilitiesFound: 26 | os.Exit(3) 27 | default: 28 | fmt.Fprintln(os.Stderr, err) 29 | os.Exit(1) 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/client/schema.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package client 6 | 7 | import ( 8 | "path" 9 | "time" 10 | ) 11 | 12 | const ( 13 | idDir = "ID" 14 | indexDir = "index" 15 | ) 16 | 17 | var ( 18 | dbEndpoint = path.Join(indexDir, "db") 19 | modulesEndpoint = path.Join(indexDir, "modules") 20 | ) 21 | 22 | func entryEndpoint(id string) string { 23 | return path.Join(idDir, id) 24 | } 25 | 26 | // dbMeta contains metadata about the database itself. 27 | type dbMeta struct { 28 | // Modified is the time the database was last modified, calculated 29 | // as the most recent time any single OSV entry was modified. 30 | Modified time.Time `json:"modified"` 31 | } 32 | 33 | // moduleMeta contains metadata about a Go module that has one 34 | // or more vulnerabilities in the database. 35 | // 36 | // Found in the "index/modules" endpoint of the vulnerability database. 37 | type moduleMeta struct { 38 | // Path is the module path. 39 | Path string `json:"path"` 40 | // Vulns is a list of vulnerabilities that affect this module. 41 | Vulns []moduleVuln `json:"vulns"` 42 | } 43 | 44 | // moduleVuln contains metadata about a vulnerability that affects 45 | // a certain module. 46 | type moduleVuln struct { 47 | // ID is a unique identifier for the vulnerability. 48 | // The Go vulnerability database issues IDs of the form 49 | // GO--. 50 | ID string `json:"id"` 51 | // Modified is the time the vuln was last modified. 52 | Modified time.Time `json:"modified"` 53 | // Fixed is the latest version that introduces a fix for the 54 | // vulnerability, in SemVer 2.0.0 format, with no leading "v" prefix. 55 | Fixed string `json:"fixed,omitempty"` 56 | } 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/derrors/derrors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package derrors defines internal error values to categorize the different 6 | // types error semantics supported by x/vuln. 7 | package derrors 8 | 9 | import ( 10 | "fmt" 11 | ) 12 | 13 | // Wrap adds context to the error and allows 14 | // unwrapping the result to recover the original error. 15 | // 16 | // Example: 17 | // 18 | // defer derrors.Wrap(&err, "copy(%s, %s)", dst, src) 19 | func Wrap(errp *error, format string, args ...interface{}) { 20 | if *errp != nil { 21 | *errp = fmt.Errorf("%s: %w", fmt.Sprintf(format, args...), *errp) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/goenv.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !testmode 6 | // +build !testmode 7 | 8 | package internal 9 | 10 | import ( 11 | "encoding/json" 12 | "os/exec" 13 | ) 14 | 15 | // GoEnv returns the value for key in `go env`. 16 | func GoEnv(key string) (string, error) { 17 | out, err := exec.Command("go", "env", "-json", key).Output() 18 | if err != nil { 19 | return "", err 20 | } 21 | env := make(map[string]string) 22 | if err := json.Unmarshal(out, &env); err != nil { 23 | return "", err 24 | } 25 | return env[key], nil 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/goenv_testmode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build testmode 6 | // +build testmode 7 | 8 | package internal 9 | 10 | import ( 11 | "encoding/json" 12 | "os" 13 | "os/exec" 14 | ) 15 | 16 | // GoEnv returns the value for key in `go env`. 17 | // 18 | // For debugging and testing purposes, the value of 19 | // undocumented environment variable TEST_GOVERSION 20 | // is used for go env GOVERSION. 21 | func GoEnv(key string) (string, error) { 22 | out, err := exec.Command("go", "env", "-json", key).Output() 23 | if err != nil { 24 | return "", err 25 | } 26 | env := make(map[string]string) 27 | if err := json.Unmarshal(out, &env); err != nil { 28 | return "", err 29 | } 30 | 31 | if v := os.Getenv("TEST_GOVERSION"); v != "" { 32 | // Unlikely to happen in practice, mostly used for testing. 33 | env["GOVERSION"] = v 34 | } 35 | 36 | return env[key], nil 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/govulncheck/handler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2023 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package govulncheck 6 | 7 | import ( 8 | "encoding/json" 9 | "io" 10 | ) 11 | 12 | // Handler handles messages to be presented in a vulnerability scan output 13 | // stream. 14 | type Handler interface { 15 | // Vulnerability adds a vulnerability to be printed to the output. 16 | Vulnerability(vuln *Vuln) error 17 | 18 | // Config communicates introductory message to the user. 19 | Config(config *Config) error 20 | 21 | // Progress is called to display a progress message. 22 | Progress(progress *Progress) error 23 | } 24 | 25 | // HandleJSON reads the json from the supplied stream and hands the decoded 26 | // output to the handler. 27 | func HandleJSON(from io.Reader, to Handler) error { 28 | dec := json.NewDecoder(from) 29 | for dec.More() { 30 | msg := Message{} 31 | // decode the next message in the stream 32 | if err := dec.Decode(&msg); err != nil { 33 | return err 34 | } 35 | // dispatch the message 36 | //TODO: should we verify only one field was set? 37 | var err error 38 | if msg.Config != nil { 39 | err = to.Config(msg.Config) 40 | } 41 | if msg.Vulnerability != nil { 42 | err = to.Vulnerability(msg.Vulnerability) 43 | } 44 | if msg.Progress != nil { 45 | err = to.Progress(msg.Progress) 46 | } 47 | if err != nil { 48 | return err 49 | } 50 | } 51 | return nil 52 | } 53 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/govulncheck/json.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package govulncheck 6 | 7 | import ( 8 | "encoding/json" 9 | 10 | "io" 11 | ) 12 | 13 | type jsonHandler struct { 14 | enc *json.Encoder 15 | } 16 | 17 | // NewJSONHandler returns a handler that writes govulncheck output as json. 18 | func NewJSONHandler(w io.Writer) Handler { 19 | enc := json.NewEncoder(w) 20 | enc.SetIndent("", " ") 21 | return &jsonHandler{enc: enc} 22 | } 23 | 24 | // Config does not do anything in JSON mode. 25 | func (h *jsonHandler) Config(config *Config) error { 26 | return h.enc.Encode(Message{Config: config}) 27 | } 28 | 29 | // Progress does not do anything in JSON mode. 30 | func (h *jsonHandler) Progress(progress *Progress) error { 31 | return h.enc.Encode(Message{Progress: progress}) 32 | } 33 | 34 | // Vulnerability gathers vulnerabilities to be written. 35 | func (h *jsonHandler) Vulnerability(vuln *Vuln) error { 36 | return h.enc.Encode(Message{Vulnerability: vuln}) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/internal.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package internal contains functionality for x/vuln. 6 | package internal 7 | 8 | // IDDirectory is the name of the directory that contains entries 9 | // listed by their IDs. 10 | const IDDirectory = "ID" 11 | 12 | // Pseudo-module paths used for parts of the Go system. 13 | // These are technically not valid module paths, so we 14 | // mustn't pass them to module.EscapePath. 15 | // Keep in sync with vulndb/internal/database/generate.go. 16 | const ( 17 | // GoStdModulePath is the internal Go module path string used 18 | // when listing vulnerabilities in standard library. 19 | GoStdModulePath = "stdlib" 20 | 21 | // GoCmdModulePath is the internal Go module path string used 22 | // when listing vulnerabilities in the go command. 23 | GoCmdModulePath = "toolchain" 24 | ) 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/binary.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.18 6 | // +build go1.18 7 | 8 | package scan 9 | 10 | import ( 11 | "context" 12 | "os" 13 | 14 | "golang.org/x/vuln/internal/govulncheck" 15 | "golang.org/x/vuln/internal/vulncheck" 16 | ) 17 | 18 | // runBinary detects presence of vulnerable symbols in an executable. 19 | func runBinary(ctx context.Context, handler govulncheck.Handler, cfg *config) ([]*govulncheck.Vuln, error) { 20 | var exe *os.File 21 | exe, err := os.Open(cfg.patterns[0]) 22 | if err != nil { 23 | return nil, err 24 | } 25 | defer exe.Close() 26 | 27 | p := &govulncheck.Progress{Message: binaryProgressMessage} 28 | if err := handler.Progress(p); err != nil { 29 | return nil, err 30 | } 31 | vr, err := binary(ctx, exe, &cfg.Config) 32 | if err != nil { 33 | return nil, err 34 | } 35 | return createBinaryResult(vr), nil 36 | } 37 | 38 | func createBinaryResult(vr *vulncheck.Result) []*govulncheck.Vuln { 39 | modVersions := moduleVersionMap(vr.Modules) 40 | // Create Result where each vulncheck.Vuln{OSV, ModPath, PkgPath} becomes 41 | // a separate Vuln{OSV, Modules{Packages{PkgPath}}} entry. We merge the 42 | // results later. 43 | var vulns []*govulncheck.Vuln 44 | for _, vv := range vr.Vulns { 45 | p := &govulncheck.Package{Path: vv.PkgPath} 46 | // in binary mode, call stacks contain just the symbol data 47 | p.CallStacks = []govulncheck.CallStack{{Symbol: vv.Symbol}} 48 | m := &govulncheck.Module{ 49 | Path: vv.ModPath, 50 | FoundVersion: foundVersion(vv.ModPath, modVersions), 51 | FixedVersion: fixedVersion(vv.ModPath, vv.OSV.Affected), 52 | Packages: []*govulncheck.Package{p}, 53 | } 54 | 55 | v := &govulncheck.Vuln{OSV: vv.OSV, Modules: []*govulncheck.Module{m}} 56 | vulns = append(vulns, v) 57 | } 58 | 59 | vulns = merge(vulns) 60 | sortResult(vulns) 61 | return vulns 62 | } 63 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/binary_118.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build go1.18 6 | // +build go1.18 7 | 8 | package scan 9 | 10 | import ( 11 | "context" 12 | "io" 13 | 14 | "golang.org/x/vuln/internal/vulncheck" 15 | ) 16 | 17 | func binary(ctx context.Context, exe io.ReaderAt, cfg *vulncheck.Config) (_ *vulncheck.Result, err error) { 18 | return vulncheck.Binary(ctx, exe, cfg) 19 | } 20 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/binary_not118.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.18 6 | // +build !go1.18 7 | 8 | package scan 9 | 10 | import ( 11 | "context" 12 | "errors" 13 | "io" 14 | 15 | "golang.org/x/vuln/internal/vulncheck" 16 | ) 17 | 18 | func binary(ctx context.Context, exe io.ReaderAt, cfg *vulncheck.Config) (_ *vulncheck.Result, err error) { 19 | return nil, errors.New("compile with Go 1.18 or higher to analyze binary files") 20 | } 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/errors.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scan 6 | 7 | import ( 8 | "errors" 9 | "fmt" 10 | "os" 11 | "strings" 12 | 13 | "golang.org/x/tools/go/packages" 14 | ) 15 | 16 | var ( 17 | ErrMissingArgPatterns = errors.New("missing any pattern args") 18 | ErrInvalidArg = errors.New("invalid arg") 19 | ErrVulnerabilitiesFound = errors.New("vulnerabilities found") 20 | ) 21 | 22 | //lint:file-ignore ST1005 Ignore staticcheck message about error formatting 23 | var ( 24 | // errGoVersionMismatch is used to indicate that there is a mismatch between 25 | // the Go version used to build govulncheck and the one currently on PATH. 26 | errGoVersionMismatch = errors.New(`Loading packages failed, possibly due to a mismatch between the Go version 27 | used to build govulncheck and the Go version on PATH. Consider rebuilding 28 | govulncheck with the current Go version.`) 29 | 30 | // errNoGoSum indicates that a go.mod file was not found in this module. 31 | errNoGoMod = errors.New(`no go.mod file 32 | 33 | govulncheck only works Go with modules. Try navigating to your module directory. 34 | Otherwise, run go mod init to make your project a module. 35 | 36 | See https://go.dev/doc/modules/managing-dependencies for more information.`) 37 | ) 38 | 39 | // packageError contains errors from loading a set of packages. 40 | type packageError struct { 41 | Errors []packages.Error 42 | } 43 | 44 | func (e *packageError) Error() string { 45 | var b strings.Builder 46 | fmt.Fprintln(&b, "Packages contain errors:") 47 | for _, e := range e.Errors { 48 | fmt.Fprintln(&b, e) 49 | } 50 | return b.String() 51 | } 52 | 53 | // fileExists checks if file path exists. Returns true 54 | // if the file exists or it cannot prove that it does 55 | // not exist. Otherwise, returns false. 56 | func fileExists(path string) bool { 57 | if _, err := os.Stat(path); err == nil { 58 | return true 59 | } else if errors.Is(err, os.ErrNotExist) { 60 | return false 61 | } 62 | // Conservatively return true if os.Stat fails 63 | // for some other reason. 64 | return true 65 | } 66 | 67 | // isGoVersionMismatchError checks if err is due to mismatch between 68 | // the Go version used to build govulncheck and the one currently 69 | // on PATH. 70 | func isGoVersionMismatchError(err error) bool { 71 | msg := err.Error() 72 | // See golang.org/x/tools/go/packages/packages.go. 73 | return strings.Contains(msg, "This application uses version go") && 74 | strings.Contains(msg, "It may fail to process source files") 75 | } 76 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/filepath.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scan 6 | 7 | import ( 8 | "path/filepath" 9 | "strings" 10 | ) 11 | 12 | // AbsRelShorter takes path and returns its path relative 13 | // to the current directory, if shorter. Returns path 14 | // when path is an empty string or upon any error. 15 | func AbsRelShorter(path string) string { 16 | if path == "" { 17 | return "" 18 | } 19 | 20 | c, err := filepath.Abs(".") 21 | if err != nil { 22 | return path 23 | } 24 | r, err := filepath.Rel(c, path) 25 | if err != nil { 26 | return path 27 | } 28 | 29 | rSegments := strings.Split(r, string(filepath.Separator)) 30 | pathSegments := strings.Split(path, string(filepath.Separator)) 31 | if len(rSegments) < len(pathSegments) { 32 | return r 33 | } 34 | return path 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/flag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !testmode 6 | // +build !testmode 7 | 8 | package scan 9 | 10 | import ( 11 | "flag" 12 | ) 13 | 14 | func addTestFlags(flags *flag.FlagSet, cfg *config) { 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/flag_testmode.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build testmode 6 | // +build testmode 7 | 8 | package scan 9 | 10 | import ( 11 | "flag" 12 | ) 13 | 14 | func addTestFlags(flags *flag.FlagSet, cfg *config) { 15 | flags.StringVar(&cfg.dir, "dir", "", "directory to use for loading source files") 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/flags.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scan 6 | 7 | import ( 8 | "flag" 9 | "fmt" 10 | "os" 11 | 12 | "golang.org/x/tools/go/buildutil" 13 | "golang.org/x/vuln/internal/vulncheck" 14 | ) 15 | 16 | type config struct { 17 | vulncheck.Config 18 | patterns []string 19 | mode string 20 | db string 21 | json bool 22 | dir string 23 | verbose bool 24 | tags []string 25 | test bool 26 | } 27 | 28 | const ( 29 | modeSource = "source" 30 | modeBinary = "binary" 31 | ) 32 | 33 | var supportedModes = map[string]bool{ 34 | modeSource: true, 35 | modeBinary: true, 36 | } 37 | 38 | func (c *Cmd) parseFlags() (*config, error) { 39 | cfg := &config{} 40 | var ( 41 | tagsFlag buildutil.TagsFlag 42 | mode string 43 | ) 44 | flags := flag.NewFlagSet("", flag.ContinueOnError) 45 | flags.BoolVar(&cfg.json, "json", false, "output JSON") 46 | flags.BoolVar(&cfg.verbose, "v", false, "print a full call stack for each vulnerability") 47 | flags.BoolVar(&cfg.test, "test", false, "analyze test files (only valid for source mode)") 48 | flags.StringVar(&cfg.db, "db", "https://vuln.go.dev", "vulnerability database URL") 49 | flags.StringVar(&mode, "mode", modeSource, "supports source or binary") 50 | flags.Var(&tagsFlag, "tags", "comma-separated `list` of build tags") 51 | flags.Usage = func() { 52 | fmt.Fprint(flags.Output(), `Govulncheck is a tool for finding known vulnerabilities. 53 | 54 | Usage: 55 | 56 | govulncheck [flags] [patterns] 57 | govulncheck -mode=binary [flags] [binary] 58 | 59 | `) 60 | flags.PrintDefaults() 61 | fmt.Fprintf(flags.Output(), "\n%s\n", detailsMessage) 62 | } 63 | addTestFlags(flags, cfg) 64 | if err := flags.Parse(c.Args[1:]); err != nil { 65 | return nil, err 66 | } 67 | cfg.patterns = flags.Args() 68 | if len(cfg.patterns) == 0 { 69 | flags.Usage() 70 | return nil, ErrMissingArgPatterns 71 | } 72 | if _, ok := supportedModes[mode]; !ok { 73 | return nil, ErrInvalidArg 74 | } 75 | cfg.mode = mode 76 | 77 | if cfg.mode == modeBinary { 78 | if len(cfg.patterns) != 1 { 79 | return nil, ErrInvalidArg 80 | } 81 | if !isFile(cfg.patterns[0]) { 82 | return nil, fmt.Errorf("%q is not a file", cfg.patterns[0]) 83 | } 84 | } 85 | cfg.tags = tagsFlag 86 | return cfg, nil 87 | } 88 | 89 | func isFile(path string) bool { 90 | s, err := os.Stat(path) 91 | if err != nil { 92 | return false 93 | } 94 | return !s.IsDir() 95 | } 96 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/result.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package govulncheck provides functionality to support the govulncheck command. 6 | package scan 7 | 8 | import ( 9 | "fmt" 10 | "strings" 11 | 12 | "golang.org/x/tools/go/packages" 13 | "golang.org/x/vuln/internal/govulncheck" 14 | ) 15 | 16 | // LoadMode is the level of information needed for each package 17 | // for running golang.org/x/tools/go/packages.Load. 18 | var LoadMode = packages.NeedName | packages.NeedImports | packages.NeedTypes | 19 | packages.NeedSyntax | packages.NeedTypesInfo | packages.NeedDeps | 20 | packages.NeedModule 21 | 22 | // IsCalled reports whether the vulnerability is called, therefore 23 | // affecting the target source code or binary. 24 | func IsCalled(v *govulncheck.Vuln) bool { 25 | for _, m := range v.Modules { 26 | for _, p := range m.Packages { 27 | if len(p.CallStacks) > 0 { 28 | return true 29 | } 30 | } 31 | } 32 | return false 33 | } 34 | 35 | // FuncName returns the full qualified function name from a stack frame, 36 | // adjusted to remove pointer annotations. 37 | func FuncName(frame *govulncheck.StackFrame) string { 38 | switch { 39 | case frame.Receiver != "": 40 | return fmt.Sprintf("%s.%s", strings.TrimPrefix(frame.Receiver, "*"), frame.Function) 41 | case frame.Package != "": 42 | return fmt.Sprintf("%s.%s", frame.Package, frame.Function) 43 | default: 44 | return frame.Function 45 | } 46 | } 47 | 48 | // Pos returns the position of the call in sf as string. 49 | // If position is not available, return "". 50 | func Pos(sf *govulncheck.StackFrame) string { 51 | if sf.Position.IsValid() { 52 | return sf.Position.String() 53 | } 54 | return "" 55 | } 56 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/stdlib.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package scan 6 | 7 | import ( 8 | "fmt" 9 | "strings" 10 | 11 | "golang.org/x/mod/semver" 12 | ) 13 | 14 | // Support functions for standard library packages. 15 | // These are copied from the internal/stdlib package in the pkgsite repo. 16 | 17 | // semverToGoTag returns the Go standard library repository tag corresponding 18 | // to semver, a version string without the initial "v". 19 | // Go tags differ from standard semantic versions in a few ways, 20 | // such as beginning with "go" instead of "v". 21 | func semverToGoTag(v string) string { 22 | if strings.HasPrefix(v, "v0.0.0") { 23 | return "master" 24 | } 25 | // Special case: v1.0.0 => go1. 26 | if v == "v1.0.0" { 27 | return "go1" 28 | } 29 | if !semver.IsValid(v) { 30 | return fmt.Sprintf("", v) 31 | } 32 | goVersion := semver.Canonical(v) 33 | prerelease := semver.Prerelease(goVersion) 34 | versionWithoutPrerelease := strings.TrimSuffix(goVersion, prerelease) 35 | patch := strings.TrimPrefix(versionWithoutPrerelease, semver.MajorMinor(goVersion)+".") 36 | if patch == "0" { 37 | versionWithoutPrerelease = strings.TrimSuffix(versionWithoutPrerelease, ".0") 38 | } 39 | goVersion = fmt.Sprintf("go%s", strings.TrimPrefix(versionWithoutPrerelease, "v")) 40 | if prerelease != "" { 41 | // Go prereleases look like "beta1" instead of "beta.1". 42 | // "beta1" is bad for sorting (since beta10 comes before beta9), so 43 | // require the dot form. 44 | i := finalDigitsIndex(prerelease) 45 | if i >= 1 { 46 | if prerelease[i-1] != '.' { 47 | return fmt.Sprintf("", v) 48 | } 49 | // Remove the dot. 50 | prerelease = prerelease[:i-1] + prerelease[i:] 51 | } 52 | goVersion += strings.TrimPrefix(prerelease, "-") 53 | } 54 | return goVersion 55 | } 56 | 57 | // finalDigitsIndex returns the index of the first digit in the sequence of digits ending s. 58 | // If s doesn't end in digits, it returns -1. 59 | func finalDigitsIndex(s string) int { 60 | // Assume ASCII (since the semver package does anyway). 61 | var i int 62 | for i = len(s) - 1; i >= 0; i-- { 63 | if s[i] < '0' || s[i] > '9' { 64 | break 65 | } 66 | } 67 | if i == len(s)-1 { 68 | return -1 69 | } 70 | return i + 1 71 | } 72 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/template/config.tmpl: -------------------------------------------------------------------------------- 1 | {{- /* 2 | This template is a text template used to communicate to the 3 | user the environment used for vulnerability analysis, namely 4 | the Go version, govulncheck version, vuln dbs with their last 5 | modified timestamp. 6 | */ -}} 7 | govulncheck is an experimental tool. Share feedback at https://go.dev/s/govulncheck-feedback. 8 | 9 | Using {{template "Go" .}}{{template "Version" .}}with 10 | vulnerability data from {{.DataSource}}{{template "LastModified" .}}. 11 | {{/* This is the end of the main template */ -}} 12 | 13 | {{- define "Go" -}} 14 | {{if .GoVersion}}{{.GoVersion}} and {{end}} 15 | {{- end -}} 16 | 17 | {{- define "Version" -}} 18 | {{if .Version}}{{.Version}} {{else}}govulncheck {{end}} 19 | {{- end -}} 20 | 21 | {{- define "LastModified" -}} 22 | {{if .LastModified}} (last modified {{.LastModified}}){{end}} 23 | {{- end -}} 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/scan/template/output.tmpl: -------------------------------------------------------------------------------- 1 | {{- /* 2 | This template is a text template used to print out vulncheck output. 3 | It consists of three sections showing: 4 | 1) The number of vulnerabilities detected. 5 | 2) Callstacks detected for each pair of module and vulnerability. 6 | 3) Vulnerabilities that are only imported but not called. 7 | */ -}} 8 | {{- template "VulnCount" . -}} 9 | {{- template "Affected" . -}} 10 | {{- template "Informational" . -}} 11 | {{/* This is the end of the main template */ -}} 12 | 13 | {{- define "VulnCount" -}} 14 | {{if eq (len .Affected) 0 -}} 15 | No vulnerabilities found. 16 | {{else -}} 17 | Your code is affected by {{len .Affected}} {{pluralize (len .Affected) "vulnerability"}} from 18 | {{- if .AffectedModules}} {{.AffectedModules}} {{pluralize .AffectedModules "module"}}{{end}} 19 | {{- if .StdlibAffected}}{{if .AffectedModules}} and{{end}} the Go standard library{{end}}. 20 | {{end}} 21 | {{- end -}} 22 | 23 | {{- define "Affected" -}} 24 | {{- if .Affected -}} 25 | {{- $idx := 0 -}} 26 | {{- range $vulnInfo := .Affected -}} 27 | {{- $idx = inc $idx}} 28 | Vulnerability #{{$idx}}: {{$vulnInfo.ID}} 29 | {{wrap $vulnInfo.Details | indent 2}} 30 | 31 | More info: https://pkg.go.dev/vuln/{{$vulnInfo.ID}} 32 | {{range $modInfo := $vulnInfo.Modules}} 33 | {{- if $modInfo.IsStd}} 34 | Standard library 35 | {{- else}} 36 | Module: {{$modInfo.Module}} 37 | {{- end}} 38 | Found in: {{$modInfo.Found}} 39 | Fixed in: {{if $modInfo.Fixed}}{{$modInfo.Fixed}}{{else}}N/A{{end}} 40 | {{- if $modInfo.Platforms}} 41 | Platforms: {{commaseparate $modInfo.Platforms}} 42 | {{- end}} 43 | {{if $modInfo.Stacks}} 44 | Call stacks in your code: 45 | {{indent 6 $modInfo.Stacks}}{{end}} 46 | {{- end -}} 47 | {{- end -}} 48 | {{- end -}} 49 | {{- end -}} 50 | 51 | {{- define "Informational" -}} 52 | {{if .Unaffected}} 53 | === Informational === 54 | 55 | Found {{len .Unaffected}} {{pluralize (len .Unaffected) "vulnerability"}} in packages that you import, but there are no call 56 | stacks leading to the use of {{if eq (len .Unaffected) 1}}this vulnerability{{else}}these vulnerabilities{{end}}. You may not need to 57 | take any action. See https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck 58 | for details. 59 | {{$idx := 0}}{{range $vulnInfo := .Unaffected}} 60 | {{- $idx = inc $idx}} 61 | Vulnerability #{{$idx}}: {{$vulnInfo.ID}}{{$modInfo:= index $vulnInfo.Modules 0}} 62 | {{wrap $vulnInfo.Details | indent 2}} 63 | More info: https://pkg.go.dev/vuln/{{$vulnInfo.ID}} 64 | Found in: {{$modInfo.Found}} 65 | Fixed in: {{if $modInfo.Fixed}}{{$modInfo.Fixed}}{{else}}N/A{{end}} 66 | {{- if $modInfo.Platforms}} 67 | Platforms: {{commaseparate $modInfo.Platforms}}{{end}} 68 | {{end}} 69 | {{- end -}} 70 | {{- end -}} 71 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/semver/semver.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package semver provides shared utilities for manipulating 6 | // Go semantic versions. 7 | package semver 8 | 9 | import ( 10 | "regexp" 11 | "strings" 12 | ) 13 | 14 | // addSemverPrefix adds a 'v' prefix to s if it isn't already prefixed 15 | // with 'v' or 'go'. This allows us to easily test go-style SEMVER 16 | // strings against normal SEMVER strings. 17 | func addSemverPrefix(s string) string { 18 | if !strings.HasPrefix(s, "v") && !strings.HasPrefix(s, "go") { 19 | return "v" + s 20 | } 21 | return s 22 | } 23 | 24 | // removeSemverPrefix removes the 'v' or 'go' prefixes from go-style 25 | // SEMVER strings, for usage in the public vulnerability format. 26 | func removeSemverPrefix(s string) string { 27 | s = strings.TrimPrefix(s, "v") 28 | s = strings.TrimPrefix(s, "go") 29 | return s 30 | } 31 | 32 | // CanonicalizeSemverPrefix turns a SEMVER string into the canonical 33 | // representation using the 'v' prefix, as used by the OSV format. 34 | // Input may be a bare SEMVER ("1.2.3"), Go prefixed SEMVER ("go1.2.3"), 35 | // or already canonical SEMVER ("v1.2.3"). 36 | func CanonicalizeSemverPrefix(s string) string { 37 | return addSemverPrefix(removeSemverPrefix(s)) 38 | } 39 | 40 | var ( 41 | // Regexp for matching go tags. The groups are: 42 | // 1 the major.minor version 43 | // 2 the patch version, or empty if none 44 | // 3 the entire prerelease, if present 45 | // 4 the prerelease type ("beta" or "rc") 46 | // 5 the prerelease number 47 | tagRegexp = regexp.MustCompile(`^go(\d+\.\d+)(\.\d+|)((beta|rc|-pre)(\d+))?$`) 48 | ) 49 | 50 | // This is a modified copy of pkgsite/internal/stdlib:VersionForTag. 51 | func GoTagToSemver(tag string) string { 52 | if tag == "" { 53 | return "" 54 | } 55 | 56 | tag = strings.Fields(tag)[0] 57 | // Special cases for go1. 58 | if tag == "go1" { 59 | return "v1.0.0" 60 | } 61 | if tag == "go1.0" { 62 | return "" 63 | } 64 | m := tagRegexp.FindStringSubmatch(tag) 65 | if m == nil { 66 | return "" 67 | } 68 | version := "v" + m[1] 69 | if m[2] != "" { 70 | version += m[2] 71 | } else { 72 | version += ".0" 73 | } 74 | if m[3] != "" { 75 | if !strings.HasPrefix(m[4], "-") { 76 | version += "-" 77 | } 78 | version += m[4] + "." + m[5] 79 | } 80 | return version 81 | } 82 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/vulncheck/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package vulncheck detects uses of known vulnerabilities 7 | in Go programs. 8 | 9 | Vulncheck identifies vulnerability uses in Go programs 10 | at the level of call graph, package import graph, and module 11 | requires graph. For instance, vulncheck identifies which 12 | vulnerable functions and methods are transitively called 13 | from the program entry points. vulncheck also detects 14 | transitively imported packages and required modules that 15 | contain known vulnerable functions and methods. 16 | 17 | We recommend using the command line tool [govulncheck] to 18 | detect vulnerabilities in your code. 19 | 20 | # Usage 21 | 22 | The two main APIs of vulncheck, [Source] and [Binary], allow vulnerability 23 | detection in Go source code and binaries, respectively. 24 | 25 | [Source] accepts a list of [Package] objects, which 26 | are a trimmed version of [golang.org/x/tools/go/packages.Package] objects to 27 | reduce memory consumption. [Binary] accepts a path to a Go binary file that 28 | must have been compiled with Go 1.18 or greater. 29 | 30 | Both [Source] and [Binary] require information about known 31 | vulnerabilities in the form of a vulnerability database, 32 | specifically a [golang.org/x/vuln/internal/client.Client]. 33 | The vulnerabilities 34 | are modeled using the [golang.org/x/vuln/internal/osv] format. 35 | 36 | # Results 37 | 38 | The results of vulncheck are slices of the call graph, package imports graph, 39 | and module requires graph leading to the use of an identified vulnerability. 40 | The parts of these graphs not related to any vulnerabilities are omitted. 41 | 42 | The [CallStacks] and [ImportChains] functions search the returned slices for 43 | user-friendly representative call stacks and import chains. These call stacks 44 | and import chains are provided as examples of vulnerability uses in the client 45 | code. 46 | 47 | # Limitations 48 | 49 | There are some limitations with vulncheck. Please see the 50 | [documented limitations] for more information. 51 | 52 | [govulncheck]: https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck 53 | [documented limitations]: https://go.dev/security/vulncheck#limitations. 54 | */ 55 | package vulncheck 56 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/vulncheck/entries.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package vulncheck 6 | 7 | import ( 8 | "strings" 9 | 10 | "golang.org/x/tools/go/ssa" 11 | ) 12 | 13 | func entryPoints(topPackages []*ssa.Package) []*ssa.Function { 14 | var entries []*ssa.Function 15 | for _, pkg := range topPackages { 16 | if pkg.Pkg.Name() == "main" { 17 | // for "main" packages the only valid entry points are the "main" 18 | // function and any "init#" functions, even if there are other 19 | // exported functions or types. similarly to isEntry it should be 20 | // safe to ignore the validity of the main or init# signatures, 21 | // since the compiler will reject malformed definitions, 22 | // and the init function is synthetic 23 | entries = append(entries, memberFuncs(pkg.Members["main"], pkg.Prog)...) 24 | for name, member := range pkg.Members { 25 | if strings.HasPrefix(name, "init#") || name == "init" { 26 | entries = append(entries, memberFuncs(member, pkg.Prog)...) 27 | } 28 | } 29 | continue 30 | } 31 | for _, member := range pkg.Members { 32 | for _, f := range memberFuncs(member, pkg.Prog) { 33 | if isEntry(f) { 34 | entries = append(entries, f) 35 | } 36 | } 37 | } 38 | } 39 | return entries 40 | } 41 | 42 | func isEntry(f *ssa.Function) bool { 43 | // it should be safe to ignore checking that the signature of the "init" function 44 | // is valid, since it is synthetic 45 | if f.Name() == "init" && f.Synthetic == "package initializer" { 46 | return true 47 | } 48 | 49 | return f.Synthetic == "" && f.Object() != nil && f.Object().Exported() 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/vulncheck/fetch.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package vulncheck 6 | 7 | import ( 8 | "context" 9 | 10 | "golang.org/x/vuln/internal/client" 11 | ) 12 | 13 | // FetchVulnerabilities fetches vulnerabilities that affect the supplied modules. 14 | func FetchVulnerabilities(ctx context.Context, client client.Client, modules []*Module) ([]*ModVulns, error) { 15 | var mv []*ModVulns 16 | for _, mod := range modules { 17 | modPath := mod.Path 18 | if mod.Replace != nil { 19 | modPath = mod.Replace.Path 20 | } 21 | vulns, err := client.ByModule(ctx, modPath) 22 | if err != nil { 23 | return nil, err 24 | } 25 | if len(vulns) == 0 { 26 | continue 27 | } 28 | mv = append(mv, &ModVulns{ 29 | Module: mod, 30 | Vulns: vulns, 31 | }) 32 | } 33 | return mv, nil 34 | } 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/vulncheck/internal/buildinfo/README.md: -------------------------------------------------------------------------------- 1 | This code is a copied and slightly modified subset of go/src/debug/buildinfo. 2 | 3 | It contains logic for parsing Go binary files for the purpose of extracting 4 | module dependency and symbol table information. 5 | 6 | Logic added by vulncheck is located in files with "additions_" prefix. 7 | 8 | Within the originally named files, changed or added logic is annotated with 9 | a comment starting with "Addition:". 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/vulncheck/internal/gosym/README.md: -------------------------------------------------------------------------------- 1 | This code is a copied and slightly modified version of go/src/debug/gosym. 2 | 3 | The original code contains logic for accessing symbol tables and line numbers 4 | in Go binaries. The only reason why this is copied is to support inlining. 5 | 6 | Code added by vulncheck is located in files with "additions_" prefix and it 7 | contains logic for accessing inlining information. 8 | 9 | Within the originally named files, deleted or added logic is annotated with 10 | a comment starting with "Addition:". The modified logic allows the inlining 11 | code in "additions_*" files to access the necessary information. 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/vuln/internal/vulncheck/slicing.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package vulncheck 6 | 7 | import ( 8 | "golang.org/x/tools/go/callgraph" 9 | "golang.org/x/tools/go/ssa" 10 | ) 11 | 12 | // forwardSlice computes the transitive closure of functions forward reachable 13 | // via calls in cg or referred to in an instruction starting from `sources`. 14 | func forwardSlice(sources map[*ssa.Function]bool, cg *callgraph.Graph) map[*ssa.Function]bool { 15 | seen := make(map[*ssa.Function]bool) 16 | var visit func(f *ssa.Function) 17 | visit = func(f *ssa.Function) { 18 | if seen[f] { 19 | return 20 | } 21 | seen[f] = true 22 | 23 | if n := cg.Nodes[f]; n != nil { 24 | for _, e := range n.Out { 25 | if e.Site != nil { 26 | visit(e.Callee.Func) 27 | } 28 | } 29 | } 30 | 31 | var buf [10]*ssa.Value // avoid alloc in common case 32 | for _, b := range f.Blocks { 33 | for _, instr := range b.Instrs { 34 | for _, op := range instr.Operands(buf[:0]) { 35 | if fn, ok := (*op).(*ssa.Function); ok { 36 | visit(fn) 37 | } 38 | } 39 | } 40 | } 41 | } 42 | for source := range sources { 43 | visit(source) 44 | } 45 | return seen 46 | } 47 | 48 | // pruneSet removes functions in `set` that are in `toPrune`. 49 | func pruneSet(set, toPrune map[*ssa.Function]bool) { 50 | for f := range set { 51 | if !toPrune[f] { 52 | delete(set, f) 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Dominik Honnef 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/analysis/code/visit.go: -------------------------------------------------------------------------------- 1 | package code 2 | 3 | import ( 4 | "bytes" 5 | "go/ast" 6 | "go/format" 7 | 8 | "honnef.co/go/tools/pattern" 9 | 10 | "golang.org/x/tools/go/analysis" 11 | "golang.org/x/tools/go/analysis/passes/inspect" 12 | "golang.org/x/tools/go/ast/inspector" 13 | ) 14 | 15 | func Preorder(pass *analysis.Pass, fn func(ast.Node), types ...ast.Node) { 16 | pass.ResultOf[inspect.Analyzer].(*inspector.Inspector).Preorder(types, fn) 17 | } 18 | 19 | func PreorderStack(pass *analysis.Pass, fn func(ast.Node, []ast.Node), types ...ast.Node) { 20 | pass.ResultOf[inspect.Analyzer].(*inspector.Inspector).WithStack(types, func(n ast.Node, push bool, stack []ast.Node) (proceed bool) { 21 | if push { 22 | fn(n, stack) 23 | } 24 | return true 25 | }) 26 | } 27 | 28 | func Match(pass *analysis.Pass, q pattern.Pattern, node ast.Node) (*pattern.Matcher, bool) { 29 | // Note that we ignore q.Relevant – callers of Match usually use 30 | // AST inspectors that already filter on nodes we're interested 31 | // in. 32 | m := &pattern.Matcher{TypesInfo: pass.TypesInfo} 33 | ok := m.Match(q, node) 34 | return m, ok 35 | } 36 | 37 | func MatchAndEdit(pass *analysis.Pass, before, after pattern.Pattern, node ast.Node) (*pattern.Matcher, []analysis.TextEdit, bool) { 38 | m, ok := Match(pass, before, node) 39 | if !ok { 40 | return m, nil, false 41 | } 42 | r := pattern.NodeToAST(after.Root, m.State) 43 | buf := &bytes.Buffer{} 44 | format.Node(buf, pass.Fset, r) 45 | edit := []analysis.TextEdit{{ 46 | Pos: node.Pos(), 47 | End: node.End(), 48 | NewText: buf.Bytes(), 49 | }} 50 | return m, edit, true 51 | } 52 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/analysis/edit/edit.go: -------------------------------------------------------------------------------- 1 | // Package edit contains helpers for creating suggested fixes. 2 | package edit 3 | 4 | import ( 5 | "bytes" 6 | "go/ast" 7 | "go/format" 8 | "go/token" 9 | 10 | "golang.org/x/tools/go/analysis" 11 | "honnef.co/go/tools/pattern" 12 | ) 13 | 14 | // Ranger describes values that have a start and end position. 15 | // In most cases these are either ast.Node or manually constructed ranges. 16 | type Ranger interface { 17 | Pos() token.Pos 18 | End() token.Pos 19 | } 20 | 21 | // Range implements the Ranger interface. 22 | type Range [2]token.Pos 23 | 24 | func (r Range) Pos() token.Pos { return r[0] } 25 | func (r Range) End() token.Pos { return r[1] } 26 | 27 | // ReplaceWithString replaces a range with a string. 28 | func ReplaceWithString(old Ranger, new string) analysis.TextEdit { 29 | return analysis.TextEdit{ 30 | Pos: old.Pos(), 31 | End: old.End(), 32 | NewText: []byte(new), 33 | } 34 | } 35 | 36 | // ReplaceWithNode replaces a range with an AST node. 37 | func ReplaceWithNode(fset *token.FileSet, old Ranger, new ast.Node) analysis.TextEdit { 38 | buf := &bytes.Buffer{} 39 | if err := format.Node(buf, fset, new); err != nil { 40 | panic("internal error: " + err.Error()) 41 | } 42 | return analysis.TextEdit{ 43 | Pos: old.Pos(), 44 | End: old.End(), 45 | NewText: buf.Bytes(), 46 | } 47 | } 48 | 49 | // ReplaceWithPattern replaces a range with the result of executing a pattern. 50 | func ReplaceWithPattern(fset *token.FileSet, old Ranger, new pattern.Pattern, state pattern.State) analysis.TextEdit { 51 | r := pattern.NodeToAST(new.Root, state) 52 | buf := &bytes.Buffer{} 53 | format.Node(buf, fset, r) 54 | return analysis.TextEdit{ 55 | Pos: old.Pos(), 56 | End: old.End(), 57 | NewText: buf.Bytes(), 58 | } 59 | } 60 | 61 | // Delete deletes a range of code. 62 | func Delete(old Ranger) analysis.TextEdit { 63 | return analysis.TextEdit{ 64 | Pos: old.Pos(), 65 | End: old.End(), 66 | NewText: nil, 67 | } 68 | } 69 | 70 | func Fix(msg string, edits ...analysis.TextEdit) analysis.SuggestedFix { 71 | return analysis.SuggestedFix{ 72 | Message: msg, 73 | TextEdits: edits, 74 | } 75 | } 76 | 77 | // Selector creates a new selector expression. 78 | func Selector(x, sel string) *ast.SelectorExpr { 79 | return &ast.SelectorExpr{ 80 | X: &ast.Ident{Name: x}, 81 | Sel: &ast.Ident{Name: sel}, 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/analysis/facts/directives/directives.go: -------------------------------------------------------------------------------- 1 | package directives 2 | 3 | import ( 4 | "reflect" 5 | 6 | "golang.org/x/tools/go/analysis" 7 | "honnef.co/go/tools/analysis/lint" 8 | ) 9 | 10 | func directives(pass *analysis.Pass) (interface{}, error) { 11 | return lint.ParseDirectives(pass.Files, pass.Fset), nil 12 | } 13 | 14 | var Analyzer = &analysis.Analyzer{ 15 | Name: "directives", 16 | Doc: "extracts linter directives", 17 | Run: directives, 18 | RunDespiteErrors: true, 19 | ResultType: reflect.TypeOf([]lint.Directive{}), 20 | } 21 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/analysis/facts/generated/generated.go: -------------------------------------------------------------------------------- 1 | package generated 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "io" 7 | "os" 8 | "reflect" 9 | "strings" 10 | 11 | "golang.org/x/tools/go/analysis" 12 | ) 13 | 14 | type Generator int 15 | 16 | // A list of known generators we can detect 17 | const ( 18 | Unknown Generator = iota 19 | Goyacc 20 | Cgo 21 | Stringer 22 | ProtocGenGo 23 | ) 24 | 25 | var ( 26 | // used by cgo before Go 1.11 27 | oldCgo = []byte("// Created by cgo - DO NOT EDIT") 28 | prefix = []byte("// Code generated ") 29 | suffix = []byte(" DO NOT EDIT.") 30 | nl = []byte("\n") 31 | crnl = []byte("\r\n") 32 | ) 33 | 34 | func isGenerated(path string) (Generator, bool) { 35 | f, err := os.Open(path) 36 | if err != nil { 37 | return 0, false 38 | } 39 | defer f.Close() 40 | br := bufio.NewReader(f) 41 | for { 42 | s, err := br.ReadBytes('\n') 43 | if err != nil && err != io.EOF { 44 | return 0, false 45 | } 46 | s = bytes.TrimSuffix(s, crnl) 47 | s = bytes.TrimSuffix(s, nl) 48 | if bytes.HasPrefix(s, prefix) && bytes.HasSuffix(s, suffix) { 49 | if len(s)-len(suffix) < len(prefix) { 50 | return Unknown, true 51 | } 52 | 53 | text := string(s[len(prefix) : len(s)-len(suffix)]) 54 | switch text { 55 | case "by goyacc.": 56 | return Goyacc, true 57 | case "by cmd/cgo;": 58 | return Cgo, true 59 | case "by protoc-gen-go.": 60 | return ProtocGenGo, true 61 | } 62 | if strings.HasPrefix(text, `by "stringer `) { 63 | return Stringer, true 64 | } 65 | if strings.HasPrefix(text, `by goyacc `) { 66 | return Goyacc, true 67 | } 68 | 69 | return Unknown, true 70 | } 71 | if bytes.Equal(s, oldCgo) { 72 | return Cgo, true 73 | } 74 | if err == io.EOF { 75 | break 76 | } 77 | } 78 | return 0, false 79 | } 80 | 81 | var Analyzer = &analysis.Analyzer{ 82 | Name: "isgenerated", 83 | Doc: "annotate file names that have been code generated", 84 | Run: func(pass *analysis.Pass) (interface{}, error) { 85 | m := map[string]Generator{} 86 | for _, f := range pass.Files { 87 | path := pass.Fset.PositionFor(f.Pos(), false).Filename 88 | g, ok := isGenerated(path) 89 | if ok { 90 | m[path] = g 91 | } 92 | } 93 | return m, nil 94 | }, 95 | RunDespiteErrors: true, 96 | ResultType: reflect.TypeOf(map[string]Generator{}), 97 | } 98 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/analysis/facts/tokenfile/token.go: -------------------------------------------------------------------------------- 1 | package tokenfile 2 | 3 | import ( 4 | "go/ast" 5 | "go/token" 6 | "reflect" 7 | 8 | "golang.org/x/tools/go/analysis" 9 | ) 10 | 11 | var Analyzer = &analysis.Analyzer{ 12 | Name: "tokenfileanalyzer", 13 | Doc: "creates a mapping of *token.File to *ast.File", 14 | Run: func(pass *analysis.Pass) (interface{}, error) { 15 | m := map[*token.File]*ast.File{} 16 | for _, af := range pass.Files { 17 | tf := pass.Fset.File(af.Pos()) 18 | m[tf] = af 19 | } 20 | return m, nil 21 | }, 22 | RunDespiteErrors: true, 23 | ResultType: reflect.TypeOf(map[*token.File]*ast.File{}), 24 | } 25 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/cmd/staticcheck/README.md: -------------------------------------------------------------------------------- 1 | # staticcheck 2 | 3 | _staticcheck_ offers extensive analysis of Go code, covering a myriad 4 | of categories. It will detect bugs, suggest code simplifications, 5 | point out dead code, and more. 6 | 7 | ## Installation 8 | 9 | See [the main README](https://github.com/dominikh/go-tools#installation) for installation instructions. 10 | 11 | ## Documentation 12 | 13 | Detailed documentation can be found on 14 | [staticcheck.io](https://staticcheck.io/docs/). 15 | 16 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/cmd/staticcheck/staticcheck.go: -------------------------------------------------------------------------------- 1 | // staticcheck analyses Go code and makes it better. 2 | package main 3 | 4 | import ( 5 | "log" 6 | "os" 7 | 8 | "honnef.co/go/tools/lintcmd" 9 | "honnef.co/go/tools/lintcmd/version" 10 | "honnef.co/go/tools/quickfix" 11 | "honnef.co/go/tools/simple" 12 | "honnef.co/go/tools/staticcheck" 13 | "honnef.co/go/tools/stylecheck" 14 | "honnef.co/go/tools/unused" 15 | ) 16 | 17 | func main() { 18 | cmd := lintcmd.NewCommand("staticcheck") 19 | cmd.SetVersion(version.Version, version.MachineVersion) 20 | 21 | fs := cmd.FlagSet() 22 | debug := fs.String("debug.unused-graph", "", "Write unused's object graph to `file`") 23 | qf := fs.Bool("debug.run-quickfix-analyzers", false, "Run quickfix analyzers") 24 | 25 | cmd.ParseFlags(os.Args[1:]) 26 | 27 | cmd.AddAnalyzers(simple.Analyzers...) 28 | cmd.AddAnalyzers(staticcheck.Analyzers...) 29 | cmd.AddAnalyzers(stylecheck.Analyzers...) 30 | cmd.AddAnalyzers(unused.Analyzer) 31 | 32 | if *qf { 33 | cmd.AddAnalyzers(quickfix.Analyzers...) 34 | } 35 | 36 | if *debug != "" { 37 | f, err := os.OpenFile(*debug, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666) 38 | if err != nil { 39 | log.Fatal(err) 40 | } 41 | unused.Debug = f 42 | } 43 | 44 | cmd.Run() 45 | } 46 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/config/example.conf: -------------------------------------------------------------------------------- 1 | checks = ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-ST1023"] 2 | initialisms = ["ACL", "API", "ASCII", "CPU", "CSS", "DNS", 3 | "EOF", "GUID", "HTML", "HTTP", "HTTPS", "ID", 4 | "IP", "JSON", "QPS", "RAM", "RPC", "SLA", 5 | "SMTP", "SQL", "SSH", "TCP", "TLS", "TTL", 6 | "UDP", "UI", "GID", "UID", "UUID", "URI", 7 | "URL", "UTF8", "VM", "XML", "XMPP", "XSRF", 8 | "XSS", "SIP", "RTP", "AMQP", "DB", "TS"] 9 | dot_import_whitelist = [ 10 | "github.com/mmcloughlin/avo/build", 11 | "github.com/mmcloughlin/avo/operand", 12 | "github.com/mmcloughlin/avo/reg", 13 | ] 14 | http_status_code_whitelist = ["200", "400", "404", "500"] 15 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ast/astutil/upstream.go: -------------------------------------------------------------------------------- 1 | package astutil 2 | 3 | import ( 4 | "go/ast" 5 | "go/token" 6 | _ "unsafe" 7 | 8 | "golang.org/x/tools/go/ast/astutil" 9 | ) 10 | 11 | type Cursor = astutil.Cursor 12 | type ApplyFunc = astutil.ApplyFunc 13 | 14 | func Apply(root ast.Node, pre, post ApplyFunc) (result ast.Node) { 15 | return astutil.Apply(root, pre, post) 16 | } 17 | 18 | func PathEnclosingInterval(root *ast.File, start, end token.Pos) (path []ast.Node, exact bool) { 19 | return astutil.PathEnclosingInterval(root, start, end) 20 | } 21 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/buildid/UPSTREAM: -------------------------------------------------------------------------------- 1 | This package extracts buildid.go and note.go from cmd/internal/buildid/. 2 | 3 | We have modified it to remove support for AIX big archive files, to cut down on our dependencies. 4 | 5 | The last upstream commit we've looked at was: 639acdc833bfd12b7edd43092d1b380d70cb2874 6 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | Copyright (c) 2016 Dominik Honnef. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following disclaimer 12 | in the documentation and/or other materials provided with the 13 | distribution. 14 | * Neither the name of Google Inc. nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/UPSTREAM: -------------------------------------------------------------------------------- 1 | This package started as a copy of golang.org/x/tools/go/ssa, imported from an unknown commit in 2016. 2 | It has since been heavily modified to match our own needs in an IR. 3 | The changes are too many to list here, and it is best to consider this package independent of go/ssa. 4 | 5 | Upstream changes still get applied when they address bugs in portions of code we have inherited. 6 | 7 | The last upstream commit we've looked at was: 8 | 915f6209478fe61eb90dbe155a8a1c58655b931f 9 | 10 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/irutil/loops.go: -------------------------------------------------------------------------------- 1 | package irutil 2 | 3 | import "honnef.co/go/tools/go/ir" 4 | 5 | type Loop struct{ *ir.BlockSet } 6 | 7 | func FindLoops(fn *ir.Function) []Loop { 8 | if fn.Blocks == nil { 9 | return nil 10 | } 11 | tree := fn.DomPreorder() 12 | var sets []Loop 13 | for _, h := range tree { 14 | for _, n := range h.Preds { 15 | if !h.Dominates(n) { 16 | continue 17 | } 18 | // n is a back-edge to h 19 | // h is the loop header 20 | if n == h { 21 | set := Loop{ir.NewBlockSet(len(fn.Blocks))} 22 | set.Add(n) 23 | sets = append(sets, set) 24 | continue 25 | } 26 | set := Loop{ir.NewBlockSet(len(fn.Blocks))} 27 | set.Add(h) 28 | set.Add(n) 29 | for _, b := range allPredsBut(n, h, nil) { 30 | set.Add(b) 31 | } 32 | sets = append(sets, set) 33 | } 34 | } 35 | return sets 36 | } 37 | 38 | func allPredsBut(b, but *ir.BasicBlock, list []*ir.BasicBlock) []*ir.BasicBlock { 39 | outer: 40 | for _, pred := range b.Preds { 41 | if pred == but { 42 | continue 43 | } 44 | for _, p := range list { 45 | // TODO improve big-o complexity of this function 46 | if pred == p { 47 | continue outer 48 | } 49 | } 50 | list = append(list, pred) 51 | list = allPredsBut(pred, but, list) 52 | } 53 | return list 54 | } 55 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/irutil/stub.go: -------------------------------------------------------------------------------- 1 | package irutil 2 | 3 | import ( 4 | "honnef.co/go/tools/go/ir" 5 | ) 6 | 7 | // IsStub reports whether a function is a stub. A function is 8 | // considered a stub if it has no instructions or if all it does is 9 | // return a constant value. 10 | func IsStub(fn *ir.Function) bool { 11 | for _, b := range fn.Blocks { 12 | for _, instr := range b.Instrs { 13 | switch instr.(type) { 14 | case *ir.Const: 15 | // const naturally has no side-effects 16 | case *ir.Panic: 17 | // panic is a stub if it only uses constants 18 | case *ir.Return: 19 | // return is a stub if it only uses constants 20 | case *ir.DebugRef: 21 | case *ir.Jump: 22 | // if there are no disallowed instructions, then we're 23 | // only jumping to the exit block (or possibly 24 | // somewhere else that's stubby?) 25 | default: 26 | // all other instructions are assumed to do actual work 27 | return false 28 | } 29 | } 30 | } 31 | return true 32 | } 33 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/irutil/terminates.go: -------------------------------------------------------------------------------- 1 | package irutil 2 | 3 | import ( 4 | "go/types" 5 | 6 | "honnef.co/go/tools/go/ir" 7 | ) 8 | 9 | // Terminates reports whether fn is supposed to return, that is if it 10 | // has at least one theoretic path that returns from the function. 11 | // Explicit panics do not count as terminating. 12 | func Terminates(fn *ir.Function) bool { 13 | if fn.Blocks == nil { 14 | // assuming that a function terminates is the conservative 15 | // choice 16 | return true 17 | } 18 | 19 | for _, block := range fn.Blocks { 20 | if _, ok := block.Control().(*ir.Return); ok { 21 | if len(block.Preds) == 0 { 22 | return true 23 | } 24 | for _, pred := range block.Preds { 25 | switch ctrl := pred.Control().(type) { 26 | case *ir.Panic: 27 | // explicit panics do not count as terminating 28 | case *ir.If: 29 | // Check if we got here by receiving from a closed 30 | // time.Tick channel – this cannot happen at 31 | // runtime and thus doesn't constitute termination 32 | iff := ctrl 33 | if !ok { 34 | return true 35 | } 36 | ex, ok := iff.Cond.(*ir.Extract) 37 | if !ok { 38 | return true 39 | } 40 | if ex.Index != 1 { 41 | return true 42 | } 43 | recv, ok := ex.Tuple.(*ir.Recv) 44 | if !ok { 45 | return true 46 | } 47 | call, ok := recv.Chan.(*ir.Call) 48 | if !ok { 49 | return true 50 | } 51 | fn, ok := call.Common().Value.(*ir.Function) 52 | if !ok { 53 | return true 54 | } 55 | fn2, ok := fn.Object().(*types.Func) 56 | if !ok { 57 | return true 58 | } 59 | if fn2.FullName() != "time.Tick" { 60 | return true 61 | } 62 | default: 63 | // we've reached the exit block 64 | return true 65 | } 66 | } 67 | } 68 | } 69 | return false 70 | } 71 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/irutil/visit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package irutil 6 | 7 | import "honnef.co/go/tools/go/ir" 8 | 9 | // This file defines utilities for visiting the IR of 10 | // a Program. 11 | // 12 | // TODO(adonovan): test coverage. 13 | 14 | // AllFunctions finds and returns the set of functions potentially 15 | // needed by program prog, as determined by a simple linker-style 16 | // reachability algorithm starting from the members and method-sets of 17 | // each package. The result may include anonymous functions and 18 | // synthetic wrappers. 19 | // 20 | // Precondition: all packages are built. 21 | func AllFunctions(prog *ir.Program) map[*ir.Function]bool { 22 | visit := visitor{ 23 | prog: prog, 24 | seen: make(map[*ir.Function]bool), 25 | } 26 | visit.program() 27 | return visit.seen 28 | } 29 | 30 | type visitor struct { 31 | prog *ir.Program 32 | seen map[*ir.Function]bool 33 | } 34 | 35 | func (visit *visitor) program() { 36 | for _, pkg := range visit.prog.AllPackages() { 37 | for _, mem := range pkg.Members { 38 | if fn, ok := mem.(*ir.Function); ok { 39 | visit.function(fn) 40 | } 41 | } 42 | } 43 | for _, T := range visit.prog.RuntimeTypes() { 44 | mset := visit.prog.MethodSets.MethodSet(T) 45 | for i, n := 0, mset.Len(); i < n; i++ { 46 | visit.function(visit.prog.MethodValue(mset.At(i))) 47 | } 48 | } 49 | } 50 | 51 | func (visit *visitor) function(fn *ir.Function) { 52 | if !visit.seen[fn] { 53 | visit.seen[fn] = true 54 | var buf [10]*ir.Value // avoid alloc in common case 55 | for _, b := range fn.Blocks { 56 | for _, instr := range b.Instrs { 57 | for _, op := range instr.Operands(buf[:0]) { 58 | if fn, ok := (*op).(*ir.Function); ok { 59 | visit.function(fn) 60 | } 61 | } 62 | } 63 | } 64 | } 65 | } 66 | 67 | // MainPackages returns the subset of the specified packages 68 | // named "main" that define a main function. 69 | // The result may include synthetic "testmain" packages. 70 | func MainPackages(pkgs []*ir.Package) []*ir.Package { 71 | var mains []*ir.Package 72 | for _, pkg := range pkgs { 73 | if pkg.Pkg.Name() == "main" && pkg.Func("main") != nil { 74 | mains = append(mains, pkg) 75 | } 76 | } 77 | return mains 78 | } 79 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/ir/write.go: -------------------------------------------------------------------------------- 1 | package ir 2 | 3 | func NewJump(parent *BasicBlock) *Jump { 4 | return &Jump{anInstruction{block: parent}} 5 | } 6 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/loader/hash.go: -------------------------------------------------------------------------------- 1 | package loader 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "sort" 7 | "strings" 8 | 9 | "honnef.co/go/tools/go/buildid" 10 | "honnef.co/go/tools/lintcmd/cache" 11 | ) 12 | 13 | // computeHash computes a package's hash. The hash is based on all Go 14 | // files that make up the package, as well as the hashes of imported 15 | // packages. 16 | func computeHash(c *cache.Cache, pkg *PackageSpec) (cache.ActionID, error) { 17 | key := c.NewHash("package " + pkg.PkgPath) 18 | fmt.Fprintf(key, "goos %s goarch %s\n", runtime.GOOS, runtime.GOARCH) 19 | fmt.Fprintf(key, "import %q\n", pkg.PkgPath) 20 | 21 | // Compute the hashes of all files making up the package. As an 22 | // optimization, we use the build ID that Go already computed for 23 | // us, because it is virtually identical to hashed all 24 | // CompiledGoFiles. 25 | success := false 26 | if pkg.ExportFile != "" { 27 | id, err := getBuildid(pkg.ExportFile) 28 | if err == nil { 29 | if idx := strings.IndexRune(id, '/'); idx > -1 { 30 | fmt.Fprintf(key, "files %s\n", id[:idx]) 31 | success = true 32 | } 33 | } 34 | } 35 | if !success { 36 | for _, f := range pkg.CompiledGoFiles { 37 | h, err := cache.FileHash(f) 38 | if err != nil { 39 | return cache.ActionID{}, err 40 | } 41 | fmt.Fprintf(key, "file %s %x\n", f, h) 42 | } 43 | } 44 | 45 | imps := make([]*PackageSpec, 0, len(pkg.Imports)) 46 | for _, v := range pkg.Imports { 47 | imps = append(imps, v) 48 | } 49 | sort.Slice(imps, func(i, j int) bool { 50 | return imps[i].PkgPath < imps[j].PkgPath 51 | }) 52 | 53 | for _, dep := range imps { 54 | if dep.ExportFile == "" { 55 | fmt.Fprintf(key, "import %s \n", dep.PkgPath) 56 | } else { 57 | id, err := getBuildid(dep.ExportFile) 58 | if err == nil { 59 | fmt.Fprintf(key, "import %s %s\n", dep.PkgPath, id) 60 | } else { 61 | fh, err := cache.FileHash(dep.ExportFile) 62 | if err != nil { 63 | return cache.ActionID{}, err 64 | } 65 | fmt.Fprintf(key, "import %s %x\n", dep.PkgPath, fh) 66 | } 67 | } 68 | } 69 | return key.Sum(), nil 70 | } 71 | 72 | var buildidCache = map[string]string{} 73 | 74 | func getBuildid(f string) (string, error) { 75 | if h, ok := buildidCache[f]; ok { 76 | return h, nil 77 | } 78 | h, err := buildid.ReadFile(f) 79 | if err != nil { 80 | return "", err 81 | } 82 | buildidCache[f] = h 83 | return h, nil 84 | } 85 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/types/typeutil/ext.go: -------------------------------------------------------------------------------- 1 | package typeutil 2 | 3 | import ( 4 | "fmt" 5 | "go/types" 6 | ) 7 | 8 | type Iterator struct { 9 | elem types.Type 10 | } 11 | 12 | func (t *Iterator) Underlying() types.Type { return t } 13 | func (t *Iterator) String() string { return fmt.Sprintf("iterator(%s)", t.elem) } 14 | func (t *Iterator) Elem() types.Type { return t.elem } 15 | 16 | func NewIterator(elem types.Type) *Iterator { 17 | return &Iterator{elem: elem} 18 | } 19 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/go/types/typeutil/upstream.go: -------------------------------------------------------------------------------- 1 | package typeutil 2 | 3 | import ( 4 | "go/ast" 5 | "go/types" 6 | _ "unsafe" 7 | 8 | "golang.org/x/tools/go/types/typeutil" 9 | ) 10 | 11 | type MethodSetCache = typeutil.MethodSetCache 12 | type Hasher = typeutil.Hasher 13 | 14 | func Callee(info *types.Info, call *ast.CallExpr) types.Object { 15 | return typeutil.Callee(info, call) 16 | } 17 | 18 | func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection { 19 | return typeutil.IntuitiveMethodSet(T, msets) 20 | } 21 | 22 | func MakeHasher() Hasher { 23 | return typeutil.MakeHasher() 24 | } 25 | 26 | type Map[V any] struct { 27 | m typeutil.Map 28 | } 29 | 30 | func (m *Map[V]) Delete(key types.Type) bool { return m.m.Delete(key) } 31 | func (m *Map[V]) At(key types.Type) (V, bool) { 32 | v := m.m.At(key) 33 | if v == nil { 34 | var zero V 35 | return zero, false 36 | } else { 37 | return v.(V), true 38 | } 39 | } 40 | func (m *Map[V]) Set(key types.Type, value V) { m.m.Set(key, value) } 41 | func (m *Map[V]) Len() int { return m.m.Len() } 42 | func (m *Map[V]) Iterate(f func(key types.Type, value V)) { 43 | ff := func(key types.Type, value interface{}) { 44 | f(key, value.(V)) 45 | } 46 | m.m.Iterate(ff) 47 | 48 | } 49 | func (m *Map[V]) Keys() []types.Type { return m.m.Keys() } 50 | func (m *Map[V]) String() string { return m.m.String() } 51 | func (m *Map[V]) KeysString() string { return m.m.KeysString() } 52 | func (m *Map[V]) SetHasher(h typeutil.Hasher) { m.m.SetHasher(h) } 53 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/renameio/UPSTREAM: -------------------------------------------------------------------------------- 1 | This package is a copy of cmd/go/internal/renameio. 2 | The upstream package no longer exists, as the Go project replaced all of its uses with the lockedfile package. 3 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/robustio/UPSTREAM: -------------------------------------------------------------------------------- 1 | This package is a copy of cmd/go/internal/robustio. 2 | It is mostly in sync with upstream according to the last commit we've looked at, 3 | with the exception of still using I/O functions that work with older Go versions. 4 | 5 | The last upstream commit we've looked at was: 6 | dc04f3ba1f25313bc9c97e728620206c235db9ee 7 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/robustio/robustio.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package robustio wraps I/O functions that are prone to failure on Windows, 6 | // transparently retrying errors up to an arbitrary timeout. 7 | // 8 | // Errors are classified heuristically and retries are bounded, so the functions 9 | // in this package do not completely eliminate spurious errors. However, they do 10 | // significantly reduce the rate of failure in practice. 11 | // 12 | // If so, the error will likely wrap one of: 13 | // The functions in this package do not completely eliminate spurious errors, 14 | // but substantially reduce their rate of occurrence in practice. 15 | package robustio 16 | 17 | // Rename is like os.Rename, but on Windows retries errors that may occur if the 18 | // file is concurrently read or overwritten. 19 | // 20 | // (See golang.org/issue/31247 and golang.org/issue/32188.) 21 | func Rename(oldpath, newpath string) error { 22 | return rename(oldpath, newpath) 23 | } 24 | 25 | // ReadFile is like os.ReadFile, but on Windows retries errors that may 26 | // occur if the file is concurrently replaced. 27 | // 28 | // (See golang.org/issue/31247 and golang.org/issue/32188.) 29 | func ReadFile(filename string) ([]byte, error) { 30 | return readFile(filename) 31 | } 32 | 33 | // RemoveAll is like os.RemoveAll, but on Windows retries errors that may occur 34 | // if an executable file in the directory has recently been executed. 35 | // 36 | // (See golang.org/issue/19491.) 37 | func RemoveAll(path string) error { 38 | return removeAll(path) 39 | } 40 | 41 | // IsEphemeralError reports whether err is one of the errors that the functions 42 | // in this package attempt to mitigate. 43 | // 44 | // Errors considered ephemeral include: 45 | // - syscall.ERROR_ACCESS_DENIED 46 | // - syscall.ERROR_FILE_NOT_FOUND 47 | // - internal/syscall/windows.ERROR_SHARING_VIOLATION 48 | // 49 | // This set may be expanded in the future; programs must not rely on the 50 | // non-ephemerality of any given error. 51 | func IsEphemeralError(err error) bool { 52 | return isEphemeralError(err) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/robustio/robustio_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package robustio 6 | 7 | import ( 8 | "errors" 9 | "syscall" 10 | ) 11 | 12 | const errFileNotFound = syscall.ENOENT 13 | 14 | // isEphemeralError returns true if err may be resolved by waiting. 15 | func isEphemeralError(err error) bool { 16 | var errno syscall.Errno 17 | if errors.As(err, &errno) { 18 | return errno == errFileNotFound 19 | } 20 | return false 21 | } 22 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/robustio/robustio_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !windows && !darwin 6 | 7 | package robustio 8 | 9 | import ( 10 | "os" 11 | ) 12 | 13 | func rename(oldpath, newpath string) error { 14 | return os.Rename(oldpath, newpath) 15 | } 16 | 17 | func readFile(filename string) ([]byte, error) { 18 | return os.ReadFile(filename) 19 | } 20 | 21 | func removeAll(path string) error { 22 | return os.RemoveAll(path) 23 | } 24 | 25 | func isEphemeralError(err error) bool { 26 | return false 27 | } 28 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/robustio/robustio_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package robustio 6 | 7 | import ( 8 | "errors" 9 | "syscall" 10 | ) 11 | 12 | const ERROR_SHARING_VIOLATION = 32 13 | const errFileNotFound = syscall.ERROR_FILE_NOT_FOUND 14 | 15 | // isEphemeralError returns true if err may be resolved by waiting. 16 | func isEphemeralError(err error) bool { 17 | var errno syscall.Errno 18 | if errors.As(err, &errno) { 19 | switch errno { 20 | case syscall.ERROR_ACCESS_DENIED, 21 | syscall.ERROR_FILE_NOT_FOUND, 22 | ERROR_SHARING_VIOLATION: 23 | return true 24 | } 25 | } 26 | return false 27 | } 28 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/internal/sync/sync.go: -------------------------------------------------------------------------------- 1 | package sync 2 | 3 | type Semaphore struct { 4 | ch chan struct{} 5 | } 6 | 7 | func NewSemaphore(size int) Semaphore { 8 | return Semaphore{ 9 | ch: make(chan struct{}, size), 10 | } 11 | } 12 | 13 | func (sem Semaphore) Acquire() { 14 | sem.ch <- struct{}{} 15 | } 16 | 17 | func (sem Semaphore) AcquireMaybe() bool { 18 | select { 19 | case sem.ch <- struct{}{}: 20 | return true 21 | default: 22 | return false 23 | } 24 | } 25 | 26 | func (sem Semaphore) Release() { 27 | <-sem.ch 28 | } 29 | 30 | func (sem Semaphore) Len() int { 31 | return len(sem.ch) 32 | } 33 | 34 | func (sem Semaphore) Cap() int { 35 | return cap(sem.ch) 36 | } 37 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/knowledge/doc.go: -------------------------------------------------------------------------------- 1 | // Package knowledge contains manually collected information about Go APIs. 2 | package knowledge 3 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/cache/UPSTREAM: -------------------------------------------------------------------------------- 1 | This package is a copy of cmd/go/internal/cache. 2 | 3 | Differences from upstream: 4 | - we continue to use renameio instead of lockedfile for writing trim.txt 5 | - we still use I/O helpers that work with earlier versions of Go. 6 | - we use a cache directory specific to Staticcheck 7 | - we use a Staticcheck-specific salt 8 | 9 | The last upstream commit we've looked at was: 10 | 06ac303f6a14b133254f757e54599c48e3c2a4ad 11 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/cache/default.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package cache 6 | 7 | import ( 8 | "fmt" 9 | "log" 10 | "os" 11 | "path/filepath" 12 | "sync" 13 | ) 14 | 15 | // Default returns the default cache to use. 16 | func Default() (*Cache, error) { 17 | defaultOnce.Do(initDefaultCache) 18 | return defaultCache, defaultDirErr 19 | } 20 | 21 | var ( 22 | defaultOnce sync.Once 23 | defaultCache *Cache 24 | ) 25 | 26 | // cacheREADME is a message stored in a README in the cache directory. 27 | // Because the cache lives outside the normal Go trees, we leave the 28 | // README as a courtesy to explain where it came from. 29 | const cacheREADME = `This directory holds cached build artifacts from staticcheck. 30 | ` 31 | 32 | // initDefaultCache does the work of finding the default cache 33 | // the first time Default is called. 34 | func initDefaultCache() { 35 | dir := DefaultDir() 36 | if err := os.MkdirAll(dir, 0777); err != nil { 37 | log.Fatalf("failed to initialize build cache at %s: %s\n", dir, err) 38 | } 39 | if _, err := os.Stat(filepath.Join(dir, "README")); err != nil { 40 | // Best effort. 41 | os.WriteFile(filepath.Join(dir, "README"), []byte(cacheREADME), 0666) 42 | } 43 | 44 | c, err := Open(dir) 45 | if err != nil { 46 | log.Fatalf("failed to initialize build cache at %s: %s\n", dir, err) 47 | } 48 | defaultCache = c 49 | } 50 | 51 | var ( 52 | defaultDirOnce sync.Once 53 | defaultDir string 54 | defaultDirErr error 55 | ) 56 | 57 | // DefaultDir returns the effective STATICCHECK_CACHE setting. 58 | func DefaultDir() string { 59 | // Save the result of the first call to DefaultDir for later use in 60 | // initDefaultCache. cmd/go/main.go explicitly sets GOCACHE so that 61 | // subprocesses will inherit it, but that means initDefaultCache can't 62 | // otherwise distinguish between an explicit "off" and a UserCacheDir error. 63 | 64 | defaultDirOnce.Do(func() { 65 | defaultDir = os.Getenv("STATICCHECK_CACHE") 66 | if filepath.IsAbs(defaultDir) { 67 | return 68 | } 69 | if defaultDir != "" { 70 | defaultDirErr = fmt.Errorf("STATICCHECK_CACHE is not an absolute path") 71 | return 72 | } 73 | 74 | // Compute default location. 75 | dir, err := os.UserCacheDir() 76 | if err != nil { 77 | defaultDirErr = fmt.Errorf("STATICCHECK_CACHE is not defined and %v", err) 78 | return 79 | } 80 | defaultDir = filepath.Join(dir, "staticcheck") 81 | }) 82 | 83 | return defaultDir 84 | } 85 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/config.go: -------------------------------------------------------------------------------- 1 | package lintcmd 2 | 3 | import ( 4 | "bufio" 5 | "errors" 6 | "fmt" 7 | "io" 8 | "strings" 9 | "unicode" 10 | ) 11 | 12 | type parseBuildConfigError struct { 13 | line int 14 | err error 15 | } 16 | 17 | func (err parseBuildConfigError) Error() string { return err.err.Error() } 18 | 19 | func parseBuildConfigs(r io.Reader) ([]buildConfig, error) { 20 | var builds []buildConfig 21 | br := bufio.NewReader(r) 22 | i := 0 23 | for { 24 | line, err := br.ReadString('\n') 25 | if err != nil { 26 | if err == io.EOF { 27 | break 28 | } else { 29 | return nil, err 30 | } 31 | } 32 | line = strings.TrimSpace(line) 33 | if line == "" { 34 | continue 35 | } 36 | name, envs, flags, err := parseBuildConfig(line) 37 | if err != nil { 38 | return nil, parseBuildConfigError{line: i + 1, err: err} 39 | } 40 | 41 | bc := buildConfig{ 42 | Name: name, 43 | Envs: envs, 44 | Flags: flags, 45 | } 46 | builds = append(builds, bc) 47 | 48 | i++ 49 | } 50 | return builds, nil 51 | } 52 | 53 | func parseBuildConfig(line string) (name string, envs []string, flags []string, err error) { 54 | if line == "" { 55 | return "", nil, nil, errors.New("couldn't parse empty build config") 56 | } 57 | if strings.Index(line, ":") == len(line)-1 { 58 | name = line[:len(line)-1] 59 | } else { 60 | idx := strings.Index(line, ": ") 61 | if idx == -1 { 62 | return name, envs, flags, errors.New("missing build name") 63 | } 64 | name = line[:idx] 65 | 66 | var buf []rune 67 | var inQuote bool 68 | args := &envs 69 | for _, r := range strings.TrimSpace(line[idx+2:]) { 70 | switch r { 71 | case ' ': 72 | if inQuote { 73 | buf = append(buf, r) 74 | } else if len(buf) != 0 { 75 | if buf[0] == '-' { 76 | args = &flags 77 | } 78 | *args = append(*args, string(buf)) 79 | buf = buf[:0] 80 | } 81 | case '"': 82 | inQuote = !inQuote 83 | default: 84 | buf = append(buf, r) 85 | } 86 | } 87 | 88 | if len(buf) > 0 { 89 | if inQuote { 90 | return "", nil, nil, errors.New("unterminated quoted string") 91 | } 92 | if buf[0] == '-' { 93 | args = &flags 94 | } 95 | *args = append(*args, string(buf)) 96 | } 97 | } 98 | 99 | for _, r := range name { 100 | if !(r == '_' || unicode.IsLetter(r) || unicode.IsNumber(r)) { 101 | return "", nil, nil, fmt.Errorf("invalid build name %q", name) 102 | } 103 | } 104 | return name, envs, flags, nil 105 | } 106 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/directives.go: -------------------------------------------------------------------------------- 1 | package lintcmd 2 | 3 | import ( 4 | "strings" 5 | 6 | "honnef.co/go/tools/lintcmd/runner" 7 | ) 8 | 9 | func parseDirectives(dirs []runner.SerializedDirective) ([]ignore, []diagnostic) { 10 | var ignores []ignore 11 | var diagnostics []diagnostic 12 | 13 | for _, dir := range dirs { 14 | cmd := dir.Command 15 | args := dir.Arguments 16 | switch cmd { 17 | case "ignore", "file-ignore": 18 | if len(args) < 2 { 19 | p := diagnostic{ 20 | Diagnostic: runner.Diagnostic{ 21 | Position: dir.NodePosition, 22 | Message: "malformed linter directive; missing the required reason field?", 23 | Category: "compile", 24 | }, 25 | Severity: severityError, 26 | } 27 | diagnostics = append(diagnostics, p) 28 | continue 29 | } 30 | default: 31 | // unknown directive, ignore 32 | continue 33 | } 34 | checks := strings.Split(args[0], ",") 35 | pos := dir.NodePosition 36 | var ig ignore 37 | switch cmd { 38 | case "ignore": 39 | ig = &lineIgnore{ 40 | File: pos.Filename, 41 | Line: pos.Line, 42 | Checks: checks, 43 | Pos: dir.DirectivePosition, 44 | } 45 | case "file-ignore": 46 | ig = &fileIgnore{ 47 | File: pos.Filename, 48 | Checks: checks, 49 | } 50 | } 51 | ignores = append(ignores, ig) 52 | } 53 | 54 | return ignores, diagnostics 55 | } 56 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/runner/stats.go: -------------------------------------------------------------------------------- 1 | package runner 2 | 3 | import ( 4 | "sync/atomic" 5 | "time" 6 | 7 | "honnef.co/go/tools/go/loader" 8 | 9 | "golang.org/x/tools/go/analysis" 10 | ) 11 | 12 | const ( 13 | StateInitializing = iota 14 | StateLoadPackageGraph 15 | StateBuildActionGraph 16 | StateProcessing 17 | StateFinalizing 18 | ) 19 | 20 | type Stats struct { 21 | state uint32 22 | initialPackages uint32 23 | totalPackages uint32 24 | processedPackages uint32 25 | processedInitialPackages uint32 26 | 27 | // optional function to call every time an analyzer has finished analyzing a package. 28 | PrintAnalyzerMeasurement func(*analysis.Analyzer, *loader.PackageSpec, time.Duration) 29 | } 30 | 31 | func (s *Stats) setState(state uint32) { atomic.StoreUint32(&s.state, state) } 32 | func (s *Stats) State() int { return int(atomic.LoadUint32(&s.state)) } 33 | func (s *Stats) setInitialPackages(n int) { atomic.StoreUint32(&s.initialPackages, uint32(n)) } 34 | func (s *Stats) InitialPackages() int { return int(atomic.LoadUint32(&s.initialPackages)) } 35 | func (s *Stats) setTotalPackages(n int) { atomic.StoreUint32(&s.totalPackages, uint32(n)) } 36 | func (s *Stats) TotalPackages() int { return int(atomic.LoadUint32(&s.totalPackages)) } 37 | 38 | func (s *Stats) finishPackage() { atomic.AddUint32(&s.processedPackages, 1) } 39 | func (s *Stats) finishInitialPackage() { atomic.AddUint32(&s.processedInitialPackages, 1) } 40 | func (s *Stats) ProcessedPackages() int { return int(atomic.LoadUint32(&s.processedPackages)) } 41 | func (s *Stats) ProcessedInitialPackages() int { 42 | return int(atomic.LoadUint32(&s.processedInitialPackages)) 43 | } 44 | 45 | func (s *Stats) measureAnalyzer(analysis *analysis.Analyzer, pkg *loader.PackageSpec, d time.Duration) { 46 | if s.PrintAnalyzerMeasurement != nil { 47 | s.PrintAnalyzerMeasurement(analysis, pkg, d) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/stats.go: -------------------------------------------------------------------------------- 1 | //go:build !aix && !android && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris 2 | // +build !aix,!android,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris 3 | 4 | package lintcmd 5 | 6 | import "os" 7 | 8 | var infoSignals = []os.Signal{} 9 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/stats_bsd.go: -------------------------------------------------------------------------------- 1 | //go:build darwin || dragonfly || freebsd || netbsd || openbsd 2 | // +build darwin dragonfly freebsd netbsd openbsd 3 | 4 | package lintcmd 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | ) 10 | 11 | var infoSignals = []os.Signal{syscall.SIGINFO} 12 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/stats_posix.go: -------------------------------------------------------------------------------- 1 | //go:build aix || android || linux || solaris 2 | // +build aix android linux solaris 3 | 4 | package lintcmd 5 | 6 | import ( 7 | "os" 8 | "syscall" 9 | ) 10 | 11 | var infoSignals = []os.Signal{syscall.SIGUSR1} 12 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/version/buildinfo.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "fmt" 5 | "runtime/debug" 6 | ) 7 | 8 | func printBuildInfo() { 9 | if info, ok := debug.ReadBuildInfo(); ok { 10 | fmt.Println("Main module:") 11 | printModule(&info.Main) 12 | fmt.Println("Dependencies:") 13 | for _, dep := range info.Deps { 14 | printModule(dep) 15 | } 16 | } else { 17 | fmt.Println("Built without Go modules") 18 | } 19 | } 20 | 21 | func buildInfoVersion() (string, bool) { 22 | info, ok := debug.ReadBuildInfo() 23 | if !ok { 24 | return "", false 25 | } 26 | if info.Main.Version == "(devel)" { 27 | return "", false 28 | } 29 | return info.Main.Version, true 30 | } 31 | 32 | func printModule(m *debug.Module) { 33 | fmt.Printf("\t%s", m.Path) 34 | if m.Version != "(devel)" { 35 | fmt.Printf("@%s", m.Version) 36 | } 37 | if m.Sum != "" { 38 | fmt.Printf(" (sum: %s)", m.Sum) 39 | } 40 | if m.Replace != nil { 41 | fmt.Printf(" (replace: %s)", m.Replace.Path) 42 | } 43 | fmt.Println() 44 | } 45 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/lintcmd/version/version.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "path/filepath" 7 | "runtime" 8 | ) 9 | 10 | const Version = "2023.1.3" 11 | const MachineVersion = "v0.4.3" 12 | 13 | // version returns a version descriptor and reports whether the 14 | // version is a known release. 15 | func version(human, machine string) (human_, machine_ string, known bool) { 16 | if human != "devel" { 17 | return human, machine, true 18 | } 19 | v, ok := buildInfoVersion() 20 | if ok { 21 | return v, "", false 22 | } 23 | return "devel", "", false 24 | } 25 | 26 | func Print(human, machine string) { 27 | human, machine, release := version(human, machine) 28 | 29 | if release { 30 | fmt.Printf("%s %s (%s)\n", filepath.Base(os.Args[0]), human, machine) 31 | } else if human == "devel" { 32 | fmt.Printf("%s (no version)\n", filepath.Base(os.Args[0])) 33 | } else { 34 | fmt.Printf("%s (devel, %s)\n", filepath.Base(os.Args[0]), human) 35 | } 36 | } 37 | 38 | func Verbose(human, machine string) { 39 | Print(human, machine) 40 | fmt.Println() 41 | fmt.Println("Compiled with Go version:", runtime.Version()) 42 | printBuildInfo() 43 | } 44 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/printf/fuzz.go: -------------------------------------------------------------------------------- 1 | //go:build gofuzz 2 | // +build gofuzz 3 | 4 | package printf 5 | 6 | func Fuzz(data []byte) int { 7 | _, err := Parse(string(data)) 8 | if err == nil { 9 | return 1 10 | } 11 | return 0 12 | } 13 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/quickfix/analysis.go: -------------------------------------------------------------------------------- 1 | package quickfix 2 | 3 | import ( 4 | "honnef.co/go/tools/analysis/facts/tokenfile" 5 | "honnef.co/go/tools/analysis/lint" 6 | "honnef.co/go/tools/internal/sharedcheck" 7 | 8 | "golang.org/x/tools/go/analysis" 9 | "golang.org/x/tools/go/analysis/passes/inspect" 10 | ) 11 | 12 | var Analyzers = lint.InitializeAnalyzers(Docs, map[string]*analysis.Analyzer{ 13 | "QF1001": { 14 | Run: CheckDeMorgan, 15 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 16 | }, 17 | "QF1002": { 18 | Run: CheckTaglessSwitch, 19 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 20 | }, 21 | "QF1003": { 22 | Run: CheckIfElseToSwitch, 23 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 24 | }, 25 | "QF1004": { 26 | Run: CheckStringsReplaceAll, 27 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 28 | }, 29 | "QF1005": { 30 | Run: CheckMathPow, 31 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 32 | }, 33 | "QF1006": { 34 | Run: CheckForLoopIfBreak, 35 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 36 | }, 37 | "QF1007": { 38 | Run: CheckConditionalAssignment, 39 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 40 | }, 41 | "QF1008": { 42 | Run: CheckExplicitEmbeddedSelector, 43 | Requires: []*analysis.Analyzer{inspect.Analyzer, tokenfile.Analyzer}, 44 | }, 45 | "QF1009": { 46 | Run: CheckTimeEquality, 47 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 48 | }, 49 | "QF1010": { 50 | Run: CheckByteSlicePrinting, 51 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 52 | }, 53 | "QF1011": sharedcheck.RedundantTypeInDeclarationChecker("could", true), 54 | "QF1012": { 55 | Run: CheckWriteBytesSprintf, 56 | Requires: []*analysis.Analyzer{inspect.Analyzer}, 57 | }, 58 | }) 59 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/staticcheck/buildtag.go: -------------------------------------------------------------------------------- 1 | package staticcheck 2 | 3 | import ( 4 | "go/ast" 5 | "strings" 6 | 7 | "honnef.co/go/tools/go/ast/astutil" 8 | ) 9 | 10 | func buildTags(f *ast.File) [][]string { 11 | var out [][]string 12 | for _, line := range strings.Split(astutil.Preamble(f), "\n") { 13 | if !strings.HasPrefix(line, "+build ") { 14 | continue 15 | } 16 | line = strings.TrimSpace(strings.TrimPrefix(line, "+build ")) 17 | fields := strings.Fields(line) 18 | out = append(out, fields) 19 | } 20 | return out 21 | } 22 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/staticcheck/fakexml/xml.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package fakexml 6 | 7 | // References: 8 | // Annotated XML spec: https://www.xml.com/axml/testaxml.htm 9 | // XML name spaces: https://www.w3.org/TR/REC-xml-names/ 10 | 11 | // TODO(rsc): 12 | // Test error handling. 13 | 14 | // A Name represents an XML name (Local) annotated 15 | // with a name space identifier (Space). 16 | // In tokens returned by Decoder.Token, the Space identifier 17 | // is given as a canonical URL, not the short prefix used 18 | // in the document being parsed. 19 | type Name struct { 20 | Space, Local string 21 | } 22 | 23 | // An Attr represents an attribute in an XML element (Name=Value). 24 | type Attr struct { 25 | Name Name 26 | Value string 27 | } 28 | 29 | // A StartElement represents an XML start element. 30 | type StartElement struct { 31 | Name Name 32 | Attr []Attr 33 | } 34 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/staticcheck/structtag.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Copyright 2019 Dominik Honnef. All rights reserved. 3 | 4 | package staticcheck 5 | 6 | import "strconv" 7 | 8 | func parseStructTag(tag string) (map[string][]string, error) { 9 | // FIXME(dh): detect missing closing quote 10 | out := map[string][]string{} 11 | 12 | for tag != "" { 13 | // Skip leading space. 14 | i := 0 15 | for i < len(tag) && tag[i] == ' ' { 16 | i++ 17 | } 18 | tag = tag[i:] 19 | if tag == "" { 20 | break 21 | } 22 | 23 | // Scan to colon. A space, a quote or a control character is a syntax error. 24 | // Strictly speaking, control chars include the range [0x7f, 0x9f], not just 25 | // [0x00, 0x1f], but in practice, we ignore the multi-byte control characters 26 | // as it is simpler to inspect the tag's bytes than the tag's runes. 27 | i = 0 28 | for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f { 29 | i++ 30 | } 31 | if i == 0 || i+1 >= len(tag) || tag[i] != ':' || tag[i+1] != '"' { 32 | break 33 | } 34 | name := string(tag[:i]) 35 | tag = tag[i+1:] 36 | 37 | // Scan quoted string to find value. 38 | i = 1 39 | for i < len(tag) && tag[i] != '"' { 40 | if tag[i] == '\\' { 41 | i++ 42 | } 43 | i++ 44 | } 45 | if i >= len(tag) { 46 | break 47 | } 48 | qvalue := string(tag[:i+1]) 49 | tag = tag[i+1:] 50 | 51 | value, err := strconv.Unquote(qvalue) 52 | if err != nil { 53 | return nil, err 54 | } 55 | out[name] = append(out[name], value) 56 | } 57 | return out, nil 58 | } 59 | -------------------------------------------------------------------------------- /vendor/honnef.co/go/tools/unused/implements.go: -------------------------------------------------------------------------------- 1 | package unused 2 | 3 | import "go/types" 4 | 5 | // lookupMethod returns the index of and method with matching package and name, or (-1, nil). 6 | func lookupMethod(T *types.Interface, pkg *types.Package, name string) (int, *types.Func) { 7 | if name != "_" { 8 | for i := 0; i < T.NumMethods(); i++ { 9 | m := T.Method(i) 10 | if sameId(m, pkg, name) { 11 | return i, m 12 | } 13 | } 14 | } 15 | return -1, nil 16 | } 17 | 18 | func sameId(obj types.Object, pkg *types.Package, name string) bool { 19 | // spec: 20 | // "Two identifiers are different if they are spelled differently, 21 | // or if they appear in different packages and are not exported. 22 | // Otherwise, they are the same." 23 | if name != obj.Name() { 24 | return false 25 | } 26 | // obj.Name == name 27 | if obj.Exported() { 28 | return true 29 | } 30 | // not exported, so packages must be the same (pkg == nil for 31 | // fields in Universe scope; this can only happen for types 32 | // introduced via Eval) 33 | if pkg == nil || obj.Pkg() == nil { 34 | return pkg == obj.Pkg() 35 | } 36 | // pkg != nil && obj.pkg != nil 37 | return pkg.Path() == obj.Pkg().Path() 38 | } 39 | 40 | func implements(V types.Type, T *types.Interface, msV *types.MethodSet) ([]*types.Selection, bool) { 41 | // fast path for common case 42 | if T.Empty() { 43 | return nil, true 44 | } 45 | 46 | if ityp, _ := V.Underlying().(*types.Interface); ityp != nil { 47 | // TODO(dh): is this code reachable? 48 | for i := 0; i < T.NumMethods(); i++ { 49 | m := T.Method(i) 50 | _, obj := lookupMethod(ityp, m.Pkg(), m.Name()) 51 | switch { 52 | case obj == nil: 53 | return nil, false 54 | case !types.Identical(obj.Type(), m.Type()): 55 | return nil, false 56 | } 57 | } 58 | return nil, true 59 | } 60 | 61 | // A concrete type implements T if it implements all methods of T. 62 | var sels []*types.Selection 63 | for i := 0; i < T.NumMethods(); i++ { 64 | m := T.Method(i) 65 | sel := msV.Lookup(m.Pkg(), m.Name()) 66 | if sel == nil { 67 | return nil, false 68 | } 69 | 70 | f, _ := sel.Obj().(*types.Func) 71 | if f == nil { 72 | return nil, false 73 | } 74 | 75 | if !types.Identical(f.Type(), m.Type()) { 76 | return nil, false 77 | } 78 | 79 | sels = append(sels, sel) 80 | } 81 | return sels, true 82 | } 83 | --------------------------------------------------------------------------------