├── .github ├── CODEOWNERS ├── FUNDING.yml ├── dependabot.yml └── workflows │ ├── ci.yml │ └── release.yml ├── .gitignore ├── .golangci.yml ├── .goreleaser.yml ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── cf-worker.js ├── go.mod ├── go.sum ├── main.go ├── main_test.go └── vendor ├── github.com ├── davecgh │ └── go-spew │ │ ├── LICENSE │ │ └── spew │ │ ├── bypass.go │ │ ├── bypasssafe.go │ │ ├── common.go │ │ ├── config.go │ │ ├── doc.go │ │ ├── dump.go │ │ ├── format.go │ │ └── spew.go ├── go-pkgz │ ├── lgr │ │ ├── .gitignore │ │ ├── .golangci.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── adaptor.go │ │ ├── interface.go │ │ ├── logger.go │ │ ├── mapper.go │ │ └── options.go │ └── rest │ │ ├── .gitignore │ │ ├── .golangci.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── basic_auth.go │ │ ├── benchmarks.go │ │ ├── blackwords.go │ │ ├── cache_control.go │ │ ├── depricattion.go │ │ ├── file_server.go │ │ ├── gzip.go │ │ ├── httperrors.go │ │ ├── logger │ │ ├── logger.go │ │ └── options.go │ │ ├── metrics.go │ │ ├── middleware.go │ │ ├── nocache.go │ │ ├── onlyfrom.go │ │ ├── profiler.go │ │ ├── realip │ │ └── real.go │ │ ├── rest.go │ │ ├── rewrite.go │ │ ├── sizelimit.go │ │ ├── throttle.go │ │ └── trace.go ├── pmezard │ └── go-difflib │ │ ├── LICENSE │ │ └── difflib │ │ └── difflib.go ├── stretchr │ └── testify │ │ ├── LICENSE │ │ ├── assert │ │ ├── assertion_compare.go │ │ ├── assertion_format.go │ │ ├── assertion_format.go.tmpl │ │ ├── assertion_forward.go │ │ ├── assertion_forward.go.tmpl │ │ ├── assertion_order.go │ │ ├── assertions.go │ │ ├── doc.go │ │ ├── errors.go │ │ ├── forward_assertions.go │ │ ├── http_assertions.go │ │ └── yaml │ │ │ ├── yaml_custom.go │ │ │ ├── yaml_default.go │ │ │ └── yaml_fail.go │ │ └── require │ │ ├── doc.go │ │ ├── forward_requirements.go │ │ ├── require.go │ │ ├── require.go.tmpl │ │ ├── require_forward.go │ │ ├── require_forward.go.tmpl │ │ └── requirements.go └── umputun │ └── go-flags │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── arg.go │ ├── check_crosscompile.sh │ ├── closest.go │ ├── command.go │ ├── completion.go │ ├── convert.go │ ├── error.go │ ├── flags.go │ ├── group.go │ ├── help.go │ ├── ini.go │ ├── man.go │ ├── multitag.go │ ├── option.go │ ├── optstyle_other.go │ ├── optstyle_windows.go │ ├── parser.go │ ├── termsize.go │ ├── termsize_nosysioctl.go │ ├── termsize_windows.go │ ├── tiocgwinsz_bsdish.go │ ├── tiocgwinsz_linux.go │ └── tiocgwinsz_other.go ├── golang.org └── x │ ├── crypto │ ├── LICENSE │ ├── PATENTS │ ├── argon2 │ │ ├── argon2.go │ │ ├── blake2b.go │ │ ├── blamka_amd64.go │ │ ├── blamka_amd64.s │ │ ├── blamka_generic.go │ │ └── blamka_ref.go │ ├── bcrypt │ │ ├── base64.go │ │ └── bcrypt.go │ ├── blake2b │ │ ├── blake2b.go │ │ ├── blake2bAVX2_amd64.go │ │ ├── blake2bAVX2_amd64.s │ │ ├── blake2b_amd64.s │ │ ├── blake2b_generic.go │ │ ├── blake2b_ref.go │ │ ├── blake2x.go │ │ └── register.go │ └── blowfish │ │ ├── block.go │ │ ├── cipher.go │ │ └── const.go │ └── sys │ ├── LICENSE │ ├── PATENTS │ └── cpu │ ├── asm_aix_ppc64.s │ ├── asm_darwin_x86_gc.s │ ├── byteorder.go │ ├── cpu.go │ ├── cpu_aix.go │ ├── cpu_arm.go │ ├── cpu_arm64.go │ ├── cpu_arm64.s │ ├── cpu_darwin_x86.go │ ├── cpu_gc_arm64.go │ ├── cpu_gc_s390x.go │ ├── cpu_gc_x86.go │ ├── cpu_gc_x86.s │ ├── cpu_gccgo_arm64.go │ ├── cpu_gccgo_s390x.go │ ├── cpu_gccgo_x86.c │ ├── cpu_gccgo_x86.go │ ├── cpu_linux.go │ ├── cpu_linux_arm.go │ ├── cpu_linux_arm64.go │ ├── cpu_linux_mips64x.go │ ├── cpu_linux_noinit.go │ ├── cpu_linux_ppc64x.go │ ├── cpu_linux_riscv64.go │ ├── cpu_linux_s390x.go │ ├── cpu_loong64.go │ ├── cpu_mips64x.go │ ├── cpu_mipsx.go │ ├── cpu_netbsd_arm64.go │ ├── cpu_openbsd_arm64.go │ ├── cpu_openbsd_arm64.s │ ├── cpu_other_arm.go │ ├── cpu_other_arm64.go │ ├── cpu_other_mips64x.go │ ├── cpu_other_ppc64x.go │ ├── cpu_other_riscv64.go │ ├── cpu_other_x86.go │ ├── cpu_ppc64x.go │ ├── cpu_riscv64.go │ ├── cpu_s390x.go │ ├── cpu_s390x.s │ ├── cpu_wasm.go │ ├── cpu_x86.go │ ├── cpu_zos.go │ ├── cpu_zos_s390x.go │ ├── endian_big.go │ ├── endian_little.go │ ├── hwcap_linux.go │ ├── parse.go │ ├── proc_cpuinfo_linux.go │ ├── runtime_auxv.go │ ├── runtime_auxv_go121.go │ ├── syscall_aix_gccgo.go │ ├── syscall_aix_ppc64_gc.go │ └── syscall_darwin_x86_gc.go ├── gopkg.in └── yaml.v3 │ ├── LICENSE │ ├── NOTICE │ ├── README.md │ ├── apic.go │ ├── decode.go │ ├── emitterc.go │ ├── encode.go │ ├── parserc.go │ ├── readerc.go │ ├── resolve.go │ ├── scannerc.go │ ├── sorter.go │ ├── writerc.go │ ├── yaml.go │ ├── yamlh.go │ └── yamlprivateh.go └── modules.txt /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # These owners will be the default owners for everything in the repo. 2 | # Unless a later match takes precedence, @umputun will be requested for 3 | # review when someone opens a pull request. 4 | 5 | * @umputun 6 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [umputun] 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "gomod" 9 | directory: "/" 10 | schedule: 11 | interval: "weekly" 12 | open-pull-requests-limit: 0 13 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: 6 | tags: 7 | pull_request: 8 | 9 | jobs: 10 | build: 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - name: set up go 1.22 15 | uses: actions/setup-go@v5 16 | with: 17 | go-version: "1.22" 18 | id: go 19 | 20 | - name: checkout 21 | uses: actions/checkout@v4 22 | 23 | - name: build and test 24 | run: | 25 | go test -timeout=60s -covermode=count -coverprofile=$GITHUB_WORKSPACE/profile.cov_tmp ./... 26 | cat $GITHUB_WORKSPACE/profile.cov_tmp | grep -v "mocks" > $GITHUB_WORKSPACE/profile.cov 27 | env: 28 | TZ: "America/Chicago" 29 | 30 | - name: golangci-lint 31 | uses: golangci/golangci-lint-action@v6 32 | with: 33 | version: v1.58 34 | 35 | - name: install goveralls 36 | run: go install github.com/mattn/goveralls@latest 37 | 38 | - name: submit coverage 39 | run: | 40 | goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov 41 | env: 42 | COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} 43 | 44 | - name: set up QEMU 45 | uses: docker/setup-qemu-action@v3 46 | 47 | - name: set up Docker Buildx 48 | id: buildx 49 | uses: docker/setup-buildx-action@v3 50 | 51 | - name: available platforms 52 | run: echo ${{ steps.buildx.outputs.platforms }} 53 | 54 | - name: build and deploy master image to ghcr.io and dockerhub 55 | if: ${{ github.ref == 'refs/heads/master' }} 56 | env: 57 | GITHUB_PACKAGE_TOKEN: ${{ secrets.PKG_TOKEN }} 58 | USERNAME: ${{ github.actor }} 59 | GITHUB_SHA: ${{ github.sha}} 60 | GITHUB_REF: ${{ github.ref}} 61 | run: | 62 | ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)" 63 | echo GITHUB_REF - $ref 64 | echo ${GITHUB_PACKAGE_TOKEN} | docker login ghcr.io -u ${USERNAME} --password-stdin 65 | docker buildx build --push \ 66 | --build-arg CI=github --build-arg GITHUB_SHA=${GITHUB_SHA} --build-arg GIT_BRANCH=${ref} \ 67 | --platform linux/amd64,linux/arm/v7,linux/arm64 \ 68 | -t ghcr.io/${USERNAME}/echo-http:latest . 69 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*' 7 | 8 | jobs: 9 | goreleaser: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: check out code 13 | uses: actions/checkout@v4 14 | 15 | - name: set up go 16 | uses: actions/setup-go@v5 17 | with: 18 | go-version: "1.22" 19 | 20 | - name: run goreleaser 21 | uses: goreleaser/goreleaser-action@v4 22 | with: 23 | version: ~> 1.25 24 | args: release --clean 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }} 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | dist/ 17 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | timeout: 5m 3 | 4 | linters-settings: 5 | govet: 6 | enable: 7 | - shadow 8 | goconst: 9 | min-len: 2 10 | min-occurrences: 2 11 | misspell: 12 | locale: US 13 | lll: 14 | line-length: 140 15 | gocritic: 16 | enabled-tags: 17 | - performance 18 | - style 19 | - experimental 20 | disabled-checks: 21 | - wrapperFunc 22 | - hugeParam 23 | - rangeValCopy 24 | - singleCaseSwitch 25 | - ifElseChain 26 | 27 | linters: 28 | enable: 29 | - revive 30 | - govet 31 | - unconvert 32 | - staticcheck 33 | - gosec 34 | - dupl 35 | - misspell 36 | - unused 37 | - typecheck 38 | - ineffassign 39 | - stylecheck 40 | - gochecknoinits 41 | - exportloopref 42 | - gocritic 43 | - nakedret 44 | - gosimple 45 | - prealloc 46 | fast: false 47 | disable-all: true 48 | 49 | issues: 50 | exclude-dirs: 51 | - vendor 52 | exclude-rules: 53 | - text: "package-comments: should have a package comment" 54 | linters: 55 | - revive 56 | - text: "at least one file in a package should have a package comment" 57 | linters: 58 | - stylecheck 59 | - text: "should have a package comment, unless it's in another file for this package" 60 | linters: 61 | - golint 62 | - path: _test\.go 63 | linters: 64 | - gosec 65 | - dupl 66 | exclude-use-default: false 67 | -------------------------------------------------------------------------------- /.goreleaser.yml: -------------------------------------------------------------------------------- 1 | project_name: echo-http 2 | dist: .bin 3 | builds: 4 | - id: echo-http 5 | binary: "echo-http" 6 | env: 7 | - CGO_ENABLED=0 8 | goos: 9 | - linux 10 | - darwin 11 | - windows 12 | goarch: 13 | - amd64 14 | - arm 15 | - arm64 16 | ignore: 17 | - goos: freebsd 18 | goarch: arm 19 | - goos: freebsd 20 | goarch: arm64 21 | - goos: windows 22 | goarch: arm 23 | - goos: windows 24 | goarch: arm64 25 | ldflags: "-s -w -X main.revision={{.Tag}}-{{.ShortCommit}}-{{.CommitDate}}" 26 | 27 | archives: 28 | - id: echo-http 29 | name_template: >- 30 | {{.ProjectName}}_ 31 | {{- .Tag}}_ 32 | {{- if eq .Os "darwin"}}macos 33 | {{- else if eq .Os "windows"}}win 34 | {{- else}}{{.Os}}{{end}}_ 35 | {{- if eq .Arch "amd64"}}x86_64 36 | {{- else if eq .Arch "386"}}i386 37 | {{- else}}{{.Arch}}{{end}} 38 | format_overrides: 39 | - goos: windows 40 | format: zip 41 | files: 42 | - LICENSE 43 | - README.md 44 | rlcp: true 45 | 46 | 47 | brews: 48 | - 49 | name: echo-http 50 | tap: 51 | owner: umputun 52 | name: homebrew-apps 53 | branch: master 54 | commit_author: 55 | name: umputun 56 | email: umputun@gmail.com 57 | commit_msg_template: "Brew formula update for {{ .ProjectName }} version {{ .Tag }}" 58 | homepage: "https://echo.umputun.com" 59 | description: "Responds with json-formatted echo of the incoming request and with a predefined message." 60 | license: "MIT" 61 | 62 | nfpms: 63 | - id: echo-http 64 | package_name: echo-http 65 | file_name_template: "{{.ProjectName}}_{{.Tag}}_{{.Os}}_{{.Arch}}" 66 | vendor: Umputun 67 | homepage: https://echo.umputun.com 68 | maintainer: Umputun 69 | description: Responds with json-formatted echo of the incoming request and with a predefined message 70 | license: MIT 71 | formats: 72 | - deb 73 | - rpm 74 | - apk 75 | bindir: /usr/bin 76 | epoch: 1 77 | release: 1 78 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.22-alpine as backend 2 | 3 | ARG GIT_BRANCH 4 | ARG GITHUB_SHA 5 | ARG CI 6 | 7 | ENV CGO_ENABLED=0 8 | 9 | ADD . /build 10 | WORKDIR /build 11 | 12 | RUN apk add --no-cache --update git tzdata ca-certificates 13 | 14 | RUN \ 15 | if [ -z "$CI" ] ; then \ 16 | echo "runs outside of CI" && version=$(git rev-parse --abbrev-ref HEAD)-$(git log -1 --format=%h)-$(date +%Y%m%dT%H:%M:%S); \ 17 | else version=${GIT_BRANCH}-${GITHUB_SHA:0:7}-$(date +%Y%m%dT%H:%M:%S); fi && \ 18 | echo "version=$version" && \ 19 | go build -o /build/echo-http -ldflags "-X main.revision=${version} -s -w" 20 | 21 | 22 | FROM scratch 23 | 24 | # enables automatic changelog generation by tools like Dependabot 25 | LABEL org.opencontainers.image.source="https://github.com/umputun/echo-http" 26 | 27 | COPY --from=backend /usr/share/zoneinfo /usr/share/zoneinfo 28 | COPY --from=backend /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ 29 | COPY --from=backend /build/echo-http /srv/echo-http 30 | 31 | EXPOSE 8080 32 | WORKDIR /srv 33 | ENTRYPOINT ["/srv/echo-http"] 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021-2024 Umputun 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | B=$(shell git rev-parse --abbrev-ref HEAD) 2 | BRANCH=$(subst /,-,$(B)) 3 | GITREV=$(shell git describe --abbrev=7 --always --tags) 4 | REV=$(GITREV)-$(BRANCH)-$(shell date +%Y%m%d-%H:%M:%S) 5 | 6 | docker: 7 | docker build -t umputun/echo-http . 8 | 9 | build: info 10 | - GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X main.revision=$(REV) -s -w" -o ./dist/echo-http 11 | 12 | info: 13 | - @echo "revision $(REV)" 14 | 15 | .PHONY: dist docker race_test bin info 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # echo-http - Echo http service 2 | 3 | Responds with json-formatted echo of the incoming request and with a predefined message. 4 | 5 | ## installation 6 | 7 | - The binary can be installed directly with go install: `go install github.com/umputun/echo-http@latest` 8 | - Can be downloaded from [releases](https://github.com/umputun/echo-http/releases) 9 | - For MacOS user can be installed with brew: `brew install umputun/apps/echo-http` 10 | - For docker there is a multi-arch docker container `ghcr.io/umputun/echo-http` 11 | 12 | 13 | ## usage 14 | 15 | Send any http request to the server, and it will respond with a json-formatted echo with all the things it knows about the request. 16 | 17 | ```sh 18 | http https://echo.umputun.com/something 19 | ``` 20 | 21 | ```json 22 | { 23 | "headers": { 24 | "Accept": "*/*", 25 | "Accept-Encoding": "gzip", 26 | "User-Agent": "HTTPie/2.4.0", 27 | "X-Forwarded-For": "12.12.12.12", 28 | "X-Forwarded-Host": "172.29.0.2:8080", 29 | "X-Origin-Host": "echo.umputun.com", 30 | "X-Real-Ip": "12.12.12.12" 31 | }, 32 | "host": "172.29.0.2:8080", 33 | "message": "echo echo 123", 34 | "remote_addr": "172.29.0.3:37432", 35 | "request": "GET /something" 36 | } 37 | ``` 38 | 39 | Alternatively, it can be run within cloudflare worker. In this case, the server will respond with the same echo. See [cf-worker.js](https://github.com/umputun/echo-http/blob/master/cf-worker.js) for details. The worker is available at `https://echo.umputun.dev/`. 40 | 41 | ```sh 42 | http https://echo.umputun.dev/aaaa 43 | ``` 44 | 45 | ```json 46 | { 47 | "headers": { 48 | "accept": "application/json, */*;q=0.5", 49 | "accept-encoding": "gzip, br", 50 | "connection": "Keep-Alive", 51 | "content-length": "15", 52 | "content-type": "application/json", 53 | "host": "echo.umputun.dev", 54 | "user-agent": "HTTPie/3.2.2", 55 | "x-forwarded-proto": "https" 56 | }, 57 | "host": "echo.umputun.dev", 58 | "message": "echo", 59 | "remote_addr": "50.123.44.200", 60 | "request": "POST /aaaa" 61 | } 62 | ``` 63 | 64 | ## Application options 65 | 66 | ``` 67 | -l, --listen= listen on host:port (default: 0.0.0.0:8080) [$LISTEN] 68 | -m, --message= response message (default: echo) [$MESSAGE] 69 | 70 | Help Options: 71 | -h, --help Show this help message 72 | ``` 73 | -------------------------------------------------------------------------------- /cf-worker.js: -------------------------------------------------------------------------------- 1 | // This is a simple Cloudflare Worker that echoes back the request details as a JSON response. 2 | // Replicates the same behavior provided in go code 3 | 4 | addEventListener("fetch", (event) => { 5 | event.respondWith(handleRequest(event.request)); 6 | }); 7 | 8 | async function handleRequest(request) { 9 | const url = new URL(request.url); 10 | const headers = {}; 11 | for (const [key, value] of request.headers) { 12 | if (!key.startsWith("cf-") && key !== "x-real-ip") { 13 | const normalizedKey = normalizeHeaderCase(key); 14 | headers[normalizedKey] = value; 15 | } 16 | } 17 | 18 | const echo = { 19 | message: "echo", 20 | request: `${request.method} ${url.pathname}${url.search}`, 21 | host: url.host, 22 | headers: headers, 23 | remote_addr: request.headers.get("x-real-ip") || "", 24 | }; 25 | 26 | return new Response(JSON.stringify(echo), { 27 | headers: { "Content-Type": "application/json" }, 28 | }); 29 | } 30 | 31 | function normalizeHeaderCase(header) { 32 | return header.split('-') 33 | .map(part => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()) 34 | .join('-'); 35 | } 36 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/umputun/echo-http 2 | 3 | go 1.22 4 | 5 | require ( 6 | github.com/go-pkgz/lgr v0.11.1 7 | github.com/go-pkgz/rest v1.20.2 8 | github.com/stretchr/testify v1.10.0 9 | github.com/umputun/go-flags v1.5.1 10 | ) 11 | 12 | require ( 13 | github.com/davecgh/go-spew v1.1.1 // indirect 14 | github.com/pmezard/go-difflib v1.0.0 // indirect 15 | golang.org/x/crypto v0.31.0 // indirect 16 | golang.org/x/sys v0.28.0 // indirect 17 | gopkg.in/yaml.v3 v3.0.1 // indirect 18 | ) 19 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 2 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 3 | github.com/go-pkgz/lgr v0.11.1 h1:hXFhZcznehI6imLhEa379oMOKFz7TQUmisAqb3oLOSM= 4 | github.com/go-pkgz/lgr v0.11.1/go.mod h1:tgDF4RXQnBfIgJqjgkv0yOeTQ3F1yewWIZkpUhHnAkU= 5 | github.com/go-pkgz/rest v1.20.2 h1:6wYWo85H7xFU09FadVKKc5LKIfIpCStBXJj9F/P4COc= 6 | github.com/go-pkgz/rest v1.20.2/go.mod h1:NC2xNN/y1rIs0PY13FowKoH8rk9RhJNJ0tTbkBg8Yks= 7 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 8 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 9 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 10 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 11 | github.com/umputun/go-flags v1.5.1 h1:vRauoXV3Ultt1HrxivSxowbintgZLJE+EcBy5ta3/mY= 12 | github.com/umputun/go-flags v1.5.1/go.mod h1:nTbvsO/hKqe7Utri/NoyN18GR3+EWf+9RrmsdwdhrEc= 13 | golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= 14 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 15 | golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= 16 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 17 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 18 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 19 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 20 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 21 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "errors" 6 | "fmt" 7 | "net/http" 8 | "os" 9 | "os/signal" 10 | "strings" 11 | "syscall" 12 | "time" 13 | 14 | log "github.com/go-pkgz/lgr" 15 | "github.com/go-pkgz/rest" 16 | "github.com/go-pkgz/rest/logger" 17 | "github.com/umputun/go-flags" 18 | ) 19 | 20 | var opts struct { 21 | Listen string `short:"l" long:"listen" env:"LISTEN" default:"0.0.0.0:8080" description:"listen on host:port"` 22 | Message string `short:"m" long:"message" env:"MESSAGE" default:"echo" description:"response message"` 23 | Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"` 24 | } 25 | 26 | var revision = "local" 27 | 28 | func main() { 29 | fmt.Printf("echo-http %s\n", revision) 30 | 31 | p := flags.NewParser(&opts, flags.PrintErrors|flags.PassDoubleDash|flags.HelpFlag) 32 | p.SubcommandsOptional = true 33 | if _, err := p.Parse(); err != nil { 34 | if err.(*flags.Error).Type != flags.ErrHelp { 35 | log.Printf("[ERROR] cli error: %v", err) 36 | } 37 | os.Exit(1) 38 | } 39 | setupLog(opts.Dbg) 40 | 41 | ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) 42 | defer cancel() 43 | if err := run(ctx); err != nil { 44 | if !errors.Is(err, http.ErrServerClosed) { 45 | log.Printf("[ERROR] server failed, %v", err) 46 | } else { 47 | log.Printf("[INFO] server stopped") 48 | } 49 | } 50 | } 51 | 52 | func run(ctx context.Context) error { 53 | 54 | router := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 55 | echo := struct { 56 | Message string `json:"message"` 57 | Request string `json:"request"` 58 | Host string `json:"host"` 59 | Headers map[string]string `json:"headers"` 60 | RemoteAddr string `json:"remote_addr"` 61 | }{ 62 | Message: opts.Message, 63 | Request: r.Method + " " + r.RequestURI, 64 | Host: r.Host, 65 | Headers: make(map[string]string), 66 | RemoteAddr: r.RemoteAddr, 67 | } 68 | 69 | for k, vv := range r.Header { 70 | echo.Headers[k] = strings.Join(vv, "; ") 71 | } 72 | 73 | rest.RenderJSON(w, &echo) 74 | }) 75 | 76 | restLogger := logger.New(logger.Log(log.Default()), logger.Prefix("[DEBUG]")) 77 | srv := http.Server{Addr: opts.Listen, 78 | Handler: rest.Wrap(router, rest.Recoverer(log.Default()), restLogger.Handler), 79 | ReadHeaderTimeout: time.Second * 30, 80 | WriteTimeout: time.Second * 30, 81 | IdleTimeout: time.Second * 30, 82 | } 83 | log.Printf("[INFO] starting server on %s", opts.Listen) 84 | 85 | go func() { 86 | <-ctx.Done() 87 | if err := srv.Shutdown(ctx); err != nil { 88 | log.Printf("[WARN] shutdown failed, %v", err) 89 | } 90 | }() 91 | 92 | return srv.ListenAndServe() 93 | } 94 | 95 | func setupLog(dbg bool) { 96 | if dbg { 97 | log.Setup(log.Debug, log.CallerFile, log.CallerFunc, log.Msec, log.LevelBraces) 98 | return 99 | } 100 | log.Setup(log.Msec, log.LevelBraces) 101 | } 102 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "encoding/json" 6 | "fmt" 7 | "io" 8 | "math/rand" 9 | "net/http" 10 | "testing" 11 | "time" 12 | 13 | "github.com/stretchr/testify/assert" 14 | "github.com/stretchr/testify/require" 15 | ) 16 | 17 | func TestRun(t *testing.T) { 18 | randomPort := rand.Intn(65535-1024) + 1024 19 | opts.Listen = fmt.Sprintf(":%d", randomPort) 20 | 21 | ctx, cancel := context.WithCancel(context.Background()) 22 | go run(ctx) 23 | time.Sleep(time.Millisecond * 500) 24 | defer cancel() 25 | 26 | testCases := []struct { 27 | name string 28 | method string 29 | endpoint string 30 | msg string 31 | headers map[string]string 32 | }{ 33 | {"GET root", "GET", "/", "Hello, World!", map[string]string{"X-Test": "true"}}, 34 | {"POST root", "POST", "/", "Post Message", map[string]string{"Authorization": "Bearer token"}}, 35 | {"GET no headers", "GET", "/", "Hello, No Headers!", map[string]string{}}, 36 | {"GET custom path", "GET", "/custom", "Hello, Custom Path!", map[string]string{"X-Custom": "true"}}, 37 | {"GET multiple headers", "GET", "/", "Hello, Multiple Headers!", 38 | map[string]string{"X-Header1": "value1", "X-Header2": "value2"}}, 39 | } 40 | 41 | for _, tc := range testCases { 42 | t.Run(tc.name, func(t *testing.T) { 43 | opts.Message = tc.msg 44 | 45 | client := &http.Client{} 46 | req, err := http.NewRequest(tc.method, fmt.Sprintf("http://localhost:%d%s", randomPort, tc.endpoint), http.NoBody) 47 | assert.NoError(t, err) 48 | 49 | for k, v := range tc.headers { 50 | req.Header.Set(k, v) 51 | } 52 | 53 | resp, err := client.Do(req) 54 | require.NoError(t, err) 55 | defer resp.Body.Close() 56 | 57 | body, err := io.ReadAll(resp.Body) 58 | require.NoError(t, err) 59 | 60 | var echoResp map[string]interface{} 61 | err = json.Unmarshal(body, &echoResp) 62 | require.NoError(t, err) 63 | 64 | assert.Equal(t, tc.msg, echoResp["message"]) 65 | assert.Equal(t, fmt.Sprintf("%s %s", tc.method, tc.endpoint), echoResp["request"]) 66 | assert.Equal(t, fmt.Sprintf("localhost:%d", randomPort), echoResp["host"]) 67 | 68 | for k, v := range tc.headers { 69 | assert.Equal(t, v, echoResp["headers"].(map[string]interface{})[k]) 70 | } 71 | 72 | assert.NotNil(t, echoResp["remote_addr"]) 73 | }) 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/LICENSE: -------------------------------------------------------------------------------- 1 | ISC License 2 | 3 | Copyright (c) 2012-2016 Dave Collins 4 | 5 | Permission to use, copy, modify, and/or distribute this software for any 6 | purpose with or without fee is hereby granted, provided that the above 7 | copyright notice and this permission notice appear in all copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypass.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is not running on Google App Engine, compiled by GopherJS, and 17 | // "-tags safe" is not added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // Go versions prior to 1.4 are disabled because they use a different layout 20 | // for interfaces which make the implementation of unsafeReflectValue more complex. 21 | // +build !js,!appengine,!safe,!disableunsafe,go1.4 22 | 23 | package spew 24 | 25 | import ( 26 | "reflect" 27 | "unsafe" 28 | ) 29 | 30 | const ( 31 | // UnsafeDisabled is a build-time constant which specifies whether or 32 | // not access to the unsafe package is available. 33 | UnsafeDisabled = false 34 | 35 | // ptrSize is the size of a pointer on the current arch. 36 | ptrSize = unsafe.Sizeof((*byte)(nil)) 37 | ) 38 | 39 | type flag uintptr 40 | 41 | var ( 42 | // flagRO indicates whether the value field of a reflect.Value 43 | // is read-only. 44 | flagRO flag 45 | 46 | // flagAddr indicates whether the address of the reflect.Value's 47 | // value may be taken. 48 | flagAddr flag 49 | ) 50 | 51 | // flagKindMask holds the bits that make up the kind 52 | // part of the flags field. In all the supported versions, 53 | // it is in the lower 5 bits. 54 | const flagKindMask = flag(0x1f) 55 | 56 | // Different versions of Go have used different 57 | // bit layouts for the flags type. This table 58 | // records the known combinations. 59 | var okFlags = []struct { 60 | ro, addr flag 61 | }{{ 62 | // From Go 1.4 to 1.5 63 | ro: 1 << 5, 64 | addr: 1 << 7, 65 | }, { 66 | // Up to Go tip. 67 | ro: 1<<5 | 1<<6, 68 | addr: 1 << 8, 69 | }} 70 | 71 | var flagValOffset = func() uintptr { 72 | field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") 73 | if !ok { 74 | panic("reflect.Value has no flag field") 75 | } 76 | return field.Offset 77 | }() 78 | 79 | // flagField returns a pointer to the flag field of a reflect.Value. 80 | func flagField(v *reflect.Value) *flag { 81 | return (*flag)(unsafe.Pointer(uintptr(unsafe.Pointer(v)) + flagValOffset)) 82 | } 83 | 84 | // unsafeReflectValue converts the passed reflect.Value into a one that bypasses 85 | // the typical safety restrictions preventing access to unaddressable and 86 | // unexported data. It works by digging the raw pointer to the underlying 87 | // value out of the protected value and generating a new unprotected (unsafe) 88 | // reflect.Value to it. 89 | // 90 | // This allows us to check for implementations of the Stringer and error 91 | // interfaces to be used for pretty printing ordinarily unaddressable and 92 | // inaccessible values such as unexported struct fields. 93 | func unsafeReflectValue(v reflect.Value) reflect.Value { 94 | if !v.IsValid() || (v.CanInterface() && v.CanAddr()) { 95 | return v 96 | } 97 | flagFieldPtr := flagField(&v) 98 | *flagFieldPtr &^= flagRO 99 | *flagFieldPtr |= flagAddr 100 | return v 101 | } 102 | 103 | // Sanity checks against future reflect package changes 104 | // to the type or semantics of the Value.flag field. 105 | func init() { 106 | field, ok := reflect.TypeOf(reflect.Value{}).FieldByName("flag") 107 | if !ok { 108 | panic("reflect.Value has no flag field") 109 | } 110 | if field.Type.Kind() != reflect.TypeOf(flag(0)).Kind() { 111 | panic("reflect.Value flag field has changed kind") 112 | } 113 | type t0 int 114 | var t struct { 115 | A t0 116 | // t0 will have flagEmbedRO set. 117 | t0 118 | // a will have flagStickyRO set 119 | a t0 120 | } 121 | vA := reflect.ValueOf(t).FieldByName("A") 122 | va := reflect.ValueOf(t).FieldByName("a") 123 | vt0 := reflect.ValueOf(t).FieldByName("t0") 124 | 125 | // Infer flagRO from the difference between the flags 126 | // for the (otherwise identical) fields in t. 127 | flagPublic := *flagField(&vA) 128 | flagWithRO := *flagField(&va) | *flagField(&vt0) 129 | flagRO = flagPublic ^ flagWithRO 130 | 131 | // Infer flagAddr from the difference between a value 132 | // taken from a pointer and not. 133 | vPtrA := reflect.ValueOf(&t).Elem().FieldByName("A") 134 | flagNoPtr := *flagField(&vA) 135 | flagPtr := *flagField(&vPtrA) 136 | flagAddr = flagNoPtr ^ flagPtr 137 | 138 | // Check that the inferred flags tally with one of the known versions. 139 | for _, f := range okFlags { 140 | if flagRO == f.ro && flagAddr == f.addr { 141 | return 142 | } 143 | } 144 | panic("reflect.Value read-only flag has changed semantics") 145 | } 146 | -------------------------------------------------------------------------------- /vendor/github.com/davecgh/go-spew/spew/bypasssafe.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2016 Dave Collins 2 | // 3 | // Permission to use, copy, modify, and distribute this software for any 4 | // purpose with or without fee is hereby granted, provided that the above 5 | // copyright notice and this permission notice appear in all copies. 6 | // 7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 10 | // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 12 | // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 | // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 | 15 | // NOTE: Due to the following build constraints, this file will only be compiled 16 | // when the code is running on Google App Engine, compiled by GopherJS, or 17 | // "-tags safe" is added to the go build command line. The "disableunsafe" 18 | // tag is deprecated and thus should not be used. 19 | // +build js appengine safe disableunsafe !go1.4 20 | 21 | package spew 22 | 23 | import "reflect" 24 | 25 | const ( 26 | // UnsafeDisabled is a build-time constant which specifies whether or 27 | // not access to the unsafe package is available. 28 | UnsafeDisabled = true 29 | ) 30 | 31 | // unsafeReflectValue typically converts the passed reflect.Value into a one 32 | // that bypasses the typical safety restrictions preventing access to 33 | // unaddressable and unexported data. However, doing this relies on access to 34 | // the unsafe package. This is a stub version which simply returns the passed 35 | // reflect.Value when the unsafe package is not available. 36 | func unsafeReflectValue(v reflect.Value) reflect.Value { 37 | return v 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | vendor 14 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/.golangci.yml: -------------------------------------------------------------------------------- 1 | linters-settings: 2 | govet: 3 | check-shadowing: true 4 | golint: 5 | min-confidence: 0 6 | gocyclo: 7 | min-complexity: 15 8 | maligned: 9 | suggest-new: true 10 | dupl: 11 | threshold: 100 12 | goconst: 13 | min-len: 2 14 | min-occurrences: 2 15 | misspell: 16 | locale: US 17 | lll: 18 | line-length: 140 19 | gocritic: 20 | enabled-tags: 21 | - performance 22 | - style 23 | - experimental 24 | disabled-checks: 25 | - wrapperFunc 26 | - hugeParam 27 | 28 | linters: 29 | enable: 30 | - megacheck 31 | - revive 32 | - govet 33 | - unconvert 34 | - megacheck 35 | - gas 36 | - gocyclo 37 | - dupl 38 | - misspell 39 | - unparam 40 | - unused 41 | - typecheck 42 | - ineffassign 43 | - stylecheck 44 | - gochecknoinits 45 | - exportloopref 46 | - gocritic 47 | - nakedret 48 | - gosimple 49 | - prealloc 50 | fast: false 51 | disable-all: true 52 | 53 | run: 54 | output: 55 | format: tab 56 | skip-dirs: 57 | - vendor 58 | 59 | issues: 60 | exclude-rules: 61 | - text: "should have a package comment, unless it's in another file for this package" 62 | linters: 63 | - golint 64 | - text: "at least one file in a package should have a package comment" 65 | linters: 66 | - stylecheck 67 | exclude-use-default: false 68 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Umputun 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/adaptor.go: -------------------------------------------------------------------------------- 1 | package lgr 2 | 3 | import ( 4 | "log" 5 | "strings" 6 | ) 7 | 8 | // Writer holds lgr.L and wraps with io.Writer interface 9 | type Writer struct { 10 | L 11 | level string // if defined added to each message 12 | } 13 | 14 | // Write to lgr.L 15 | func (w *Writer) Write(p []byte) (n int, err error) { 16 | w.Logf(w.level + string(p)) 17 | return len(p), nil 18 | } 19 | 20 | // ToWriter makes io.Writer for given lgr.L with optional level 21 | func ToWriter(l L, level string) *Writer { 22 | if level != "" && !strings.HasSuffix(level, " ") { 23 | level += " " 24 | } 25 | return &Writer{l, level} 26 | } 27 | 28 | // ToStdLogger makes standard logger 29 | func ToStdLogger(l L, level string) *log.Logger { 30 | return log.New(ToWriter(l, level), "", 0) 31 | } 32 | 33 | // SetupStdLogger makes the default std logger with lgr.L 34 | func SetupStdLogger(opts ...Option) { 35 | logOpts := append([]Option{CallerDepth(3)}, opts...) // skip 3 more frames to compensate stdlog calls 36 | l := New(logOpts...) 37 | l.reTrace = reTraceStd // std logger split on log/ path 38 | log.SetOutput(ToWriter(l, "")) 39 | log.SetPrefix("") 40 | log.SetFlags(0) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/interface.go: -------------------------------------------------------------------------------- 1 | package lgr 2 | 3 | import ( 4 | stdlog "log" 5 | ) 6 | 7 | var def = New() // default logger doesn't allow DEBUG and doesn't add caller info 8 | 9 | // L defines minimal interface used to log things 10 | type L interface { 11 | Logf(format string, args ...interface{}) 12 | } 13 | 14 | // Func type is an adapter to allow the use of ordinary functions as Logger. 15 | type Func func(format string, args ...interface{}) 16 | 17 | // Logf calls f(format, args...) 18 | func (f Func) Logf(format string, args ...interface{}) { f(format, args...) } 19 | 20 | // NoOp logger 21 | var NoOp = Func(func(format string, args ...interface{}) {}) 22 | 23 | // Std logger sends to std default logger directly 24 | var Std = Func(func(format string, args ...interface{}) { stdlog.Printf(format, args...) }) 25 | 26 | // Printf simplifies replacement of std logger 27 | func Printf(format string, args ...interface{}) { 28 | def.logf(format, args...) 29 | } 30 | 31 | // Print simplifies replacement of std logger 32 | func Print(line string) { 33 | def.logf(line) 34 | } 35 | 36 | // Fatalf simplifies replacement of std logger 37 | func Fatalf(format string, args ...interface{}) { 38 | def.logf(format, args...) 39 | def.fatal() 40 | } 41 | 42 | // Setup default logger with options 43 | func Setup(opts ...Option) { 44 | def = New(opts...) 45 | } 46 | 47 | // Default returns pre-constructed def logger (debug off, callers disabled) 48 | func Default() L { return def } 49 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/mapper.go: -------------------------------------------------------------------------------- 1 | package lgr 2 | 3 | // Mapper defines optional functions to change elements of the logged message for each part, based on levels. 4 | // Only some mapFunc can be defined, by default does nothing. Can be used to alter the output, for example making some 5 | // part of the output colorful. 6 | type Mapper struct { 7 | MessageFunc mapFunc // message mapper on all levels 8 | ErrorFunc mapFunc // message mapper on ERROR level 9 | WarnFunc mapFunc // message mapper on WARN level 10 | InfoFunc mapFunc // message mapper on INFO level 11 | DebugFunc mapFunc // message mapper on DEBUG level 12 | 13 | CallerFunc mapFunc // caller mapper, all levels 14 | TimeFunc mapFunc // time mapper, all levels 15 | } 16 | 17 | type mapFunc func(string) string 18 | 19 | // nopMapper is a default, doing nothing 20 | var nopMapper = Mapper{ 21 | MessageFunc: func(s string) string { return s }, 22 | ErrorFunc: func(s string) string { return s }, 23 | WarnFunc: func(s string) string { return s }, 24 | InfoFunc: func(s string) string { return s }, 25 | DebugFunc: func(s string) string { return s }, 26 | CallerFunc: func(s string) string { return s }, 27 | TimeFunc: func(s string) string { return s }, 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/lgr/options.go: -------------------------------------------------------------------------------- 1 | package lgr 2 | 3 | import ( 4 | "io" 5 | "strings" 6 | ) 7 | 8 | // Option func type 9 | type Option func(l *Logger) 10 | 11 | // Out sets output writer, stdout by default 12 | func Out(w io.Writer) Option { 13 | return func(l *Logger) { 14 | l.stdout = w 15 | } 16 | } 17 | 18 | // Err sets error writer, stderr by default 19 | func Err(w io.Writer) Option { 20 | return func(l *Logger) { 21 | l.stderr = w 22 | } 23 | } 24 | 25 | // Debug turn on dbg mode 26 | func Debug(l *Logger) { 27 | l.dbg = true 28 | } 29 | 30 | // Trace turn on trace + dbg mode 31 | func Trace(l *Logger) { 32 | l.dbg = true 33 | l.trace = true 34 | } 35 | 36 | // CallerDepth sets number of stack frame skipped for caller reporting, 0 by default 37 | func CallerDepth(n int) Option { 38 | return func(l *Logger) { 39 | l.callerDepth = n 40 | } 41 | } 42 | 43 | // Format sets output layout, overwrites all options for individual parts, i.e. Caller*, Msec and LevelBraces 44 | func Format(f string) Option { 45 | return func(l *Logger) { 46 | l.format = f 47 | } 48 | } 49 | 50 | // CallerFunc adds caller info with function name. Ignored if Format option used. 51 | func CallerFunc(l *Logger) { 52 | l.callerFunc = true 53 | } 54 | 55 | // CallerPkg adds caller's package name. Ignored if Format option used. 56 | func CallerPkg(l *Logger) { 57 | l.callerPkg = true 58 | } 59 | 60 | // LevelBraces surrounds level with [], i.e. [INFO]. Ignored if Format option used. 61 | func LevelBraces(l *Logger) { 62 | l.levelBraces = true 63 | } 64 | 65 | // CallerFile adds caller info with file, and line number. Ignored if Format option used. 66 | func CallerFile(l *Logger) { 67 | l.callerFile = true 68 | } 69 | 70 | // Msec adds .msec to timestamp. Ignored if Format option used. 71 | func Msec(l *Logger) { 72 | l.msec = true 73 | } 74 | 75 | // Secret sets list of substring to be hidden, i.e. replaced by "******" 76 | // Useful to prevent passwords or other sensitive tokens to be logged. 77 | func Secret(vals ...string) Option { 78 | return func(l *Logger) { 79 | for _, v := range vals { 80 | if strings.TrimSpace(v) == "" { 81 | continue // skip empty secrets 82 | } 83 | l.secrets = append(l.secrets, []byte(v)) 84 | } 85 | } 86 | } 87 | 88 | // Map sets mapper functions to change elements of the logged message based on levels. 89 | func Map(m Mapper) Option { 90 | return func(l *Logger) { 91 | l.mapper = m 92 | } 93 | } 94 | 95 | // StackTraceOnError turns on stack trace for ERROR level. 96 | func StackTraceOnError(l *Logger) { 97 | l.errorDump = true 98 | } 99 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | vendor -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/.golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | timeout: 5m 3 | tests: false 4 | 5 | linters-settings: 6 | govet: 7 | enable: 8 | - shadow 9 | goconst: 10 | min-len: 2 11 | min-occurrences: 2 12 | misspell: 13 | locale: US 14 | lll: 15 | line-length: 140 16 | gocritic: 17 | enabled-tags: 18 | - performance 19 | - style 20 | - experimental 21 | disabled-checks: 22 | - wrapperFunc 23 | - hugeParam 24 | - rangeValCopy 25 | - singleCaseSwitch 26 | - ifElseChain 27 | 28 | linters: 29 | enable: 30 | - revive 31 | - govet 32 | - unconvert 33 | - staticcheck 34 | - unused 35 | - gosec 36 | - dupl 37 | - misspell 38 | - unparam 39 | - typecheck 40 | - ineffassign 41 | - stylecheck 42 | - gochecknoinits 43 | - copyloopvar 44 | - gocritic 45 | - nakedret 46 | - gosimple 47 | - prealloc 48 | fast: false 49 | disable-all: true 50 | 51 | issues: 52 | exclude-dirs: 53 | - vendor 54 | exclude-rules: 55 | - text: "at least one file in a package should have a package comment" 56 | linters: 57 | - stylecheck 58 | - text: "should have a package comment" 59 | linters: 60 | - revive 61 | - path: _test\.go 62 | linters: 63 | - gosec 64 | - dupl 65 | exclude-use-default: false 66 | 67 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Umputun 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/blackwords.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net/http" 7 | "strings" 8 | ) 9 | 10 | // BlackWords middleware doesn't allow some words in the request body 11 | func BlackWords(words ...string) func(http.Handler) http.Handler { 12 | 13 | return func(h http.Handler) http.Handler { 14 | fn := func(w http.ResponseWriter, r *http.Request) { 15 | 16 | if content, err := io.ReadAll(r.Body); err == nil { 17 | body := strings.ToLower(string(content)) 18 | r.Body = io.NopCloser(bytes.NewReader(content)) 19 | 20 | if body != "" { 21 | for _, word := range words { 22 | if strings.Contains(body, strings.ToLower(word)) { 23 | w.WriteHeader(http.StatusForbidden) 24 | RenderJSON(w, JSON{"error": "one of blacklisted words detected"}) 25 | return 26 | } 27 | } 28 | } 29 | } 30 | h.ServeHTTP(w, r) 31 | } 32 | return http.HandlerFunc(fn) 33 | } 34 | } 35 | 36 | // BlackWordsFn middleware uses func to get the list and doesn't allow some words in the request body 37 | func BlackWordsFn(fn func() []string) func(http.Handler) http.Handler { 38 | return BlackWords(fn()...) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/cache_control.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "crypto/sha1" //nolint not used for cryptography 5 | "fmt" 6 | "net/http" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | // CacheControl is a middleware setting cache expiration. Using url+version for etag 12 | func CacheControl(expiration time.Duration, version string) func(http.Handler) http.Handler { 13 | 14 | etag := func(r *http.Request, version string) string { 15 | s := fmt.Sprintf("%s:%s", version, r.URL.String()) 16 | return fmt.Sprintf("%x", sha1.Sum([]byte(s))) //nolint 17 | } 18 | 19 | return func(h http.Handler) http.Handler { 20 | fn := func(w http.ResponseWriter, r *http.Request) { 21 | e := `"` + etag(r, version) + `"` 22 | w.Header().Set("Etag", e) 23 | w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, no-cache", int(expiration.Seconds()))) 24 | 25 | if match := r.Header.Get("If-None-Match"); match != "" { 26 | if strings.Contains(match, e) { 27 | w.WriteHeader(http.StatusNotModified) 28 | return 29 | } 30 | } 31 | h.ServeHTTP(w, r) 32 | } 33 | return http.HandlerFunc(fn) 34 | } 35 | } 36 | 37 | // CacheControlDynamic is a middleware setting cache expiration. Using url+ func(r) for etag 38 | func CacheControlDynamic(expiration time.Duration, versionFn func(r *http.Request) string) func(http.Handler) http.Handler { 39 | 40 | etag := func(r *http.Request, version string) string { 41 | s := fmt.Sprintf("%s:%s", version, r.URL.String()) 42 | return fmt.Sprintf("%x", sha1.Sum([]byte(s))) //nolint 43 | } 44 | 45 | return func(h http.Handler) http.Handler { 46 | fn := func(w http.ResponseWriter, r *http.Request) { 47 | 48 | e := `"` + etag(r, versionFn(r)) + `"` 49 | w.Header().Set("Etag", e) 50 | w.Header().Set("Cache-Control", fmt.Sprintf("max-age=%d, no-cache", int(expiration.Seconds()))) 51 | 52 | if match := r.Header.Get("If-None-Match"); match != "" { 53 | if strings.Contains(match, e) { 54 | w.WriteHeader(http.StatusNotModified) 55 | return 56 | } 57 | } 58 | h.ServeHTTP(w, r) 59 | } 60 | return http.HandlerFunc(fn) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/depricattion.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "time" 7 | ) 8 | 9 | // Deprecation adds a header 'Deprecation: version="version", date="date" header' 10 | // see https://tools.ietf.org/id/draft-dalal-deprecation-header-00.html 11 | func Deprecation(version string, date time.Time) func(http.Handler) http.Handler { 12 | f := func(h http.Handler) http.Handler { 13 | fn := func(w http.ResponseWriter, r *http.Request) { 14 | headerVal := fmt.Sprintf("version=%q, date=%q", version, date.Format(time.RFC3339)) 15 | w.Header().Set("Deprecation", headerVal) 16 | h.ServeHTTP(w, r) 17 | } 18 | return http.HandlerFunc(fn) 19 | } 20 | return f 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/gzip.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "compress/gzip" 5 | "io" 6 | "net/http" 7 | "strings" 8 | "sync" 9 | ) 10 | 11 | var gzDefaultContentTypes = []string{ 12 | "text/css", 13 | "text/javascript", 14 | "text/xml", 15 | "text/html", 16 | "text/plain", 17 | "application/javascript", 18 | "application/x-javascript", 19 | "application/json", 20 | } 21 | 22 | var gzPool = sync.Pool{ 23 | New: func() interface{} { return gzip.NewWriter(io.Discard) }, 24 | } 25 | 26 | type gzipResponseWriter struct { 27 | io.Writer 28 | http.ResponseWriter 29 | } 30 | 31 | func (w *gzipResponseWriter) WriteHeader(status int) { 32 | w.Header().Del("Content-Length") 33 | w.ResponseWriter.WriteHeader(status) 34 | } 35 | 36 | func (w *gzipResponseWriter) Write(b []byte) (int, error) { 37 | return w.Writer.Write(b) 38 | } 39 | 40 | // Gzip is a middleware compressing response 41 | func Gzip(contentTypes ...string) func(http.Handler) http.Handler { 42 | 43 | gzCts := gzDefaultContentTypes 44 | if len(contentTypes) > 0 { 45 | gzCts = contentTypes 46 | } 47 | 48 | contentType := func(r *http.Request) string { 49 | result := r.Header.Get("Content-type") 50 | if result == "" { 51 | return "application/octet-stream" 52 | } 53 | return result 54 | } 55 | 56 | f := func(next http.Handler) http.Handler { 57 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 58 | if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { 59 | next.ServeHTTP(w, r) 60 | return 61 | } 62 | 63 | var gzOk bool 64 | ctype := contentType(r) 65 | for _, c := range gzCts { 66 | if strings.HasPrefix(strings.ToLower(ctype), strings.ToLower(c)) { 67 | gzOk = true 68 | break 69 | } 70 | } 71 | 72 | if !gzOk { 73 | next.ServeHTTP(w, r) 74 | return 75 | } 76 | 77 | w.Header().Set("Content-Encoding", "gzip") 78 | gz := gzPool.Get().(*gzip.Writer) 79 | defer gzPool.Put(gz) 80 | 81 | gz.Reset(w) 82 | defer gz.Close() 83 | 84 | next.ServeHTTP(&gzipResponseWriter{ResponseWriter: w, Writer: gz}, r) 85 | }) 86 | } 87 | return f 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/httperrors.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "net/http" 7 | "net/url" 8 | "runtime" 9 | "strings" 10 | 11 | "github.com/go-pkgz/rest/logger" 12 | ) 13 | 14 | // ErrorLogger wraps logger.Backend 15 | type ErrorLogger struct { 16 | l logger.Backend 17 | } 18 | 19 | // NewErrorLogger creates ErrorLogger for given Backend 20 | func NewErrorLogger(l logger.Backend) *ErrorLogger { 21 | return &ErrorLogger{l: l} 22 | } 23 | 24 | // Log sends json error message {error: msg} with error code and logging error and caller 25 | func (e *ErrorLogger) Log(w http.ResponseWriter, r *http.Request, httpCode int, err error, msg ...string) { 26 | m := "" 27 | if len(msg) > 0 { 28 | m = strings.Join(msg, ". ") 29 | } 30 | if e.l != nil { 31 | e.l.Logf("%s", errDetailsMsg(r, httpCode, err, m)) 32 | } 33 | renderJSONWithStatus(w, JSON{"error": m}, httpCode) 34 | } 35 | 36 | // SendErrorJSON sends {error: msg} with error code and logging error and caller 37 | func SendErrorJSON(w http.ResponseWriter, r *http.Request, l logger.Backend, code int, err error, msg string) { 38 | if l != nil { 39 | l.Logf("%s", errDetailsMsg(r, code, err, msg)) 40 | } 41 | renderJSONWithStatus(w, JSON{"error": msg}, code) 42 | } 43 | 44 | func errDetailsMsg(r *http.Request, code int, err error, msg string) string { 45 | 46 | q := r.URL.String() 47 | if qun, e := url.QueryUnescape(q); e == nil { 48 | q = qun 49 | } 50 | 51 | srcFileInfo := "" 52 | if pc, file, line, ok := runtime.Caller(2); ok { 53 | fnameElems := strings.Split(file, "/") 54 | funcNameElems := strings.Split(runtime.FuncForPC(pc).Name(), "/") 55 | srcFileInfo = fmt.Sprintf(" [caused by %s:%d %s]", strings.Join(fnameElems[len(fnameElems)-3:], "/"), 56 | line, funcNameElems[len(funcNameElems)-1]) 57 | } 58 | 59 | remoteIP := r.RemoteAddr 60 | if pos := strings.Index(remoteIP, ":"); pos >= 0 { 61 | remoteIP = remoteIP[:pos] 62 | } 63 | if err == nil { 64 | err = errors.New("no error") 65 | } 66 | return fmt.Sprintf("%s - %v - %d - %s - %s%s", msg, err, code, remoteIP, q, srcFileInfo) 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/logger/options.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | // Option func type 8 | type Option func(l *Middleware) 9 | 10 | // WithBody triggers request body logging. Body size is limited (default 1k) 11 | func WithBody(l *Middleware) { 12 | l.logBody = true 13 | } 14 | 15 | // MaxBodySize sets size of the logged part of the request body. 16 | func MaxBodySize(maximum int) Option { 17 | return func(l *Middleware) { 18 | if maximum >= 0 { 19 | l.maxBodySize = maximum 20 | } 21 | } 22 | } 23 | 24 | // Prefix sets log line prefix. 25 | func Prefix(prefix string) Option { 26 | return func(l *Middleware) { 27 | l.prefix = prefix 28 | } 29 | } 30 | 31 | // IPfn sets IP masking function. If ipFn is nil then IP address will be logged as is. 32 | func IPfn(ipFn func(ip string) string) Option { 33 | return func(l *Middleware) { 34 | l.ipFn = ipFn 35 | } 36 | } 37 | 38 | // UserFn triggers user name logging if userFn is not nil. 39 | func UserFn(userFn func(r *http.Request) (string, error)) Option { 40 | return func(l *Middleware) { 41 | l.userFn = userFn 42 | } 43 | } 44 | 45 | // SubjFn triggers subject logging if subjFn is not nil. 46 | func SubjFn(subjFn func(r *http.Request) (string, error)) Option { 47 | return func(l *Middleware) { 48 | l.subjFn = subjFn 49 | } 50 | } 51 | 52 | // ApacheCombined sets format to Apache Combined Log. 53 | // See http://httpd.apache.org/docs/2.2/logs.html#combined 54 | func ApacheCombined(l *Middleware) { 55 | l.apacheCombined = true 56 | } 57 | 58 | // Log sets logging backend. 59 | func Log(log Backend) Option { 60 | return func(l *Middleware) { 61 | l.log = log 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/metrics.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "expvar" 5 | "fmt" 6 | "net/http" 7 | "strings" 8 | ) 9 | 10 | // Metrics responds to GET /metrics with list of expvar 11 | func Metrics(onlyIps ...string) func(http.Handler) http.Handler { 12 | return func(h http.Handler) http.Handler { 13 | fn := func(w http.ResponseWriter, r *http.Request) { 14 | if r.Method == "GET" && strings.HasSuffix(strings.ToLower(r.URL.Path), "/metrics") { 15 | if matched, ip, err := matchSourceIP(r, onlyIps); !matched || err != nil { 16 | w.WriteHeader(http.StatusForbidden) 17 | RenderJSON(w, JSON{"error": fmt.Sprintf("ip %s rejected", ip)}) 18 | return 19 | } 20 | expvar.Handler().ServeHTTP(w, r) 21 | return 22 | } 23 | h.ServeHTTP(w, r) 24 | } 25 | 26 | return http.HandlerFunc(fn) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/nocache.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "net/http" 5 | "time" 6 | ) 7 | 8 | // borrowed from https://github.com/go-chi/chi/blob/master/middleware/nocache.go 9 | 10 | var epoch = time.Unix(0, 0).UTC().Format(time.RFC1123) 11 | 12 | var noCacheHeaders = map[string]string{ 13 | "Expires": epoch, 14 | "Cache-Control": "no-cache, no-store, no-transform, must-revalidate, private, max-age=0", 15 | "Pragma": "no-cache", 16 | "X-Accel-Expires": "0", 17 | } 18 | 19 | var etagHeaders = []string{ 20 | "ETag", 21 | "If-Modified-Since", 22 | "If-Match", 23 | "If-None-Match", 24 | "If-Range", 25 | "If-Unmodified-Since", 26 | } 27 | 28 | // NoCache is a simple piece of middleware that sets a number of HTTP headers to prevent 29 | // a router (or subrouter) from being cached by an upstream proxy and/or client. 30 | // 31 | // As per http://wiki.nginx.org/HttpProxyModule - NoCache sets: 32 | // Expires: Thu, 01 Jan 1970 00:00:00 UTC 33 | // Cache-Control: no-cache, private, max-age=0 34 | // X-Accel-Expires: 0 35 | // Pragma: no-cache (for HTTP/1.0 proxies/clients) 36 | func NoCache(h http.Handler) http.Handler { 37 | fn := func(w http.ResponseWriter, r *http.Request) { 38 | 39 | // Delete any ETag headers that may have been set 40 | for _, v := range etagHeaders { 41 | if r.Header.Get(v) != "" { 42 | r.Header.Del(v) 43 | } 44 | } 45 | 46 | // Set our NoCache headers 47 | for k, v := range noCacheHeaders { 48 | w.Header().Set(k, v) 49 | } 50 | 51 | h.ServeHTTP(w, r) 52 | } 53 | 54 | return http.HandlerFunc(fn) 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/onlyfrom.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "net/http" 7 | "strings" 8 | 9 | "github.com/go-pkgz/rest/realip" 10 | ) 11 | 12 | // OnlyFrom middleware allows access for limited list of source IPs. 13 | // Such IPs can be defined as complete ip (like 192.168.1.12), prefix (129.168.) or CIDR (192.168.0.0/16) 14 | func OnlyFrom(onlyIps ...string) func(http.Handler) http.Handler { 15 | return func(h http.Handler) http.Handler { 16 | fn := func(w http.ResponseWriter, r *http.Request) { 17 | if len(onlyIps) == 0 { 18 | // no restrictions if no ips defined 19 | h.ServeHTTP(w, r) 20 | return 21 | } 22 | matched, ip, err := matchSourceIP(r, onlyIps) 23 | if err != nil { 24 | w.WriteHeader(http.StatusInternalServerError) 25 | RenderJSON(w, JSON{"error": fmt.Sprintf("can't get realip: %s", err)}) 26 | return 27 | } 28 | if matched { 29 | // matched ip - allow 30 | h.ServeHTTP(w, r) 31 | return 32 | } 33 | 34 | w.WriteHeader(http.StatusForbidden) 35 | RenderJSON(w, JSON{"error": fmt.Sprintf("ip %q rejected", ip)}) 36 | } 37 | return http.HandlerFunc(fn) 38 | } 39 | } 40 | 41 | // matchSourceIP returns true if request's ip matches any of ips 42 | func matchSourceIP(r *http.Request, ips []string) (result bool, match string, err error) { 43 | ip, err := realip.Get(r) 44 | if err != nil { 45 | return false, "", fmt.Errorf("can't get realip: %w", err) // we can't get ip, so no match 46 | } 47 | // check for ip prefix or CIDR 48 | for _, exclIP := range ips { 49 | if _, cidrnet, err := net.ParseCIDR(exclIP); err == nil { 50 | if cidrnet.Contains(net.ParseIP(ip)) { 51 | return true, ip, nil 52 | } 53 | } 54 | if strings.HasPrefix(ip, exclIP) { 55 | return true, ip, nil 56 | } 57 | } 58 | return false, ip, nil 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/profiler.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "expvar" 5 | "fmt" 6 | "net/http" 7 | "net/http/pprof" 8 | ) 9 | 10 | // Profiler is a convenient subrouter used for mounting net/http/pprof. ie. 11 | // 12 | // func MyService() http.Handler { 13 | // r := chi.NewRouter() 14 | // // ..middlewares 15 | // r.Mount("/debug", middleware.Profiler()) 16 | // // ..routes 17 | // return r 18 | // } 19 | func Profiler(onlyIps ...string) http.Handler { 20 | mux := http.NewServeMux() 21 | mux.HandleFunc("/pprof/", pprof.Index) 22 | mux.HandleFunc("/pprof/cmdline", pprof.Cmdline) 23 | mux.HandleFunc("/pprof/profile", pprof.Profile) 24 | mux.HandleFunc("/pprof/symbol", pprof.Symbol) 25 | mux.HandleFunc("/pprof/trace", pprof.Trace) 26 | mux.Handle("/pprof/block", pprof.Handler("block")) 27 | mux.Handle("/pprof/heap", pprof.Handler("heap")) 28 | mux.Handle("/pprof/goroutine", pprof.Handler("goroutine")) 29 | mux.Handle("/pprof/threadcreate", pprof.Handler("threadcreate")) 30 | mux.HandleFunc("/vars", expVars) 31 | 32 | return Wrap(mux, NoCache, OnlyFrom(onlyIps...)) 33 | } 34 | 35 | // expVars copied from stdlib expvar.go as is not public. 36 | func expVars(w http.ResponseWriter, _ *http.Request) { 37 | first := true 38 | w.Header().Set("Content-Type", "application/json") 39 | fmt.Fprintf(w, "{\n") 40 | expvar.Do(func(kv expvar.KeyValue) { 41 | if !first { 42 | fmt.Fprintf(w, ",\n") 43 | } 44 | first = false 45 | fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) 46 | }) 47 | fmt.Fprintf(w, "\n}\n") 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/realip/real.go: -------------------------------------------------------------------------------- 1 | // Package realip extracts a real IP address from the request. 2 | package realip 3 | 4 | import ( 5 | "bytes" 6 | "fmt" 7 | "net" 8 | "net/http" 9 | "strings" 10 | ) 11 | 12 | type ipRange struct { 13 | start net.IP 14 | end net.IP 15 | } 16 | 17 | // privateRanges contains the list of private and special-use IP ranges. 18 | // reference: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml 19 | var privateRanges = []ipRange{ 20 | // IPv4 Private Ranges 21 | {start: net.ParseIP("10.0.0.0"), end: net.ParseIP("10.255.255.255")}, 22 | {start: net.ParseIP("172.16.0.0"), end: net.ParseIP("172.31.255.255")}, 23 | {start: net.ParseIP("192.168.0.0"), end: net.ParseIP("192.168.255.255")}, 24 | // IPv4 Link-Local 25 | {start: net.ParseIP("169.254.0.0"), end: net.ParseIP("169.254.255.255")}, 26 | // IPv4 Shared Address Space (RFC 6598) 27 | {start: net.ParseIP("100.64.0.0"), end: net.ParseIP("100.127.255.255")}, 28 | // IPv4 Benchmarking (RFC 2544) 29 | {start: net.ParseIP("198.18.0.0"), end: net.ParseIP("198.19.255.255")}, 30 | // IPv6 Unique Local Addresses (ULA) 31 | {start: net.ParseIP("fc00::"), end: net.ParseIP("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")}, 32 | // IPv6 Link-local Addresses 33 | {start: net.ParseIP("fe80::"), end: net.ParseIP("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")}, 34 | } 35 | 36 | // Get returns real ip from the given request 37 | // Prioritize public IPs over private IPs 38 | func Get(r *http.Request) (string, error) { 39 | var firstIP string 40 | for _, h := range []string{"X-Forwarded-For", "X-Real-Ip"} { 41 | addresses := strings.Split(r.Header.Get(h), ",") 42 | for i := len(addresses) - 1; i >= 0; i-- { 43 | ip := strings.TrimSpace(addresses[i]) 44 | realIP := net.ParseIP(ip) 45 | if firstIP == "" && realIP != nil { 46 | firstIP = ip 47 | } 48 | if !realIP.IsGlobalUnicast() || isPrivateSubnet(realIP) { 49 | continue 50 | } 51 | return ip, nil 52 | } 53 | } 54 | 55 | if firstIP != "" { 56 | return firstIP, nil 57 | } 58 | 59 | ip, _, err := net.SplitHostPort(r.RemoteAddr) 60 | if err != nil { 61 | return "", fmt.Errorf("can't parse ip %q: %w", r.RemoteAddr, err) 62 | } 63 | if netIP := net.ParseIP(ip); netIP == nil { 64 | return "", fmt.Errorf("no valid ip found") 65 | } 66 | 67 | return ip, nil 68 | } 69 | 70 | // isPrivateSubnet - check to see if this ip is in a private subnet 71 | func isPrivateSubnet(ipAddress net.IP) bool { 72 | 73 | // inRange - check to see if a given ip address is within a range given 74 | inRange := func(r ipRange, ipAddress net.IP) bool { 75 | // ensure the IPs are in the same format for comparison 76 | ipAddress = ipAddress.To16() 77 | r.start = r.start.To16() 78 | r.end = r.end.To16() 79 | return bytes.Compare(ipAddress, r.start) >= 0 && bytes.Compare(ipAddress, r.end) <= 0 80 | } 81 | 82 | for _, r := range privateRanges { 83 | if inRange(r, ipAddress) { 84 | return true 85 | } 86 | } 87 | return false 88 | } 89 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/rest.go: -------------------------------------------------------------------------------- 1 | // Package rest provides common middlewares and helpers for rest services 2 | package rest 3 | 4 | import ( 5 | "bytes" 6 | "encoding/json" 7 | "fmt" 8 | "net/http" 9 | "time" 10 | ) 11 | 12 | // JSON is a map alias, just for convenience 13 | type JSON map[string]any 14 | 15 | // RenderJSON sends data as json 16 | func RenderJSON(w http.ResponseWriter, data interface{}) { 17 | buf := &bytes.Buffer{} 18 | enc := json.NewEncoder(buf) 19 | enc.SetEscapeHTML(true) 20 | if err := enc.Encode(data); err != nil { 21 | http.Error(w, err.Error(), http.StatusInternalServerError) 22 | return 23 | } 24 | w.Header().Set("Content-Type", "application/json; charset=utf-8") 25 | _, _ = w.Write(buf.Bytes()) 26 | } 27 | 28 | // RenderJSONFromBytes sends binary data as json 29 | func RenderJSONFromBytes(w http.ResponseWriter, r *http.Request, data []byte) error { 30 | w.Header().Set("Content-Type", "application/json; charset=utf-8") 31 | if _, err := w.Write(data); err != nil { 32 | return fmt.Errorf("failed to send response to %s: %w", r.RemoteAddr, err) 33 | } 34 | return nil 35 | } 36 | 37 | // RenderJSONWithHTML allows html tags and forces charset=utf-8 38 | func RenderJSONWithHTML(w http.ResponseWriter, r *http.Request, v interface{}) error { 39 | 40 | encodeJSONWithHTML := func(v interface{}) ([]byte, error) { 41 | buf := &bytes.Buffer{} 42 | enc := json.NewEncoder(buf) 43 | enc.SetEscapeHTML(false) 44 | if err := enc.Encode(v); err != nil { 45 | return nil, fmt.Errorf("json encoding failed: %w", err) 46 | } 47 | return buf.Bytes(), nil 48 | } 49 | 50 | data, err := encodeJSONWithHTML(v) 51 | if err != nil { 52 | return err 53 | } 54 | return RenderJSONFromBytes(w, r, data) 55 | } 56 | 57 | // renderJSONWithStatus sends data as json and enforces status code 58 | func renderJSONWithStatus(w http.ResponseWriter, data interface{}, code int) { 59 | buf := &bytes.Buffer{} 60 | enc := json.NewEncoder(buf) 61 | enc.SetEscapeHTML(true) 62 | if err := enc.Encode(data); err != nil { 63 | http.Error(w, err.Error(), http.StatusInternalServerError) 64 | return 65 | } 66 | w.Header().Set("Content-Type", "application/json; charset=utf-8") 67 | w.WriteHeader(code) 68 | _, _ = w.Write(buf.Bytes()) 69 | } 70 | 71 | // ParseFromTo parses from and to query params of the request 72 | func ParseFromTo(r *http.Request) (from, to time.Time, err error) { 73 | parseTimeStamp := func(ts string) (time.Time, error) { 74 | formats := []string{ 75 | "2006-01-02T15:04:05.000000000", 76 | "2006-01-02T15:04:05", 77 | "2006-01-02T15:04", 78 | "20060102", 79 | time.RFC3339, 80 | time.RFC3339Nano, 81 | } 82 | 83 | for _, f := range formats { 84 | if t, e := time.Parse(f, ts); e == nil { 85 | return t, nil 86 | } 87 | } 88 | return time.Time{}, fmt.Errorf("can't parse date %q", ts) 89 | } 90 | 91 | if from, err = parseTimeStamp(r.URL.Query().Get("from")); err != nil { 92 | return from, to, fmt.Errorf("incorrect from time: %w", err) 93 | } 94 | 95 | if to, err = parseTimeStamp(r.URL.Query().Get("to")); err != nil { 96 | return from, to, fmt.Errorf("incorrect to time: %w", err) 97 | } 98 | return from, to, nil 99 | } 100 | 101 | // DecodeJSON decodes json request from http.Request to given type 102 | func DecodeJSON[T any](r *http.Request, res *T) error { 103 | if err := json.NewDecoder(r.Body).Decode(&res); err != nil { 104 | return fmt.Errorf("decode json: %w", err) 105 | } 106 | return nil 107 | } 108 | 109 | // EncodeJSON encodes given type to http.ResponseWriter and sets status code and content type header 110 | func EncodeJSON[T any](w http.ResponseWriter, status int, v T) error { 111 | w.Header().Set("Content-Type", "application/json; charset=utf-8") 112 | w.WriteHeader(status) 113 | if err := json.NewEncoder(w).Encode(v); err != nil { 114 | return fmt.Errorf("encode json: %w", err) 115 | } 116 | return nil 117 | } 118 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/rewrite.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "net/url" 7 | "path" 8 | "regexp" 9 | "strings" 10 | ) 11 | 12 | // Rewrite middleware with from->to rule. Supports regex (like nginx) and prevents multiple rewrites 13 | // example: Rewrite(`^/sites/(.*)/settings/$`, `/sites/settings/$1` 14 | func Rewrite(from, to string) func(http.Handler) http.Handler { 15 | reFrom := regexp.MustCompile(from) 16 | 17 | f := func(next http.Handler) http.Handler { 18 | fn := func(w http.ResponseWriter, r *http.Request) { 19 | 20 | ctx := r.Context() 21 | 22 | // prevent double rewrites 23 | if ctx != nil { 24 | if _, ok := ctx.Value(contextKey("rewrite")).(bool); ok { 25 | next.ServeHTTP(w, r) 26 | return 27 | } 28 | } 29 | 30 | if !reFrom.MatchString(r.URL.Path) { 31 | next.ServeHTTP(w, r) 32 | return 33 | } 34 | 35 | ru := reFrom.ReplaceAllString(r.URL.Path, to) 36 | cru := path.Clean(ru) 37 | if strings.HasSuffix(ru, "/") { // don't drop trailing slash 38 | cru += "/" 39 | } 40 | u, e := url.Parse(cru) 41 | if e != nil { 42 | w.WriteHeader(http.StatusInternalServerError) 43 | return 44 | } 45 | r.Header.Set("X-Original-URL", r.URL.RequestURI()) 46 | r.URL.Path = u.Path 47 | r.URL.RawPath = u.RawPath 48 | if u.RawQuery != "" { 49 | r.URL.RawQuery = u.RawQuery 50 | } 51 | ctx = context.WithValue(ctx, contextKey("rewrite"), true) 52 | next.ServeHTTP(w, r.WithContext(ctx)) 53 | } 54 | return http.HandlerFunc(fn) 55 | } 56 | return f 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/sizelimit.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "bytes" 5 | "io" 6 | "net/http" 7 | ) 8 | 9 | // SizeLimit middleware checks if body size is above the limit and returns StatusRequestEntityTooLarge (413) 10 | func SizeLimit(size int64) func(http.Handler) http.Handler { 11 | 12 | return func(h http.Handler) http.Handler { 13 | 14 | fn := func(w http.ResponseWriter, r *http.Request) { 15 | 16 | // check ContentLength 17 | if r.ContentLength > size { 18 | w.WriteHeader(http.StatusRequestEntityTooLarge) 19 | return 20 | } 21 | 22 | // check size of the actual body 23 | content, err := io.ReadAll(io.LimitReader(r.Body, size+1)) 24 | if err != nil { 25 | w.WriteHeader(http.StatusServiceUnavailable) 26 | return 27 | } 28 | _ = r.Body.Close() // the original body already consumed 29 | 30 | if int64(len(content)) > size { 31 | w.WriteHeader(http.StatusRequestEntityTooLarge) 32 | return 33 | } 34 | r.Body = io.NopCloser(bytes.NewReader(content)) 35 | h.ServeHTTP(w, r) 36 | } 37 | 38 | return http.HandlerFunc(fn) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/throttle.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | // Throttle middleware checks how many request in-fly and rejects with 503 if exceeded 8 | func Throttle(limit int64) func(http.Handler) http.Handler { 9 | 10 | ch := make(chan struct{}, limit) 11 | return func(h http.Handler) http.Handler { 12 | 13 | fn := func(w http.ResponseWriter, r *http.Request) { 14 | 15 | if limit <= 0 { 16 | h.ServeHTTP(w, r) 17 | return 18 | } 19 | 20 | var acquired bool 21 | defer func() { 22 | if !acquired { 23 | return 24 | } 25 | select { 26 | case <-ch: 27 | return 28 | default: 29 | return 30 | } 31 | }() 32 | 33 | select { 34 | case ch <- struct{}{}: 35 | acquired = true 36 | h.ServeHTTP(w, r) 37 | return 38 | default: 39 | w.WriteHeader(http.StatusServiceUnavailable) 40 | return 41 | } 42 | } 43 | 44 | return http.HandlerFunc(fn) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/go-pkgz/rest/trace.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "context" 5 | "crypto/rand" 6 | "crypto/sha1" //nolint:gosec //not used for cryptography 7 | "encoding/hex" 8 | "fmt" 9 | "net/http" 10 | "time" 11 | ) 12 | 13 | type contextKey string 14 | 15 | const traceHeader = "X-Request-ID" 16 | 17 | // Trace looks for header X-Request-ID and makes it as random id if not found, then populates it to the result's header 18 | // and to request context 19 | func Trace(next http.Handler) http.Handler { 20 | fn := func(w http.ResponseWriter, r *http.Request) { 21 | traceID := r.Header.Get(traceHeader) 22 | if traceID == "" { 23 | traceID = randToken() 24 | } 25 | w.Header().Set(traceHeader, traceID) 26 | ctx := context.WithValue(r.Context(), contextKey("requestID"), traceID) 27 | r = r.WithContext(ctx) 28 | next.ServeHTTP(w, r) 29 | } 30 | return http.HandlerFunc(fn) 31 | } 32 | 33 | // GetTraceID returns request id from the context 34 | func GetTraceID(r *http.Request) string { 35 | if id, ok := r.Context().Value(contextKey("requestID")).(string); ok { 36 | return id 37 | } 38 | return "" 39 | } 40 | 41 | func randToken() string { 42 | b := make([]byte, 32) 43 | if _, err := rand.Read(b); err != nil { 44 | return fmt.Sprintf("%x", time.Now().Nanosecond()) 45 | } 46 | sum := sha1.Sum(b) //nolint:gosec //not used for cryptography 47 | return hex.EncodeToString(sum[:]) 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/pmezard/go-difflib/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Patrick Mezard 2 | 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 copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | The names of its contributors may not be used to endorse or promote 14 | products derived from this software without specific prior written 15 | permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 18 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 20 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 23 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2012-2020 Mat Ryer, Tyler Bunnell and contributors. 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_format.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentFormat}} 2 | func {{.DocInfo.Name}}f(t TestingT, {{.ParamsFormat}}) bool { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(t, {{.ForwardedParamsFormat}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) bool { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | return {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/assertion_order.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | // isOrdered checks that collection contains orderable elements. 9 | func isOrdered(t TestingT, object interface{}, allowedComparesResults []compareResult, failMessage string, msgAndArgs ...interface{}) bool { 10 | objKind := reflect.TypeOf(object).Kind() 11 | if objKind != reflect.Slice && objKind != reflect.Array { 12 | return false 13 | } 14 | 15 | objValue := reflect.ValueOf(object) 16 | objLen := objValue.Len() 17 | 18 | if objLen <= 1 { 19 | return true 20 | } 21 | 22 | value := objValue.Index(0) 23 | valueInterface := value.Interface() 24 | firstValueKind := value.Kind() 25 | 26 | for i := 1; i < objLen; i++ { 27 | prevValue := value 28 | prevValueInterface := valueInterface 29 | 30 | value = objValue.Index(i) 31 | valueInterface = value.Interface() 32 | 33 | compareResult, isComparable := compare(prevValueInterface, valueInterface, firstValueKind) 34 | 35 | if !isComparable { 36 | return Fail(t, fmt.Sprintf("Can not compare type \"%s\" and \"%s\"", reflect.TypeOf(value), reflect.TypeOf(prevValue)), msgAndArgs...) 37 | } 38 | 39 | if !containsValue(allowedComparesResults, compareResult) { 40 | return Fail(t, fmt.Sprintf(failMessage, prevValue, value), msgAndArgs...) 41 | } 42 | } 43 | 44 | return true 45 | } 46 | 47 | // IsIncreasing asserts that the collection is increasing 48 | // 49 | // assert.IsIncreasing(t, []int{1, 2, 3}) 50 | // assert.IsIncreasing(t, []float{1, 2}) 51 | // assert.IsIncreasing(t, []string{"a", "b"}) 52 | func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 53 | return isOrdered(t, object, []compareResult{compareLess}, "\"%v\" is not less than \"%v\"", msgAndArgs...) 54 | } 55 | 56 | // IsNonIncreasing asserts that the collection is not increasing 57 | // 58 | // assert.IsNonIncreasing(t, []int{2, 1, 1}) 59 | // assert.IsNonIncreasing(t, []float{2, 1}) 60 | // assert.IsNonIncreasing(t, []string{"b", "a"}) 61 | func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 62 | return isOrdered(t, object, []compareResult{compareEqual, compareGreater}, "\"%v\" is not greater than or equal to \"%v\"", msgAndArgs...) 63 | } 64 | 65 | // IsDecreasing asserts that the collection is decreasing 66 | // 67 | // assert.IsDecreasing(t, []int{2, 1, 0}) 68 | // assert.IsDecreasing(t, []float{2, 1}) 69 | // assert.IsDecreasing(t, []string{"b", "a"}) 70 | func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 71 | return isOrdered(t, object, []compareResult{compareGreater}, "\"%v\" is not greater than \"%v\"", msgAndArgs...) 72 | } 73 | 74 | // IsNonDecreasing asserts that the collection is not decreasing 75 | // 76 | // assert.IsNonDecreasing(t, []int{1, 1, 2}) 77 | // assert.IsNonDecreasing(t, []float{1, 2}) 78 | // assert.IsNonDecreasing(t, []string{"a", "b"}) 79 | func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { 80 | return isOrdered(t, object, []compareResult{compareLess, compareEqual}, "\"%v\" is not less than or equal to \"%v\"", msgAndArgs...) 81 | } 82 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/doc.go: -------------------------------------------------------------------------------- 1 | // Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. 2 | // 3 | // # Example Usage 4 | // 5 | // The following is a complete example using assert in a standard test function: 6 | // 7 | // import ( 8 | // "testing" 9 | // "github.com/stretchr/testify/assert" 10 | // ) 11 | // 12 | // func TestSomething(t *testing.T) { 13 | // 14 | // var a string = "Hello" 15 | // var b string = "Hello" 16 | // 17 | // assert.Equal(t, a, b, "The two words should be the same.") 18 | // 19 | // } 20 | // 21 | // if you assert many times, use the format below: 22 | // 23 | // import ( 24 | // "testing" 25 | // "github.com/stretchr/testify/assert" 26 | // ) 27 | // 28 | // func TestSomething(t *testing.T) { 29 | // assert := assert.New(t) 30 | // 31 | // var a string = "Hello" 32 | // var b string = "Hello" 33 | // 34 | // assert.Equal(a, b, "The two words should be the same.") 35 | // } 36 | // 37 | // # Assertions 38 | // 39 | // Assertions allow you to easily write test code, and are global funcs in the `assert` package. 40 | // All assertion functions take, as the first argument, the `*testing.T` object provided by the 41 | // testing framework. This allows the assertion funcs to write the failings and other details to 42 | // the correct place. 43 | // 44 | // Every assertion function also takes an optional string message as the final argument, 45 | // allowing custom error messages to be appended to the message the assertion method outputs. 46 | package assert 47 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/errors.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | // AnError is an error instance useful for testing. If the code does not care 8 | // about error specifics, and only needs to return the error for example, this 9 | // error should be used to make the test code more readable. 10 | var AnError = errors.New("assert.AnError general error for testing") 11 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/forward_assertions.go: -------------------------------------------------------------------------------- 1 | package assert 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=assert -template=assertion_forward.go.tmpl -include-format-funcs" 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/yaml/yaml_custom.go: -------------------------------------------------------------------------------- 1 | //go:build testify_yaml_custom && !testify_yaml_fail && !testify_yaml_default 2 | // +build testify_yaml_custom,!testify_yaml_fail,!testify_yaml_default 3 | 4 | // Package yaml is an implementation of YAML functions that calls a pluggable implementation. 5 | // 6 | // This implementation is selected with the testify_yaml_custom build tag. 7 | // 8 | // go test -tags testify_yaml_custom 9 | // 10 | // This implementation can be used at build time to replace the default implementation 11 | // to avoid linking with [gopkg.in/yaml.v3]. 12 | // 13 | // In your test package: 14 | // 15 | // import assertYaml "github.com/stretchr/testify/assert/yaml" 16 | // 17 | // func init() { 18 | // assertYaml.Unmarshal = func (in []byte, out interface{}) error { 19 | // // ... 20 | // return nil 21 | // } 22 | // } 23 | package yaml 24 | 25 | var Unmarshal func(in []byte, out interface{}) error 26 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/yaml/yaml_default.go: -------------------------------------------------------------------------------- 1 | //go:build !testify_yaml_fail && !testify_yaml_custom 2 | // +build !testify_yaml_fail,!testify_yaml_custom 3 | 4 | // Package yaml is just an indirection to handle YAML deserialization. 5 | // 6 | // This package is just an indirection that allows the builder to override the 7 | // indirection with an alternative implementation of this package that uses 8 | // another implementation of YAML deserialization. This allows to not either not 9 | // use YAML deserialization at all, or to use another implementation than 10 | // [gopkg.in/yaml.v3] (for example for license compatibility reasons, see [PR #1120]). 11 | // 12 | // Alternative implementations are selected using build tags: 13 | // 14 | // - testify_yaml_fail: [Unmarshal] always fails with an error 15 | // - testify_yaml_custom: [Unmarshal] is a variable. Caller must initialize it 16 | // before calling any of [github.com/stretchr/testify/assert.YAMLEq] or 17 | // [github.com/stretchr/testify/assert.YAMLEqf]. 18 | // 19 | // Usage: 20 | // 21 | // go test -tags testify_yaml_fail 22 | // 23 | // You can check with "go list" which implementation is linked: 24 | // 25 | // go list -f '{{.Imports}}' github.com/stretchr/testify/assert/yaml 26 | // go list -tags testify_yaml_fail -f '{{.Imports}}' github.com/stretchr/testify/assert/yaml 27 | // go list -tags testify_yaml_custom -f '{{.Imports}}' github.com/stretchr/testify/assert/yaml 28 | // 29 | // [PR #1120]: https://github.com/stretchr/testify/pull/1120 30 | package yaml 31 | 32 | import goyaml "gopkg.in/yaml.v3" 33 | 34 | // Unmarshal is just a wrapper of [gopkg.in/yaml.v3.Unmarshal]. 35 | func Unmarshal(in []byte, out interface{}) error { 36 | return goyaml.Unmarshal(in, out) 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/assert/yaml/yaml_fail.go: -------------------------------------------------------------------------------- 1 | //go:build testify_yaml_fail && !testify_yaml_custom && !testify_yaml_default 2 | // +build testify_yaml_fail,!testify_yaml_custom,!testify_yaml_default 3 | 4 | // Package yaml is an implementation of YAML functions that always fail. 5 | // 6 | // This implementation can be used at build time to replace the default implementation 7 | // to avoid linking with [gopkg.in/yaml.v3]: 8 | // 9 | // go test -tags testify_yaml_fail 10 | package yaml 11 | 12 | import "errors" 13 | 14 | var errNotImplemented = errors.New("YAML functions are not available (see https://pkg.go.dev/github.com/stretchr/testify/assert/yaml)") 15 | 16 | func Unmarshal([]byte, interface{}) error { 17 | return errNotImplemented 18 | } 19 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/doc.go: -------------------------------------------------------------------------------- 1 | // Package require implements the same assertions as the `assert` package but 2 | // stops test execution when a test fails. 3 | // 4 | // # Example Usage 5 | // 6 | // The following is a complete example using require in a standard test function: 7 | // 8 | // import ( 9 | // "testing" 10 | // "github.com/stretchr/testify/require" 11 | // ) 12 | // 13 | // func TestSomething(t *testing.T) { 14 | // 15 | // var a string = "Hello" 16 | // var b string = "Hello" 17 | // 18 | // require.Equal(t, a, b, "The two words should be the same.") 19 | // 20 | // } 21 | // 22 | // # Assertions 23 | // 24 | // The `require` package have same global functions as in the `assert` package, 25 | // but instead of returning a boolean result they call `t.FailNow()`. 26 | // 27 | // Every assertion function also takes an optional string message as the final argument, 28 | // allowing custom error messages to be appended to the message the assertion method outputs. 29 | package require 30 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/forward_requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // Assertions provides assertion methods around the 4 | // TestingT interface. 5 | type Assertions struct { 6 | t TestingT 7 | } 8 | 9 | // New makes a new Assertions object for the specified TestingT. 10 | func New(t TestingT) *Assertions { 11 | return &Assertions{ 12 | t: t, 13 | } 14 | } 15 | 16 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=require -template=require_forward.go.tmpl -include-format-funcs" 17 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require.go.tmpl: -------------------------------------------------------------------------------- 1 | {{ replace .Comment "assert." "require."}} 2 | func {{.DocInfo.Name}}(t TestingT, {{.Params}}) { 3 | if h, ok := t.(tHelper); ok { h.Helper() } 4 | if assert.{{.DocInfo.Name}}(t, {{.ForwardedParams}}) { return } 5 | t.FailNow() 6 | } 7 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/require_forward.go.tmpl: -------------------------------------------------------------------------------- 1 | {{.CommentWithoutT "a"}} 2 | func (a *Assertions) {{.DocInfo.Name}}({{.Params}}) { 3 | if h, ok := a.t.(tHelper); ok { h.Helper() } 4 | {{.DocInfo.Name}}(a.t, {{.ForwardedParams}}) 5 | } 6 | -------------------------------------------------------------------------------- /vendor/github.com/stretchr/testify/require/requirements.go: -------------------------------------------------------------------------------- 1 | package require 2 | 3 | // TestingT is an interface wrapper around *testing.T 4 | type TestingT interface { 5 | Errorf(format string, args ...interface{}) 6 | FailNow() 7 | } 8 | 9 | type tHelper = interface { 10 | Helper() 11 | } 12 | 13 | // ComparisonAssertionFunc is a common function prototype when comparing two values. Can be useful 14 | // for table driven tests. 15 | type ComparisonAssertionFunc func(TestingT, interface{}, interface{}, ...interface{}) 16 | 17 | // ValueAssertionFunc is a common function prototype when validating a single value. Can be useful 18 | // for table driven tests. 19 | type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) 20 | 21 | // BoolAssertionFunc is a common function prototype when validating a bool value. Can be useful 22 | // for table driven tests. 23 | type BoolAssertionFunc func(TestingT, bool, ...interface{}) 24 | 25 | // ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful 26 | // for table driven tests. 27 | type ErrorAssertionFunc func(TestingT, error, ...interface{}) 28 | 29 | //go:generate sh -c "cd ../_codegen && go build && cd - && ../_codegen/_codegen -output-package=require -template=require.go.tmpl -include-format-funcs" 30 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | os: 4 | - linux 5 | - osx 6 | 7 | go: 8 | - 1.x 9 | - 1.9.x 10 | - 1.10.x 11 | 12 | install: 13 | # go-flags 14 | - go get -d -v ./... 15 | - go build -v ./... 16 | 17 | # linting 18 | - go get -v golang.org/x/lint/golint 19 | 20 | # code coverage 21 | - go get golang.org/x/tools/cmd/cover 22 | - go get github.com/onsi/ginkgo/ginkgo 23 | - go get github.com/modocache/gover 24 | - if [ "$TRAVIS_SECURE_ENV_VARS" = "true" ]; then go get github.com/mattn/goveralls; fi 25 | 26 | script: 27 | # go-flags 28 | - $(exit $(gofmt -l . | wc -l)) 29 | - go test -v ./... 30 | 31 | # linting 32 | - go tool vet -all=true -v=true . || true 33 | - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/golint ./... 34 | 35 | # code coverage 36 | - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/ginkgo -r -cover 37 | - $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/gover 38 | - if [ "$TRAVIS_SECURE_ENV_VARS" = "true" ]; then $(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls -coverprofile=gover.coverprofile -service=travis-ci -repotoken $COVERALLS_TOKEN; fi 39 | 40 | env: 41 | # coveralls.io 42 | secure: "RCYbiB4P0RjQRIoUx/vG/AjP3mmYCbzOmr86DCww1Z88yNcy3hYr3Cq8rpPtYU5v0g7wTpu4adaKIcqRE9xknYGbqj3YWZiCoBP1/n4Z+9sHW3Dsd9D/GRGeHUus0laJUGARjWoCTvoEtOgTdGQDoX7mH+pUUY0FBltNYUdOiiU=" 43 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Jesse van den Kieboom. All rights reserved. 2 | Redistribution and use in source and binary forms, with or without 3 | modification, are permitted provided that the following conditions are 4 | met: 5 | 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above 9 | copyright notice, this list of conditions and the following disclaimer 10 | in the documentation and/or other materials provided with the 11 | distribution. 12 | * Neither the name of Google Inc. nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/arg.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "reflect" 5 | ) 6 | 7 | // Arg represents a positional argument on the command line. 8 | type Arg struct { 9 | // The name of the positional argument (used in the help) 10 | Name string 11 | 12 | // A description of the positional argument (used in the help) 13 | Description string 14 | 15 | // The minimal number of required positional arguments 16 | Required int 17 | 18 | // The maximum number of required positional arguments 19 | RequiredMaximum int 20 | 21 | value reflect.Value 22 | tag multiTag 23 | } 24 | 25 | func (a *Arg) isRemaining() bool { 26 | return a.value.Type().Kind() == reflect.Slice 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/check_crosscompile.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | echo '# linux arm7' 6 | GOARM=7 GOARCH=arm GOOS=linux go build 7 | echo '# linux arm5' 8 | GOARM=5 GOARCH=arm GOOS=linux go build 9 | echo '# windows 386' 10 | GOARCH=386 GOOS=windows go build 11 | echo '# windows amd64' 12 | GOARCH=amd64 GOOS=windows go build 13 | echo '# darwin' 14 | GOARCH=amd64 GOOS=darwin go build 15 | echo '# freebsd' 16 | GOARCH=amd64 GOOS=freebsd go build 17 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/closest.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | func levenshtein(s string, t string) int { 4 | if len(s) == 0 { 5 | return len(t) 6 | } 7 | 8 | if len(t) == 0 { 9 | return len(s) 10 | } 11 | 12 | dists := make([][]int, len(s)+1) 13 | for i := range dists { 14 | dists[i] = make([]int, len(t)+1) 15 | dists[i][0] = i 16 | } 17 | 18 | for j := range t { 19 | dists[0][j] = j 20 | } 21 | 22 | for i, sc := range s { 23 | for j, tc := range t { 24 | if sc == tc { 25 | dists[i+1][j+1] = dists[i][j] 26 | } else { 27 | dists[i+1][j+1] = dists[i][j] + 1 28 | if dists[i+1][j] < dists[i+1][j+1] { 29 | dists[i+1][j+1] = dists[i+1][j] + 1 30 | } 31 | if dists[i][j+1] < dists[i+1][j+1] { 32 | dists[i+1][j+1] = dists[i][j+1] + 1 33 | } 34 | } 35 | } 36 | } 37 | 38 | return dists[len(s)][len(t)] 39 | } 40 | 41 | func closestChoice(cmd string, choices []string) (string, int) { 42 | if len(choices) == 0 { 43 | return "", 0 44 | } 45 | 46 | mincmd := -1 47 | mindist := -1 48 | 49 | for i, c := range choices { 50 | l := levenshtein(cmd, c) 51 | 52 | if mincmd < 0 || l < mindist { 53 | mindist = l 54 | mincmd = i 55 | } 56 | } 57 | 58 | return choices[mincmd], mindist 59 | } 60 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/error.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // ErrorType represents the type of error. 8 | type ErrorType uint 9 | 10 | const ( 11 | // ErrUnknown indicates a generic error. 12 | ErrUnknown ErrorType = iota 13 | 14 | // ErrExpectedArgument indicates that an argument was expected. 15 | ErrExpectedArgument 16 | 17 | // ErrUnknownFlag indicates an unknown flag. 18 | ErrUnknownFlag 19 | 20 | // ErrUnknownGroup indicates an unknown group. 21 | ErrUnknownGroup 22 | 23 | // ErrMarshal indicates a marshalling error while converting values. 24 | ErrMarshal 25 | 26 | // ErrHelp indicates that the built-in help was shown (the error 27 | // contains the help message). 28 | ErrHelp 29 | 30 | // ErrNoArgumentForBool indicates that an argument was given for a 31 | // boolean flag (which don't not take any arguments). 32 | ErrNoArgumentForBool 33 | 34 | // ErrRequired indicates that a required flag was not provided. 35 | ErrRequired 36 | 37 | // ErrShortNameTooLong indicates that a short flag name was specified, 38 | // longer than one character. 39 | ErrShortNameTooLong 40 | 41 | // ErrDuplicatedFlag indicates that a short or long flag has been 42 | // defined more than once 43 | ErrDuplicatedFlag 44 | 45 | // ErrTag indicates an error while parsing flag tags. 46 | ErrTag 47 | 48 | // ErrCommandRequired indicates that a command was required but not 49 | // specified 50 | ErrCommandRequired 51 | 52 | // ErrUnknownCommand indicates that an unknown command was specified. 53 | ErrUnknownCommand 54 | 55 | // ErrInvalidChoice indicates an invalid option value which only allows 56 | // a certain number of choices. 57 | ErrInvalidChoice 58 | 59 | // ErrInvalidTag indicates an invalid tag or invalid use of an existing tag 60 | ErrInvalidTag 61 | ) 62 | 63 | func (e ErrorType) String() string { 64 | switch e { 65 | case ErrUnknown: 66 | return "unknown" 67 | case ErrExpectedArgument: 68 | return "expected argument" 69 | case ErrUnknownFlag: 70 | return "unknown flag" 71 | case ErrUnknownGroup: 72 | return "unknown group" 73 | case ErrMarshal: 74 | return "marshal" 75 | case ErrHelp: 76 | return "help" 77 | case ErrNoArgumentForBool: 78 | return "no argument for bool" 79 | case ErrRequired: 80 | return "required" 81 | case ErrShortNameTooLong: 82 | return "short name too long" 83 | case ErrDuplicatedFlag: 84 | return "duplicated flag" 85 | case ErrTag: 86 | return "tag" 87 | case ErrCommandRequired: 88 | return "command required" 89 | case ErrUnknownCommand: 90 | return "unknown command" 91 | case ErrInvalidChoice: 92 | return "invalid choice" 93 | case ErrInvalidTag: 94 | return "invalid tag" 95 | } 96 | 97 | return "unrecognized error type" 98 | } 99 | 100 | // Error represents a parser error. The error returned from Parse is of this 101 | // type. The error contains both a Type and Message. 102 | type Error struct { 103 | // The type of error 104 | Type ErrorType 105 | 106 | // The error message 107 | Message string 108 | } 109 | 110 | // Error returns the error's message 111 | func (e *Error) Error() string { 112 | return e.Message 113 | } 114 | 115 | func newError(tp ErrorType, message string) *Error { 116 | return &Error{ 117 | Type: tp, 118 | Message: message, 119 | } 120 | } 121 | 122 | func newErrorf(tp ErrorType, format string, args ...interface{}) *Error { 123 | return newError(tp, fmt.Sprintf(format, args...)) 124 | } 125 | 126 | func wrapError(err error) *Error { 127 | ret, ok := err.(*Error) 128 | 129 | if !ok { 130 | return newError(ErrUnknown, err.Error()) 131 | } 132 | 133 | return ret 134 | } 135 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/multitag.go: -------------------------------------------------------------------------------- 1 | package flags 2 | 3 | import ( 4 | "strconv" 5 | ) 6 | 7 | type multiTag struct { 8 | value string 9 | cache map[string][]string 10 | } 11 | 12 | func newMultiTag(v string) multiTag { 13 | return multiTag{ 14 | value: v, 15 | } 16 | } 17 | 18 | func (x *multiTag) scan() (map[string][]string, error) { 19 | v := x.value 20 | 21 | ret := make(map[string][]string) 22 | 23 | // This is mostly copied from reflect.StructTag.Get 24 | for v != "" { 25 | i := 0 26 | 27 | // Skip whitespace 28 | for i < len(v) && v[i] == ' ' { 29 | i++ 30 | } 31 | 32 | v = v[i:] 33 | 34 | if v == "" { 35 | break 36 | } 37 | 38 | // Scan to colon to find key 39 | i = 0 40 | 41 | for i < len(v) && v[i] != ' ' && v[i] != ':' && v[i] != '"' { 42 | i++ 43 | } 44 | 45 | if i >= len(v) { 46 | return nil, newErrorf(ErrTag, "expected `:' after key name, but got end of tag (in `%v`)", x.value) 47 | } 48 | 49 | if v[i] != ':' { 50 | return nil, newErrorf(ErrTag, "expected `:' after key name, but got `%v' (in `%v`)", v[i], x.value) 51 | } 52 | 53 | if i+1 >= len(v) { 54 | return nil, newErrorf(ErrTag, "expected `\"' to start tag value at end of tag (in `%v`)", x.value) 55 | } 56 | 57 | if v[i+1] != '"' { 58 | return nil, newErrorf(ErrTag, "expected `\"' to start tag value, but got `%v' (in `%v`)", v[i+1], x.value) 59 | } 60 | 61 | name := v[:i] 62 | v = v[i+1:] 63 | 64 | // Scan quoted string to find value 65 | i = 1 66 | 67 | for i < len(v) && v[i] != '"' { 68 | if v[i] == '\n' { 69 | return nil, newErrorf(ErrTag, "unexpected newline in tag value `%v' (in `%v`)", name, x.value) 70 | } 71 | 72 | if v[i] == '\\' { 73 | i++ 74 | } 75 | i++ 76 | } 77 | 78 | if i >= len(v) { 79 | return nil, newErrorf(ErrTag, "expected end of tag value `\"' at end of tag (in `%v`)", x.value) 80 | } 81 | 82 | val, err := strconv.Unquote(v[:i+1]) 83 | 84 | if err != nil { 85 | return nil, newErrorf(ErrTag, "Malformed value of tag `%v:%v` => %v (in `%v`)", name, v[:i+1], err, x.value) 86 | } 87 | 88 | v = v[i+1:] 89 | 90 | ret[name] = append(ret[name], val) 91 | } 92 | 93 | return ret, nil 94 | } 95 | 96 | func (x *multiTag) Parse() error { 97 | vals, err := x.scan() 98 | x.cache = vals 99 | 100 | return err 101 | } 102 | 103 | func (x *multiTag) cached() map[string][]string { 104 | if x.cache == nil { 105 | cache, _ := x.scan() 106 | 107 | if cache == nil { 108 | cache = make(map[string][]string) 109 | } 110 | 111 | x.cache = cache 112 | } 113 | 114 | return x.cache 115 | } 116 | 117 | func (x *multiTag) Get(key string) string { 118 | c := x.cached() 119 | 120 | if v, ok := c[key]; ok { 121 | return v[len(v)-1] 122 | } 123 | 124 | return "" 125 | } 126 | 127 | func (x *multiTag) GetMany(key string) []string { 128 | c := x.cached() 129 | return c[key] 130 | } 131 | 132 | func (x *multiTag) Set(key string, value string) { 133 | c := x.cached() 134 | c[key] = []string{value} 135 | } 136 | 137 | func (x *multiTag) SetMany(key string, value []string) { 138 | c := x.cached() 139 | c[key] = value 140 | } 141 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/optstyle_other.go: -------------------------------------------------------------------------------- 1 | // +build !windows forceposix 2 | 3 | package flags 4 | 5 | import ( 6 | "strings" 7 | ) 8 | 9 | const ( 10 | defaultShortOptDelimiter = '-' 11 | defaultLongOptDelimiter = "--" 12 | defaultNameArgDelimiter = '=' 13 | ) 14 | 15 | func argumentStartsOption(arg string) bool { 16 | return len(arg) > 0 && arg[0] == '-' 17 | } 18 | 19 | func argumentIsOption(arg string) bool { 20 | if len(arg) > 1 && arg[0] == '-' && arg[1] != '-' { 21 | return true 22 | } 23 | 24 | if len(arg) > 2 && arg[0] == '-' && arg[1] == '-' && arg[2] != '-' { 25 | return true 26 | } 27 | 28 | return false 29 | } 30 | 31 | // stripOptionPrefix returns the option without the prefix and whether or 32 | // not the option is a long option or not. 33 | func stripOptionPrefix(optname string) (prefix string, name string, islong bool) { 34 | if strings.HasPrefix(optname, "--") { 35 | return "--", optname[2:], true 36 | } else if strings.HasPrefix(optname, "-") { 37 | return "-", optname[1:], false 38 | } 39 | 40 | return "", optname, false 41 | } 42 | 43 | // splitOption attempts to split the passed option into a name and an argument. 44 | // When there is no argument specified, nil will be returned for it. 45 | func splitOption(prefix string, option string, islong bool) (string, string, *string) { 46 | pos := strings.Index(option, "=") 47 | 48 | if (islong && pos >= 0) || (!islong && pos == 1) { 49 | rest := option[pos+1:] 50 | return option[:pos], "=", &rest 51 | } 52 | 53 | return option, "", nil 54 | } 55 | 56 | // addHelpGroup adds a new group that contains default help parameters. 57 | func (c *Command) addHelpGroup(showHelp func() error) *Group { 58 | var help struct { 59 | ShowHelp func() error `short:"h" long:"help" description:"Show this help message"` 60 | } 61 | 62 | help.ShowHelp = showHelp 63 | ret, _ := c.AddGroup("Help Options", "", &help) 64 | ret.isBuiltinHelp = true 65 | 66 | return ret 67 | } 68 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/optstyle_windows.go: -------------------------------------------------------------------------------- 1 | // +build !forceposix 2 | 3 | package flags 4 | 5 | import ( 6 | "strings" 7 | ) 8 | 9 | // Windows uses a front slash for both short and long options. Also it uses 10 | // a colon for name/argument delimter. 11 | const ( 12 | defaultShortOptDelimiter = '/' 13 | defaultLongOptDelimiter = "/" 14 | defaultNameArgDelimiter = ':' 15 | ) 16 | 17 | func argumentStartsOption(arg string) bool { 18 | return len(arg) > 0 && (arg[0] == '-' || arg[0] == '/') 19 | } 20 | 21 | func argumentIsOption(arg string) bool { 22 | // Windows-style options allow front slash for the option 23 | // delimiter. 24 | if len(arg) > 1 && arg[0] == '/' { 25 | return true 26 | } 27 | 28 | if len(arg) > 1 && arg[0] == '-' && arg[1] != '-' { 29 | return true 30 | } 31 | 32 | if len(arg) > 2 && arg[0] == '-' && arg[1] == '-' && arg[2] != '-' { 33 | return true 34 | } 35 | 36 | return false 37 | } 38 | 39 | // stripOptionPrefix returns the option without the prefix and whether or 40 | // not the option is a long option or not. 41 | func stripOptionPrefix(optname string) (prefix string, name string, islong bool) { 42 | // Determine if the argument is a long option or not. Windows 43 | // typically supports both long and short options with a single 44 | // front slash as the option delimiter, so handle this situation 45 | // nicely. 46 | possplit := 0 47 | 48 | if strings.HasPrefix(optname, "--") { 49 | possplit = 2 50 | islong = true 51 | } else if strings.HasPrefix(optname, "-") { 52 | possplit = 1 53 | islong = false 54 | } else if strings.HasPrefix(optname, "/") { 55 | possplit = 1 56 | islong = len(optname) > 2 57 | } 58 | 59 | return optname[:possplit], optname[possplit:], islong 60 | } 61 | 62 | // splitOption attempts to split the passed option into a name and an argument. 63 | // When there is no argument specified, nil will be returned for it. 64 | func splitOption(prefix string, option string, islong bool) (string, string, *string) { 65 | if len(option) == 0 { 66 | return option, "", nil 67 | } 68 | 69 | // Windows typically uses a colon for the option name and argument 70 | // delimiter while POSIX typically uses an equals. Support both styles, 71 | // but don't allow the two to be mixed. That is to say /foo:bar and 72 | // --foo=bar are acceptable, but /foo=bar and --foo:bar are not. 73 | var pos int 74 | var sp string 75 | 76 | if prefix == "/" { 77 | sp = ":" 78 | pos = strings.Index(option, sp) 79 | } else if len(prefix) > 0 { 80 | sp = "=" 81 | pos = strings.Index(option, sp) 82 | } 83 | 84 | if (islong && pos >= 0) || (!islong && pos == 1) { 85 | rest := option[pos+1:] 86 | return option[:pos], sp, &rest 87 | } 88 | 89 | return option, "", nil 90 | } 91 | 92 | // addHelpGroup adds a new group that contains default help parameters. 93 | func (c *Command) addHelpGroup(showHelp func() error) *Group { 94 | // Windows CLI applications typically use /? for help, so make both 95 | // that available as well as the POSIX style h and help. 96 | var help struct { 97 | ShowHelpWindows func() error `short:"?" description:"Show this help message"` 98 | ShowHelpPosix func() error `short:"h" long:"help" description:"Show this help message"` 99 | } 100 | 101 | help.ShowHelpWindows = showHelp 102 | help.ShowHelpPosix = showHelp 103 | 104 | ret, _ := c.AddGroup("Help Options", "", &help) 105 | ret.isBuiltinHelp = true 106 | 107 | return ret 108 | } 109 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/termsize.go: -------------------------------------------------------------------------------- 1 | // +build !windows,!plan9,!solaris,!appengine,!wasm 2 | 3 | package flags 4 | 5 | import ( 6 | "syscall" 7 | "unsafe" 8 | ) 9 | 10 | type winsize struct { 11 | row, col uint16 12 | xpixel, ypixel uint16 13 | } 14 | 15 | func getTerminalColumns() int { 16 | ws := winsize{} 17 | 18 | if tIOCGWINSZ != 0 { 19 | syscall.Syscall(syscall.SYS_IOCTL, 20 | uintptr(0), 21 | uintptr(tIOCGWINSZ), 22 | uintptr(unsafe.Pointer(&ws))) 23 | 24 | return int(ws.col) 25 | } 26 | 27 | return 80 28 | } 29 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/termsize_nosysioctl.go: -------------------------------------------------------------------------------- 1 | // +build plan9 solaris appengine wasm 2 | 3 | package flags 4 | 5 | func getTerminalColumns() int { 6 | return 80 7 | } 8 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/termsize_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package flags 4 | 5 | import ( 6 | "syscall" 7 | "unsafe" 8 | ) 9 | 10 | type ( 11 | SHORT int16 12 | WORD uint16 13 | 14 | SMALL_RECT struct { 15 | Left SHORT 16 | Top SHORT 17 | Right SHORT 18 | Bottom SHORT 19 | } 20 | 21 | COORD struct { 22 | X SHORT 23 | Y SHORT 24 | } 25 | 26 | CONSOLE_SCREEN_BUFFER_INFO struct { 27 | Size COORD 28 | CursorPosition COORD 29 | Attributes WORD 30 | Window SMALL_RECT 31 | MaximumWindowSize COORD 32 | } 33 | ) 34 | 35 | var kernel32DLL = syscall.NewLazyDLL("kernel32.dll") 36 | var getConsoleScreenBufferInfoProc = kernel32DLL.NewProc("GetConsoleScreenBufferInfo") 37 | 38 | func getError(r1, r2 uintptr, lastErr error) error { 39 | // If the function fails, the return value is zero. 40 | if r1 == 0 { 41 | if lastErr != nil { 42 | return lastErr 43 | } 44 | return syscall.EINVAL 45 | } 46 | return nil 47 | } 48 | 49 | func getStdHandle(stdhandle int) (uintptr, error) { 50 | handle, err := syscall.GetStdHandle(stdhandle) 51 | if err != nil { 52 | return 0, err 53 | } 54 | return uintptr(handle), nil 55 | } 56 | 57 | // GetConsoleScreenBufferInfo retrieves information about the specified console screen buffer. 58 | // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx 59 | func GetConsoleScreenBufferInfo(handle uintptr) (*CONSOLE_SCREEN_BUFFER_INFO, error) { 60 | var info CONSOLE_SCREEN_BUFFER_INFO 61 | if err := getError(getConsoleScreenBufferInfoProc.Call(handle, uintptr(unsafe.Pointer(&info)), 0)); err != nil { 62 | return nil, err 63 | } 64 | return &info, nil 65 | } 66 | 67 | func getTerminalColumns() int { 68 | defaultWidth := 80 69 | 70 | stdoutHandle, err := getStdHandle(syscall.STD_OUTPUT_HANDLE) 71 | if err != nil { 72 | return defaultWidth 73 | } 74 | 75 | info, err := GetConsoleScreenBufferInfo(stdoutHandle) 76 | if err != nil { 77 | return defaultWidth 78 | } 79 | 80 | if info.MaximumWindowSize.X > 0 { 81 | return int(info.MaximumWindowSize.X) 82 | } 83 | 84 | return defaultWidth 85 | } 86 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/tiocgwinsz_bsdish.go: -------------------------------------------------------------------------------- 1 | // +build darwin freebsd netbsd openbsd 2 | 3 | package flags 4 | 5 | const ( 6 | tIOCGWINSZ = 0x40087468 7 | ) 8 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/tiocgwinsz_linux.go: -------------------------------------------------------------------------------- 1 | // +build linux 2 | 3 | package flags 4 | 5 | const ( 6 | tIOCGWINSZ = 0x5413 7 | ) 8 | -------------------------------------------------------------------------------- /vendor/github.com/umputun/go-flags/tiocgwinsz_other.go: -------------------------------------------------------------------------------- 1 | // +build !darwin,!freebsd,!netbsd,!openbsd,!linux 2 | 3 | package flags 4 | 5 | const ( 6 | tIOCGWINSZ = 0 7 | ) 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2009 The Go Authors. 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 LLC 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/crypto/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/crypto/argon2/blake2b.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 argon2 6 | 7 | import ( 8 | "encoding/binary" 9 | "hash" 10 | 11 | "golang.org/x/crypto/blake2b" 12 | ) 13 | 14 | // blake2bHash computes an arbitrary long hash value of in 15 | // and writes the hash to out. 16 | func blake2bHash(out []byte, in []byte) { 17 | var b2 hash.Hash 18 | if n := len(out); n < blake2b.Size { 19 | b2, _ = blake2b.New(n, nil) 20 | } else { 21 | b2, _ = blake2b.New512(nil) 22 | } 23 | 24 | var buffer [blake2b.Size]byte 25 | binary.LittleEndian.PutUint32(buffer[:4], uint32(len(out))) 26 | b2.Write(buffer[:4]) 27 | b2.Write(in) 28 | 29 | if len(out) <= blake2b.Size { 30 | b2.Sum(out[:0]) 31 | return 32 | } 33 | 34 | outLen := len(out) 35 | b2.Sum(buffer[:0]) 36 | b2.Reset() 37 | copy(out, buffer[:32]) 38 | out = out[32:] 39 | for len(out) > blake2b.Size { 40 | b2.Write(buffer[:]) 41 | b2.Sum(buffer[:0]) 42 | copy(out, buffer[:32]) 43 | out = out[32:] 44 | b2.Reset() 45 | } 46 | 47 | if outLen%blake2b.Size > 0 { // outLen > 64 48 | r := ((outLen + 31) / 32) - 2 // ⌈τ /32⌉-2 49 | b2, _ = blake2b.New(outLen-32*r, nil) 50 | } 51 | b2.Write(buffer[:]) 52 | b2.Sum(out[:0]) 53 | } 54 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/argon2/blamka_amd64.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 amd64 && gc && !purego 6 | 7 | package argon2 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | func init() { 12 | useSSE4 = cpu.X86.HasSSE41 13 | } 14 | 15 | //go:noescape 16 | func mixBlocksSSE2(out, a, b, c *block) 17 | 18 | //go:noescape 19 | func xorBlocksSSE2(out, a, b, c *block) 20 | 21 | //go:noescape 22 | func blamkaSSE4(b *block) 23 | 24 | func processBlockSSE(out, in1, in2 *block, xor bool) { 25 | var t block 26 | mixBlocksSSE2(&t, in1, in2, &t) 27 | if useSSE4 { 28 | blamkaSSE4(&t) 29 | } else { 30 | for i := 0; i < blockLength; i += 16 { 31 | blamkaGeneric( 32 | &t[i+0], &t[i+1], &t[i+2], &t[i+3], 33 | &t[i+4], &t[i+5], &t[i+6], &t[i+7], 34 | &t[i+8], &t[i+9], &t[i+10], &t[i+11], 35 | &t[i+12], &t[i+13], &t[i+14], &t[i+15], 36 | ) 37 | } 38 | for i := 0; i < blockLength/8; i += 2 { 39 | blamkaGeneric( 40 | &t[i], &t[i+1], &t[16+i], &t[16+i+1], 41 | &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1], 42 | &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1], 43 | &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1], 44 | ) 45 | } 46 | } 47 | if xor { 48 | xorBlocksSSE2(out, in1, in2, &t) 49 | } else { 50 | mixBlocksSSE2(out, in1, in2, &t) 51 | } 52 | } 53 | 54 | func processBlock(out, in1, in2 *block) { 55 | processBlockSSE(out, in1, in2, false) 56 | } 57 | 58 | func processBlockXOR(out, in1, in2 *block) { 59 | processBlockSSE(out, in1, in2, true) 60 | } 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/argon2/blamka_generic.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 argon2 6 | 7 | var useSSE4 bool 8 | 9 | func processBlockGeneric(out, in1, in2 *block, xor bool) { 10 | var t block 11 | for i := range t { 12 | t[i] = in1[i] ^ in2[i] 13 | } 14 | for i := 0; i < blockLength; i += 16 { 15 | blamkaGeneric( 16 | &t[i+0], &t[i+1], &t[i+2], &t[i+3], 17 | &t[i+4], &t[i+5], &t[i+6], &t[i+7], 18 | &t[i+8], &t[i+9], &t[i+10], &t[i+11], 19 | &t[i+12], &t[i+13], &t[i+14], &t[i+15], 20 | ) 21 | } 22 | for i := 0; i < blockLength/8; i += 2 { 23 | blamkaGeneric( 24 | &t[i], &t[i+1], &t[16+i], &t[16+i+1], 25 | &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1], 26 | &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1], 27 | &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1], 28 | ) 29 | } 30 | if xor { 31 | for i := range t { 32 | out[i] ^= in1[i] ^ in2[i] ^ t[i] 33 | } 34 | } else { 35 | for i := range t { 36 | out[i] = in1[i] ^ in2[i] ^ t[i] 37 | } 38 | } 39 | } 40 | 41 | func blamkaGeneric(t00, t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15 *uint64) { 42 | v00, v01, v02, v03 := *t00, *t01, *t02, *t03 43 | v04, v05, v06, v07 := *t04, *t05, *t06, *t07 44 | v08, v09, v10, v11 := *t08, *t09, *t10, *t11 45 | v12, v13, v14, v15 := *t12, *t13, *t14, *t15 46 | 47 | v00 += v04 + 2*uint64(uint32(v00))*uint64(uint32(v04)) 48 | v12 ^= v00 49 | v12 = v12>>32 | v12<<32 50 | v08 += v12 + 2*uint64(uint32(v08))*uint64(uint32(v12)) 51 | v04 ^= v08 52 | v04 = v04>>24 | v04<<40 53 | 54 | v00 += v04 + 2*uint64(uint32(v00))*uint64(uint32(v04)) 55 | v12 ^= v00 56 | v12 = v12>>16 | v12<<48 57 | v08 += v12 + 2*uint64(uint32(v08))*uint64(uint32(v12)) 58 | v04 ^= v08 59 | v04 = v04>>63 | v04<<1 60 | 61 | v01 += v05 + 2*uint64(uint32(v01))*uint64(uint32(v05)) 62 | v13 ^= v01 63 | v13 = v13>>32 | v13<<32 64 | v09 += v13 + 2*uint64(uint32(v09))*uint64(uint32(v13)) 65 | v05 ^= v09 66 | v05 = v05>>24 | v05<<40 67 | 68 | v01 += v05 + 2*uint64(uint32(v01))*uint64(uint32(v05)) 69 | v13 ^= v01 70 | v13 = v13>>16 | v13<<48 71 | v09 += v13 + 2*uint64(uint32(v09))*uint64(uint32(v13)) 72 | v05 ^= v09 73 | v05 = v05>>63 | v05<<1 74 | 75 | v02 += v06 + 2*uint64(uint32(v02))*uint64(uint32(v06)) 76 | v14 ^= v02 77 | v14 = v14>>32 | v14<<32 78 | v10 += v14 + 2*uint64(uint32(v10))*uint64(uint32(v14)) 79 | v06 ^= v10 80 | v06 = v06>>24 | v06<<40 81 | 82 | v02 += v06 + 2*uint64(uint32(v02))*uint64(uint32(v06)) 83 | v14 ^= v02 84 | v14 = v14>>16 | v14<<48 85 | v10 += v14 + 2*uint64(uint32(v10))*uint64(uint32(v14)) 86 | v06 ^= v10 87 | v06 = v06>>63 | v06<<1 88 | 89 | v03 += v07 + 2*uint64(uint32(v03))*uint64(uint32(v07)) 90 | v15 ^= v03 91 | v15 = v15>>32 | v15<<32 92 | v11 += v15 + 2*uint64(uint32(v11))*uint64(uint32(v15)) 93 | v07 ^= v11 94 | v07 = v07>>24 | v07<<40 95 | 96 | v03 += v07 + 2*uint64(uint32(v03))*uint64(uint32(v07)) 97 | v15 ^= v03 98 | v15 = v15>>16 | v15<<48 99 | v11 += v15 + 2*uint64(uint32(v11))*uint64(uint32(v15)) 100 | v07 ^= v11 101 | v07 = v07>>63 | v07<<1 102 | 103 | v00 += v05 + 2*uint64(uint32(v00))*uint64(uint32(v05)) 104 | v15 ^= v00 105 | v15 = v15>>32 | v15<<32 106 | v10 += v15 + 2*uint64(uint32(v10))*uint64(uint32(v15)) 107 | v05 ^= v10 108 | v05 = v05>>24 | v05<<40 109 | 110 | v00 += v05 + 2*uint64(uint32(v00))*uint64(uint32(v05)) 111 | v15 ^= v00 112 | v15 = v15>>16 | v15<<48 113 | v10 += v15 + 2*uint64(uint32(v10))*uint64(uint32(v15)) 114 | v05 ^= v10 115 | v05 = v05>>63 | v05<<1 116 | 117 | v01 += v06 + 2*uint64(uint32(v01))*uint64(uint32(v06)) 118 | v12 ^= v01 119 | v12 = v12>>32 | v12<<32 120 | v11 += v12 + 2*uint64(uint32(v11))*uint64(uint32(v12)) 121 | v06 ^= v11 122 | v06 = v06>>24 | v06<<40 123 | 124 | v01 += v06 + 2*uint64(uint32(v01))*uint64(uint32(v06)) 125 | v12 ^= v01 126 | v12 = v12>>16 | v12<<48 127 | v11 += v12 + 2*uint64(uint32(v11))*uint64(uint32(v12)) 128 | v06 ^= v11 129 | v06 = v06>>63 | v06<<1 130 | 131 | v02 += v07 + 2*uint64(uint32(v02))*uint64(uint32(v07)) 132 | v13 ^= v02 133 | v13 = v13>>32 | v13<<32 134 | v08 += v13 + 2*uint64(uint32(v08))*uint64(uint32(v13)) 135 | v07 ^= v08 136 | v07 = v07>>24 | v07<<40 137 | 138 | v02 += v07 + 2*uint64(uint32(v02))*uint64(uint32(v07)) 139 | v13 ^= v02 140 | v13 = v13>>16 | v13<<48 141 | v08 += v13 + 2*uint64(uint32(v08))*uint64(uint32(v13)) 142 | v07 ^= v08 143 | v07 = v07>>63 | v07<<1 144 | 145 | v03 += v04 + 2*uint64(uint32(v03))*uint64(uint32(v04)) 146 | v14 ^= v03 147 | v14 = v14>>32 | v14<<32 148 | v09 += v14 + 2*uint64(uint32(v09))*uint64(uint32(v14)) 149 | v04 ^= v09 150 | v04 = v04>>24 | v04<<40 151 | 152 | v03 += v04 + 2*uint64(uint32(v03))*uint64(uint32(v04)) 153 | v14 ^= v03 154 | v14 = v14>>16 | v14<<48 155 | v09 += v14 + 2*uint64(uint32(v09))*uint64(uint32(v14)) 156 | v04 ^= v09 157 | v04 = v04>>63 | v04<<1 158 | 159 | *t00, *t01, *t02, *t03 = v00, v01, v02, v03 160 | *t04, *t05, *t06, *t07 = v04, v05, v06, v07 161 | *t08, *t09, *t10, *t11 = v08, v09, v10, v11 162 | *t12, *t13, *t14, *t15 = v12, v13, v14, v15 163 | } 164 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/argon2/blamka_ref.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 !amd64 || purego || !gc 6 | 7 | package argon2 8 | 9 | func processBlock(out, in1, in2 *block) { 10 | processBlockGeneric(out, in1, in2, false) 11 | } 12 | 13 | func processBlockXOR(out, in1, in2 *block) { 14 | processBlockGeneric(out, in1, in2, true) 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/bcrypt/base64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 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 bcrypt 6 | 7 | import "encoding/base64" 8 | 9 | const alphabet = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 10 | 11 | var bcEncoding = base64.NewEncoding(alphabet) 12 | 13 | func base64Encode(src []byte) []byte { 14 | n := bcEncoding.EncodedLen(len(src)) 15 | dst := make([]byte, n) 16 | bcEncoding.Encode(dst, src) 17 | for dst[n-1] == '=' { 18 | n-- 19 | } 20 | return dst[:n] 21 | } 22 | 23 | func base64Decode(src []byte) ([]byte, error) { 24 | numOfEquals := 4 - (len(src) % 4) 25 | for i := 0; i < numOfEquals; i++ { 26 | src = append(src, '=') 27 | } 28 | 29 | dst := make([]byte, bcEncoding.DecodedLen(len(src))) 30 | n, err := bcEncoding.Decode(dst, src) 31 | if err != nil { 32 | return nil, err 33 | } 34 | return dst[:n], nil 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2bAVX2_amd64.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 | //go:build amd64 && gc && !purego 6 | 7 | package blake2b 8 | 9 | import "golang.org/x/sys/cpu" 10 | 11 | func init() { 12 | useAVX2 = cpu.X86.HasAVX2 13 | useAVX = cpu.X86.HasAVX 14 | useSSE4 = cpu.X86.HasSSE41 15 | } 16 | 17 | //go:noescape 18 | func hashBlocksAVX2(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 19 | 20 | //go:noescape 21 | func hashBlocksAVX(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 22 | 23 | //go:noescape 24 | func hashBlocksSSE4(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) 25 | 26 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { 27 | switch { 28 | case useAVX2: 29 | hashBlocksAVX2(h, c, flag, blocks) 30 | case useAVX: 31 | hashBlocksAVX(h, c, flag, blocks) 32 | case useSSE4: 33 | hashBlocksSSE4(h, c, flag, blocks) 34 | default: 35 | hashBlocksGeneric(h, c, flag, blocks) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2b_generic.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 blake2b 6 | 7 | import ( 8 | "encoding/binary" 9 | "math/bits" 10 | ) 11 | 12 | // the precomputed values for BLAKE2b 13 | // there are 12 16-byte arrays - one for each round 14 | // the entries are calculated from the sigma constants. 15 | var precomputed = [12][16]byte{ 16 | {0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15}, 17 | {14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3}, 18 | {11, 12, 5, 15, 8, 0, 2, 13, 10, 3, 7, 9, 14, 6, 1, 4}, 19 | {7, 3, 13, 11, 9, 1, 12, 14, 2, 5, 4, 15, 6, 10, 0, 8}, 20 | {9, 5, 2, 10, 0, 7, 4, 15, 14, 11, 6, 3, 1, 12, 8, 13}, 21 | {2, 6, 0, 8, 12, 10, 11, 3, 4, 7, 15, 1, 13, 5, 14, 9}, 22 | {12, 1, 14, 4, 5, 15, 13, 10, 0, 6, 9, 8, 7, 3, 2, 11}, 23 | {13, 7, 12, 3, 11, 14, 1, 9, 5, 15, 8, 2, 0, 4, 6, 10}, 24 | {6, 14, 11, 0, 15, 9, 3, 8, 12, 13, 1, 10, 2, 7, 4, 5}, 25 | {10, 8, 7, 1, 2, 4, 6, 5, 15, 9, 3, 13, 11, 14, 12, 0}, 26 | {0, 2, 4, 6, 1, 3, 5, 7, 8, 10, 12, 14, 9, 11, 13, 15}, // equal to the first 27 | {14, 4, 9, 13, 10, 8, 15, 6, 1, 0, 11, 5, 12, 2, 7, 3}, // equal to the second 28 | } 29 | 30 | func hashBlocksGeneric(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { 31 | var m [16]uint64 32 | c0, c1 := c[0], c[1] 33 | 34 | for i := 0; i < len(blocks); { 35 | c0 += BlockSize 36 | if c0 < BlockSize { 37 | c1++ 38 | } 39 | 40 | v0, v1, v2, v3, v4, v5, v6, v7 := h[0], h[1], h[2], h[3], h[4], h[5], h[6], h[7] 41 | v8, v9, v10, v11, v12, v13, v14, v15 := iv[0], iv[1], iv[2], iv[3], iv[4], iv[5], iv[6], iv[7] 42 | v12 ^= c0 43 | v13 ^= c1 44 | v14 ^= flag 45 | 46 | for j := range m { 47 | m[j] = binary.LittleEndian.Uint64(blocks[i:]) 48 | i += 8 49 | } 50 | 51 | for j := range precomputed { 52 | s := &(precomputed[j]) 53 | 54 | v0 += m[s[0]] 55 | v0 += v4 56 | v12 ^= v0 57 | v12 = bits.RotateLeft64(v12, -32) 58 | v8 += v12 59 | v4 ^= v8 60 | v4 = bits.RotateLeft64(v4, -24) 61 | v1 += m[s[1]] 62 | v1 += v5 63 | v13 ^= v1 64 | v13 = bits.RotateLeft64(v13, -32) 65 | v9 += v13 66 | v5 ^= v9 67 | v5 = bits.RotateLeft64(v5, -24) 68 | v2 += m[s[2]] 69 | v2 += v6 70 | v14 ^= v2 71 | v14 = bits.RotateLeft64(v14, -32) 72 | v10 += v14 73 | v6 ^= v10 74 | v6 = bits.RotateLeft64(v6, -24) 75 | v3 += m[s[3]] 76 | v3 += v7 77 | v15 ^= v3 78 | v15 = bits.RotateLeft64(v15, -32) 79 | v11 += v15 80 | v7 ^= v11 81 | v7 = bits.RotateLeft64(v7, -24) 82 | 83 | v0 += m[s[4]] 84 | v0 += v4 85 | v12 ^= v0 86 | v12 = bits.RotateLeft64(v12, -16) 87 | v8 += v12 88 | v4 ^= v8 89 | v4 = bits.RotateLeft64(v4, -63) 90 | v1 += m[s[5]] 91 | v1 += v5 92 | v13 ^= v1 93 | v13 = bits.RotateLeft64(v13, -16) 94 | v9 += v13 95 | v5 ^= v9 96 | v5 = bits.RotateLeft64(v5, -63) 97 | v2 += m[s[6]] 98 | v2 += v6 99 | v14 ^= v2 100 | v14 = bits.RotateLeft64(v14, -16) 101 | v10 += v14 102 | v6 ^= v10 103 | v6 = bits.RotateLeft64(v6, -63) 104 | v3 += m[s[7]] 105 | v3 += v7 106 | v15 ^= v3 107 | v15 = bits.RotateLeft64(v15, -16) 108 | v11 += v15 109 | v7 ^= v11 110 | v7 = bits.RotateLeft64(v7, -63) 111 | 112 | v0 += m[s[8]] 113 | v0 += v5 114 | v15 ^= v0 115 | v15 = bits.RotateLeft64(v15, -32) 116 | v10 += v15 117 | v5 ^= v10 118 | v5 = bits.RotateLeft64(v5, -24) 119 | v1 += m[s[9]] 120 | v1 += v6 121 | v12 ^= v1 122 | v12 = bits.RotateLeft64(v12, -32) 123 | v11 += v12 124 | v6 ^= v11 125 | v6 = bits.RotateLeft64(v6, -24) 126 | v2 += m[s[10]] 127 | v2 += v7 128 | v13 ^= v2 129 | v13 = bits.RotateLeft64(v13, -32) 130 | v8 += v13 131 | v7 ^= v8 132 | v7 = bits.RotateLeft64(v7, -24) 133 | v3 += m[s[11]] 134 | v3 += v4 135 | v14 ^= v3 136 | v14 = bits.RotateLeft64(v14, -32) 137 | v9 += v14 138 | v4 ^= v9 139 | v4 = bits.RotateLeft64(v4, -24) 140 | 141 | v0 += m[s[12]] 142 | v0 += v5 143 | v15 ^= v0 144 | v15 = bits.RotateLeft64(v15, -16) 145 | v10 += v15 146 | v5 ^= v10 147 | v5 = bits.RotateLeft64(v5, -63) 148 | v1 += m[s[13]] 149 | v1 += v6 150 | v12 ^= v1 151 | v12 = bits.RotateLeft64(v12, -16) 152 | v11 += v12 153 | v6 ^= v11 154 | v6 = bits.RotateLeft64(v6, -63) 155 | v2 += m[s[14]] 156 | v2 += v7 157 | v13 ^= v2 158 | v13 = bits.RotateLeft64(v13, -16) 159 | v8 += v13 160 | v7 ^= v8 161 | v7 = bits.RotateLeft64(v7, -63) 162 | v3 += m[s[15]] 163 | v3 += v4 164 | v14 ^= v3 165 | v14 = bits.RotateLeft64(v14, -16) 166 | v9 += v14 167 | v4 ^= v9 168 | v4 = bits.RotateLeft64(v4, -63) 169 | 170 | } 171 | 172 | h[0] ^= v0 ^ v8 173 | h[1] ^= v1 ^ v9 174 | h[2] ^= v2 ^ v10 175 | h[3] ^= v3 ^ v11 176 | h[4] ^= v4 ^ v12 177 | h[5] ^= v5 ^ v13 178 | h[6] ^= v6 ^ v14 179 | h[7] ^= v7 ^ v15 180 | } 181 | c[0], c[1] = c0, c1 182 | } 183 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2b_ref.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 | //go:build !amd64 || purego || !gc 6 | 7 | package blake2b 8 | 9 | func hashBlocks(h *[8]uint64, c *[2]uint64, flag uint64, blocks []byte) { 10 | hashBlocksGeneric(h, c, flag, blocks) 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/blake2x.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 blake2b 6 | 7 | import ( 8 | "encoding/binary" 9 | "errors" 10 | "io" 11 | ) 12 | 13 | // XOF defines the interface to hash functions that 14 | // support arbitrary-length output. 15 | type XOF interface { 16 | // Write absorbs more data into the hash's state. It panics if called 17 | // after Read. 18 | io.Writer 19 | 20 | // Read reads more output from the hash. It returns io.EOF if the limit 21 | // has been reached. 22 | io.Reader 23 | 24 | // Clone returns a copy of the XOF in its current state. 25 | Clone() XOF 26 | 27 | // Reset resets the XOF to its initial state. 28 | Reset() 29 | } 30 | 31 | // OutputLengthUnknown can be used as the size argument to NewXOF to indicate 32 | // the length of the output is not known in advance. 33 | const OutputLengthUnknown = 0 34 | 35 | // magicUnknownOutputLength is a magic value for the output size that indicates 36 | // an unknown number of output bytes. 37 | const magicUnknownOutputLength = (1 << 32) - 1 38 | 39 | // maxOutputLength is the absolute maximum number of bytes to produce when the 40 | // number of output bytes is unknown. 41 | const maxOutputLength = (1 << 32) * 64 42 | 43 | // NewXOF creates a new variable-output-length hash. The hash either produce a 44 | // known number of bytes (1 <= size < 2**32-1), or an unknown number of bytes 45 | // (size == OutputLengthUnknown). In the latter case, an absolute limit of 46 | // 256GiB applies. 47 | // 48 | // A non-nil key turns the hash into a MAC. The key must between 49 | // zero and 32 bytes long. 50 | func NewXOF(size uint32, key []byte) (XOF, error) { 51 | if len(key) > Size { 52 | return nil, errKeySize 53 | } 54 | if size == magicUnknownOutputLength { 55 | // 2^32-1 indicates an unknown number of bytes and thus isn't a 56 | // valid length. 57 | return nil, errors.New("blake2b: XOF length too large") 58 | } 59 | if size == OutputLengthUnknown { 60 | size = magicUnknownOutputLength 61 | } 62 | x := &xof{ 63 | d: digest{ 64 | size: Size, 65 | keyLen: len(key), 66 | }, 67 | length: size, 68 | } 69 | copy(x.d.key[:], key) 70 | x.Reset() 71 | return x, nil 72 | } 73 | 74 | type xof struct { 75 | d digest 76 | length uint32 77 | remaining uint64 78 | cfg, root, block [Size]byte 79 | offset int 80 | nodeOffset uint32 81 | readMode bool 82 | } 83 | 84 | func (x *xof) Write(p []byte) (n int, err error) { 85 | if x.readMode { 86 | panic("blake2b: write to XOF after read") 87 | } 88 | return x.d.Write(p) 89 | } 90 | 91 | func (x *xof) Clone() XOF { 92 | clone := *x 93 | return &clone 94 | } 95 | 96 | func (x *xof) Reset() { 97 | x.cfg[0] = byte(Size) 98 | binary.LittleEndian.PutUint32(x.cfg[4:], uint32(Size)) // leaf length 99 | binary.LittleEndian.PutUint32(x.cfg[12:], x.length) // XOF length 100 | x.cfg[17] = byte(Size) // inner hash size 101 | 102 | x.d.Reset() 103 | x.d.h[1] ^= uint64(x.length) << 32 104 | 105 | x.remaining = uint64(x.length) 106 | if x.remaining == magicUnknownOutputLength { 107 | x.remaining = maxOutputLength 108 | } 109 | x.offset, x.nodeOffset = 0, 0 110 | x.readMode = false 111 | } 112 | 113 | func (x *xof) Read(p []byte) (n int, err error) { 114 | if !x.readMode { 115 | x.d.finalize(&x.root) 116 | x.readMode = true 117 | } 118 | 119 | if x.remaining == 0 { 120 | return 0, io.EOF 121 | } 122 | 123 | n = len(p) 124 | if uint64(n) > x.remaining { 125 | n = int(x.remaining) 126 | p = p[:n] 127 | } 128 | 129 | if x.offset > 0 { 130 | blockRemaining := Size - x.offset 131 | if n < blockRemaining { 132 | x.offset += copy(p, x.block[x.offset:]) 133 | x.remaining -= uint64(n) 134 | return 135 | } 136 | copy(p, x.block[x.offset:]) 137 | p = p[blockRemaining:] 138 | x.offset = 0 139 | x.remaining -= uint64(blockRemaining) 140 | } 141 | 142 | for len(p) >= Size { 143 | binary.LittleEndian.PutUint32(x.cfg[8:], x.nodeOffset) 144 | x.nodeOffset++ 145 | 146 | x.d.initConfig(&x.cfg) 147 | x.d.Write(x.root[:]) 148 | x.d.finalize(&x.block) 149 | 150 | copy(p, x.block[:]) 151 | p = p[Size:] 152 | x.remaining -= uint64(Size) 153 | } 154 | 155 | if todo := len(p); todo > 0 { 156 | if x.remaining < uint64(Size) { 157 | x.cfg[0] = byte(x.remaining) 158 | } 159 | binary.LittleEndian.PutUint32(x.cfg[8:], x.nodeOffset) 160 | x.nodeOffset++ 161 | 162 | x.d.initConfig(&x.cfg) 163 | x.d.Write(x.root[:]) 164 | x.d.finalize(&x.block) 165 | 166 | x.offset = copy(p, x.block[:todo]) 167 | x.remaining -= uint64(todo) 168 | } 169 | return 170 | } 171 | 172 | func (d *digest) initConfig(cfg *[Size]byte) { 173 | d.offset, d.c[0], d.c[1] = 0, 0, 0 174 | for i := range d.h { 175 | d.h[i] = iv[i] ^ binary.LittleEndian.Uint64(cfg[i*8:]) 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blake2b/register.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 blake2b 6 | 7 | import ( 8 | "crypto" 9 | "hash" 10 | ) 11 | 12 | func init() { 13 | newHash256 := func() hash.Hash { 14 | h, _ := New256(nil) 15 | return h 16 | } 17 | newHash384 := func() hash.Hash { 18 | h, _ := New384(nil) 19 | return h 20 | } 21 | 22 | newHash512 := func() hash.Hash { 23 | h, _ := New512(nil) 24 | return h 25 | } 26 | 27 | crypto.RegisterHash(crypto.BLAKE2b_256, newHash256) 28 | crypto.RegisterHash(crypto.BLAKE2b_384, newHash384) 29 | crypto.RegisterHash(crypto.BLAKE2b_512, newHash512) 30 | } 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/crypto/blowfish/cipher.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 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 blowfish implements Bruce Schneier's Blowfish encryption algorithm. 6 | // 7 | // Blowfish is a legacy cipher and its short block size makes it vulnerable to 8 | // birthday bound attacks (see https://sweet32.info). It should only be used 9 | // where compatibility with legacy systems, not security, is the goal. 10 | // 11 | // Deprecated: any new system should use AES (from crypto/aes, if necessary in 12 | // an AEAD mode like crypto/cipher.NewGCM) or XChaCha20-Poly1305 (from 13 | // golang.org/x/crypto/chacha20poly1305). 14 | package blowfish 15 | 16 | // The code is a port of Bruce Schneier's C implementation. 17 | // See https://www.schneier.com/blowfish.html. 18 | 19 | import "strconv" 20 | 21 | // The Blowfish block size in bytes. 22 | const BlockSize = 8 23 | 24 | // A Cipher is an instance of Blowfish encryption using a particular key. 25 | type Cipher struct { 26 | p [18]uint32 27 | s0, s1, s2, s3 [256]uint32 28 | } 29 | 30 | type KeySizeError int 31 | 32 | func (k KeySizeError) Error() string { 33 | return "crypto/blowfish: invalid key size " + strconv.Itoa(int(k)) 34 | } 35 | 36 | // NewCipher creates and returns a Cipher. 37 | // The key argument should be the Blowfish key, from 1 to 56 bytes. 38 | func NewCipher(key []byte) (*Cipher, error) { 39 | var result Cipher 40 | if k := len(key); k < 1 || k > 56 { 41 | return nil, KeySizeError(k) 42 | } 43 | initCipher(&result) 44 | ExpandKey(key, &result) 45 | return &result, nil 46 | } 47 | 48 | // NewSaltedCipher creates a returns a Cipher that folds a salt into its key 49 | // schedule. For most purposes, NewCipher, instead of NewSaltedCipher, is 50 | // sufficient and desirable. For bcrypt compatibility, the key can be over 56 51 | // bytes. 52 | func NewSaltedCipher(key, salt []byte) (*Cipher, error) { 53 | if len(salt) == 0 { 54 | return NewCipher(key) 55 | } 56 | var result Cipher 57 | if k := len(key); k < 1 { 58 | return nil, KeySizeError(k) 59 | } 60 | initCipher(&result) 61 | expandKeyWithSalt(key, salt, &result) 62 | return &result, nil 63 | } 64 | 65 | // BlockSize returns the Blowfish block size, 8 bytes. 66 | // It is necessary to satisfy the Block interface in the 67 | // package "crypto/cipher". 68 | func (c *Cipher) BlockSize() int { return BlockSize } 69 | 70 | // Encrypt encrypts the 8-byte buffer src using the key k 71 | // and stores the result in dst. 72 | // Note that for amounts of data larger than a block, 73 | // it is not safe to just call Encrypt on successive blocks; 74 | // instead, use an encryption mode like CBC (see crypto/cipher/cbc.go). 75 | func (c *Cipher) Encrypt(dst, src []byte) { 76 | l := uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) 77 | r := uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) 78 | l, r = encryptBlock(l, r, c) 79 | dst[0], dst[1], dst[2], dst[3] = byte(l>>24), byte(l>>16), byte(l>>8), byte(l) 80 | dst[4], dst[5], dst[6], dst[7] = byte(r>>24), byte(r>>16), byte(r>>8), byte(r) 81 | } 82 | 83 | // Decrypt decrypts the 8-byte buffer src using the key k 84 | // and stores the result in dst. 85 | func (c *Cipher) Decrypt(dst, src []byte) { 86 | l := uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) 87 | r := uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) 88 | l, r = decryptBlock(l, r, c) 89 | dst[0], dst[1], dst[2], dst[3] = byte(l>>24), byte(l>>16), byte(l>>8), byte(l) 90 | dst[4], dst[5], dst[6], dst[7] = byte(r>>24), byte(r>>16), byte(r>>8), byte(r) 91 | } 92 | 93 | func initCipher(c *Cipher) { 94 | copy(c.p[0:], p[0:]) 95 | copy(c.s0[0:], s0[0:]) 96 | copy(c.s1[0:], s1[0:]) 97 | copy(c.s2[0:], s2[0:]) 98 | copy(c.s3[0:], s3[0:]) 99 | } 100 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2009 The Go Authors. 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 LLC 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/cpu/asm_aix_ppc64.s: -------------------------------------------------------------------------------- 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 gc 6 | 7 | #include "textflag.h" 8 | 9 | // 10 | // System calls for ppc64, AIX are implemented in runtime/syscall_aix.go 11 | // 12 | 13 | TEXT ·syscall6(SB),NOSPLIT,$0-88 14 | JMP syscall·syscall6(SB) 15 | 16 | TEXT ·rawSyscall6(SB),NOSPLIT,$0-88 17 | JMP syscall·rawSyscall6(SB) 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/asm_darwin_x86_gc.s: -------------------------------------------------------------------------------- 1 | // Copyright 2024 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 darwin && amd64 && gc 6 | 7 | #include "textflag.h" 8 | 9 | TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 10 | JMP libc_sysctl(SB) 11 | GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 12 | DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) 13 | 14 | TEXT libc_sysctlbyname_trampoline<>(SB),NOSPLIT,$0-0 15 | JMP libc_sysctlbyname(SB) 16 | GLOBL ·libc_sysctlbyname_trampoline_addr(SB), RODATA, $8 17 | DATA ·libc_sysctlbyname_trampoline_addr(SB)/8, $libc_sysctlbyname_trampoline<>(SB) 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/byteorder.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 cpu 6 | 7 | import ( 8 | "runtime" 9 | ) 10 | 11 | // byteOrder is a subset of encoding/binary.ByteOrder. 12 | type byteOrder interface { 13 | Uint32([]byte) uint32 14 | Uint64([]byte) uint64 15 | } 16 | 17 | type littleEndian struct{} 18 | type bigEndian struct{} 19 | 20 | func (littleEndian) Uint32(b []byte) uint32 { 21 | _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808 22 | return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 23 | } 24 | 25 | func (littleEndian) Uint64(b []byte) uint64 { 26 | _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808 27 | return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | 28 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 29 | } 30 | 31 | func (bigEndian) Uint32(b []byte) uint32 { 32 | _ = b[3] // bounds check hint to compiler; see golang.org/issue/14808 33 | return uint32(b[3]) | uint32(b[2])<<8 | uint32(b[1])<<16 | uint32(b[0])<<24 34 | } 35 | 36 | func (bigEndian) Uint64(b []byte) uint64 { 37 | _ = b[7] // bounds check hint to compiler; see golang.org/issue/14808 38 | return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | 39 | uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 40 | } 41 | 42 | // hostByteOrder returns littleEndian on little-endian machines and 43 | // bigEndian on big-endian machines. 44 | func hostByteOrder() byteOrder { 45 | switch runtime.GOARCH { 46 | case "386", "amd64", "amd64p32", 47 | "alpha", 48 | "arm", "arm64", 49 | "loong64", 50 | "mipsle", "mips64le", "mips64p32le", 51 | "nios2", 52 | "ppc64le", 53 | "riscv", "riscv64", 54 | "sh": 55 | return littleEndian{} 56 | case "armbe", "arm64be", 57 | "m68k", 58 | "mips", "mips64", "mips64p32", 59 | "ppc", "ppc64", 60 | "s390", "s390x", 61 | "shbe", 62 | "sparc", "sparc64": 63 | return bigEndian{} 64 | } 65 | panic("unknown architecture") 66 | } 67 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_aix.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 aix 6 | 7 | package cpu 8 | 9 | const ( 10 | // getsystemcfg constants 11 | _SC_IMPL = 2 12 | _IMPL_POWER8 = 0x10000 13 | _IMPL_POWER9 = 0x20000 14 | ) 15 | 16 | func archInit() { 17 | impl := getsystemcfg(_SC_IMPL) 18 | if impl&_IMPL_POWER8 != 0 { 19 | PPC64.IsPOWER8 = true 20 | } 21 | if impl&_IMPL_POWER9 != 0 { 22 | PPC64.IsPOWER8 = true 23 | PPC64.IsPOWER9 = true 24 | } 25 | 26 | Initialized = true 27 | } 28 | 29 | func getsystemcfg(label int) (n uint64) { 30 | r0, _ := callgetsystemcfg(label) 31 | n = uint64(r0) 32 | return 33 | } 34 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_arm.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 cpu 6 | 7 | const cacheLineSize = 32 8 | 9 | // HWCAP/HWCAP2 bits. 10 | // These are specific to Linux. 11 | const ( 12 | hwcap_SWP = 1 << 0 13 | hwcap_HALF = 1 << 1 14 | hwcap_THUMB = 1 << 2 15 | hwcap_26BIT = 1 << 3 16 | hwcap_FAST_MULT = 1 << 4 17 | hwcap_FPA = 1 << 5 18 | hwcap_VFP = 1 << 6 19 | hwcap_EDSP = 1 << 7 20 | hwcap_JAVA = 1 << 8 21 | hwcap_IWMMXT = 1 << 9 22 | hwcap_CRUNCH = 1 << 10 23 | hwcap_THUMBEE = 1 << 11 24 | hwcap_NEON = 1 << 12 25 | hwcap_VFPv3 = 1 << 13 26 | hwcap_VFPv3D16 = 1 << 14 27 | hwcap_TLS = 1 << 15 28 | hwcap_VFPv4 = 1 << 16 29 | hwcap_IDIVA = 1 << 17 30 | hwcap_IDIVT = 1 << 18 31 | hwcap_VFPD32 = 1 << 19 32 | hwcap_LPAE = 1 << 20 33 | hwcap_EVTSTRM = 1 << 21 34 | 35 | hwcap2_AES = 1 << 0 36 | hwcap2_PMULL = 1 << 1 37 | hwcap2_SHA1 = 1 << 2 38 | hwcap2_SHA2 = 1 << 3 39 | hwcap2_CRC32 = 1 << 4 40 | ) 41 | 42 | func initOptions() { 43 | options = []option{ 44 | {Name: "pmull", Feature: &ARM.HasPMULL}, 45 | {Name: "sha1", Feature: &ARM.HasSHA1}, 46 | {Name: "sha2", Feature: &ARM.HasSHA2}, 47 | {Name: "swp", Feature: &ARM.HasSWP}, 48 | {Name: "thumb", Feature: &ARM.HasTHUMB}, 49 | {Name: "thumbee", Feature: &ARM.HasTHUMBEE}, 50 | {Name: "tls", Feature: &ARM.HasTLS}, 51 | {Name: "vfp", Feature: &ARM.HasVFP}, 52 | {Name: "vfpd32", Feature: &ARM.HasVFPD32}, 53 | {Name: "vfpv3", Feature: &ARM.HasVFPv3}, 54 | {Name: "vfpv3d16", Feature: &ARM.HasVFPv3D16}, 55 | {Name: "vfpv4", Feature: &ARM.HasVFPv4}, 56 | {Name: "half", Feature: &ARM.HasHALF}, 57 | {Name: "26bit", Feature: &ARM.Has26BIT}, 58 | {Name: "fastmul", Feature: &ARM.HasFASTMUL}, 59 | {Name: "fpa", Feature: &ARM.HasFPA}, 60 | {Name: "edsp", Feature: &ARM.HasEDSP}, 61 | {Name: "java", Feature: &ARM.HasJAVA}, 62 | {Name: "iwmmxt", Feature: &ARM.HasIWMMXT}, 63 | {Name: "crunch", Feature: &ARM.HasCRUNCH}, 64 | {Name: "neon", Feature: &ARM.HasNEON}, 65 | {Name: "idivt", Feature: &ARM.HasIDIVT}, 66 | {Name: "idiva", Feature: &ARM.HasIDIVA}, 67 | {Name: "lpae", Feature: &ARM.HasLPAE}, 68 | {Name: "evtstrm", Feature: &ARM.HasEVTSTRM}, 69 | {Name: "aes", Feature: &ARM.HasAES}, 70 | {Name: "crc32", Feature: &ARM.HasCRC32}, 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_arm64.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 cpu 6 | 7 | import "runtime" 8 | 9 | // cacheLineSize is used to prevent false sharing of cache lines. 10 | // We choose 128 because Apple Silicon, a.k.a. M1, has 128-byte cache line size. 11 | // It doesn't cost much and is much more future-proof. 12 | const cacheLineSize = 128 13 | 14 | func initOptions() { 15 | options = []option{ 16 | {Name: "fp", Feature: &ARM64.HasFP}, 17 | {Name: "asimd", Feature: &ARM64.HasASIMD}, 18 | {Name: "evstrm", Feature: &ARM64.HasEVTSTRM}, 19 | {Name: "aes", Feature: &ARM64.HasAES}, 20 | {Name: "fphp", Feature: &ARM64.HasFPHP}, 21 | {Name: "jscvt", Feature: &ARM64.HasJSCVT}, 22 | {Name: "lrcpc", Feature: &ARM64.HasLRCPC}, 23 | {Name: "pmull", Feature: &ARM64.HasPMULL}, 24 | {Name: "sha1", Feature: &ARM64.HasSHA1}, 25 | {Name: "sha2", Feature: &ARM64.HasSHA2}, 26 | {Name: "sha3", Feature: &ARM64.HasSHA3}, 27 | {Name: "sha512", Feature: &ARM64.HasSHA512}, 28 | {Name: "sm3", Feature: &ARM64.HasSM3}, 29 | {Name: "sm4", Feature: &ARM64.HasSM4}, 30 | {Name: "sve", Feature: &ARM64.HasSVE}, 31 | {Name: "sve2", Feature: &ARM64.HasSVE2}, 32 | {Name: "crc32", Feature: &ARM64.HasCRC32}, 33 | {Name: "atomics", Feature: &ARM64.HasATOMICS}, 34 | {Name: "asimdhp", Feature: &ARM64.HasASIMDHP}, 35 | {Name: "cpuid", Feature: &ARM64.HasCPUID}, 36 | {Name: "asimrdm", Feature: &ARM64.HasASIMDRDM}, 37 | {Name: "fcma", Feature: &ARM64.HasFCMA}, 38 | {Name: "dcpop", Feature: &ARM64.HasDCPOP}, 39 | {Name: "asimddp", Feature: &ARM64.HasASIMDDP}, 40 | {Name: "asimdfhm", Feature: &ARM64.HasASIMDFHM}, 41 | {Name: "dit", Feature: &ARM64.HasDIT}, 42 | {Name: "i8mm", Feature: &ARM64.HasI8MM}, 43 | } 44 | } 45 | 46 | func archInit() { 47 | switch runtime.GOOS { 48 | case "freebsd": 49 | readARM64Registers() 50 | case "linux", "netbsd", "openbsd": 51 | doinit() 52 | default: 53 | // Many platforms don't seem to allow reading these registers. 54 | setMinimalFeatures() 55 | } 56 | } 57 | 58 | // setMinimalFeatures fakes the minimal ARM64 features expected by 59 | // TestARM64minimalFeatures. 60 | func setMinimalFeatures() { 61 | ARM64.HasASIMD = true 62 | ARM64.HasFP = true 63 | } 64 | 65 | func readARM64Registers() { 66 | Initialized = true 67 | 68 | parseARM64SystemRegisters(getisar0(), getisar1(), getpfr0()) 69 | } 70 | 71 | func parseARM64SystemRegisters(isar0, isar1, pfr0 uint64) { 72 | // ID_AA64ISAR0_EL1 73 | switch extractBits(isar0, 4, 7) { 74 | case 1: 75 | ARM64.HasAES = true 76 | case 2: 77 | ARM64.HasAES = true 78 | ARM64.HasPMULL = true 79 | } 80 | 81 | switch extractBits(isar0, 8, 11) { 82 | case 1: 83 | ARM64.HasSHA1 = true 84 | } 85 | 86 | switch extractBits(isar0, 12, 15) { 87 | case 1: 88 | ARM64.HasSHA2 = true 89 | case 2: 90 | ARM64.HasSHA2 = true 91 | ARM64.HasSHA512 = true 92 | } 93 | 94 | switch extractBits(isar0, 16, 19) { 95 | case 1: 96 | ARM64.HasCRC32 = true 97 | } 98 | 99 | switch extractBits(isar0, 20, 23) { 100 | case 2: 101 | ARM64.HasATOMICS = true 102 | } 103 | 104 | switch extractBits(isar0, 28, 31) { 105 | case 1: 106 | ARM64.HasASIMDRDM = true 107 | } 108 | 109 | switch extractBits(isar0, 32, 35) { 110 | case 1: 111 | ARM64.HasSHA3 = true 112 | } 113 | 114 | switch extractBits(isar0, 36, 39) { 115 | case 1: 116 | ARM64.HasSM3 = true 117 | } 118 | 119 | switch extractBits(isar0, 40, 43) { 120 | case 1: 121 | ARM64.HasSM4 = true 122 | } 123 | 124 | switch extractBits(isar0, 44, 47) { 125 | case 1: 126 | ARM64.HasASIMDDP = true 127 | } 128 | 129 | // ID_AA64ISAR1_EL1 130 | switch extractBits(isar1, 0, 3) { 131 | case 1: 132 | ARM64.HasDCPOP = true 133 | } 134 | 135 | switch extractBits(isar1, 12, 15) { 136 | case 1: 137 | ARM64.HasJSCVT = true 138 | } 139 | 140 | switch extractBits(isar1, 16, 19) { 141 | case 1: 142 | ARM64.HasFCMA = true 143 | } 144 | 145 | switch extractBits(isar1, 20, 23) { 146 | case 1: 147 | ARM64.HasLRCPC = true 148 | } 149 | 150 | switch extractBits(isar1, 52, 55) { 151 | case 1: 152 | ARM64.HasI8MM = true 153 | } 154 | 155 | // ID_AA64PFR0_EL1 156 | switch extractBits(pfr0, 16, 19) { 157 | case 0: 158 | ARM64.HasFP = true 159 | case 1: 160 | ARM64.HasFP = true 161 | ARM64.HasFPHP = true 162 | } 163 | 164 | switch extractBits(pfr0, 20, 23) { 165 | case 0: 166 | ARM64.HasASIMD = true 167 | case 1: 168 | ARM64.HasASIMD = true 169 | ARM64.HasASIMDHP = true 170 | } 171 | 172 | switch extractBits(pfr0, 32, 35) { 173 | case 1: 174 | ARM64.HasSVE = true 175 | 176 | parseARM64SVERegister(getzfr0()) 177 | } 178 | 179 | switch extractBits(pfr0, 48, 51) { 180 | case 1: 181 | ARM64.HasDIT = true 182 | } 183 | } 184 | 185 | func parseARM64SVERegister(zfr0 uint64) { 186 | switch extractBits(zfr0, 0, 3) { 187 | case 1: 188 | ARM64.HasSVE2 = true 189 | } 190 | } 191 | 192 | func extractBits(data uint64, start, end uint) uint { 193 | return (uint)(data>>start) & ((1 << (end - start + 1)) - 1) 194 | } 195 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_arm64.s: -------------------------------------------------------------------------------- 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 gc 6 | 7 | #include "textflag.h" 8 | 9 | // func getisar0() uint64 10 | TEXT ·getisar0(SB),NOSPLIT,$0-8 11 | // get Instruction Set Attributes 0 into x0 12 | // mrs x0, ID_AA64ISAR0_EL1 = d5380600 13 | WORD $0xd5380600 14 | MOVD R0, ret+0(FP) 15 | RET 16 | 17 | // func getisar1() uint64 18 | TEXT ·getisar1(SB),NOSPLIT,$0-8 19 | // get Instruction Set Attributes 1 into x0 20 | // mrs x0, ID_AA64ISAR1_EL1 = d5380620 21 | WORD $0xd5380620 22 | MOVD R0, ret+0(FP) 23 | RET 24 | 25 | // func getpfr0() uint64 26 | TEXT ·getpfr0(SB),NOSPLIT,$0-8 27 | // get Processor Feature Register 0 into x0 28 | // mrs x0, ID_AA64PFR0_EL1 = d5380400 29 | WORD $0xd5380400 30 | MOVD R0, ret+0(FP) 31 | RET 32 | 33 | // func getzfr0() uint64 34 | TEXT ·getzfr0(SB),NOSPLIT,$0-8 35 | // get SVE Feature Register 0 into x0 36 | // mrs x0, ID_AA64ZFR0_EL1 = d5380480 37 | WORD $0xd5380480 38 | MOVD R0, ret+0(FP) 39 | RET 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_darwin_x86.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 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 darwin && amd64 && gc 6 | 7 | package cpu 8 | 9 | // darwinSupportsAVX512 checks Darwin kernel for AVX512 support via sysctl 10 | // call (see issue 43089). It also restricts AVX512 support for Darwin to 11 | // kernel version 21.3.0 (MacOS 12.2.0) or later (see issue 49233). 12 | // 13 | // Background: 14 | // Darwin implements a special mechanism to economize on thread state when 15 | // AVX512 specific registers are not in use. This scheme minimizes state when 16 | // preempting threads that haven't yet used any AVX512 instructions, but adds 17 | // special requirements to check for AVX512 hardware support at runtime (e.g. 18 | // via sysctl call or commpage inspection). See issue 43089 and link below for 19 | // full background: 20 | // https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.1.10/osfmk/i386/fpu.c#L214-L240 21 | // 22 | // Additionally, all versions of the Darwin kernel from 19.6.0 through 21.2.0 23 | // (corresponding to MacOS 10.15.6 - 12.1) have a bug that can cause corruption 24 | // of the AVX512 mask registers (K0-K7) upon signal return. For this reason 25 | // AVX512 is considered unsafe to use on Darwin for kernel versions prior to 26 | // 21.3.0, where a fix has been confirmed. See issue 49233 for full background. 27 | func darwinSupportsAVX512() bool { 28 | return darwinSysctlEnabled([]byte("hw.optional.avx512f\x00")) && darwinKernelVersionCheck(21, 3, 0) 29 | } 30 | 31 | // Ensure Darwin kernel version is at least major.minor.patch, avoiding dependencies 32 | func darwinKernelVersionCheck(major, minor, patch int) bool { 33 | var release [256]byte 34 | err := darwinOSRelease(&release) 35 | if err != nil { 36 | return false 37 | } 38 | 39 | var mmp [3]int 40 | c := 0 41 | Loop: 42 | for _, b := range release[:] { 43 | switch { 44 | case b >= '0' && b <= '9': 45 | mmp[c] = 10*mmp[c] + int(b-'0') 46 | case b == '.': 47 | c++ 48 | if c > 2 { 49 | return false 50 | } 51 | case b == 0: 52 | break Loop 53 | default: 54 | return false 55 | } 56 | } 57 | if c != 2 { 58 | return false 59 | } 60 | return mmp[0] > major || mmp[0] == major && (mmp[1] > minor || mmp[1] == minor && mmp[2] >= patch) 61 | } 62 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gc_arm64.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 gc 6 | 7 | package cpu 8 | 9 | func getisar0() uint64 10 | func getisar1() uint64 11 | func getpfr0() uint64 12 | func getzfr0() uint64 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gc_s390x.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 gc 6 | 7 | package cpu 8 | 9 | // haveAsmFunctions reports whether the other functions in this file can 10 | // be safely called. 11 | func haveAsmFunctions() bool { return true } 12 | 13 | // The following feature detection functions are defined in cpu_s390x.s. 14 | // They are likely to be expensive to call so the results should be cached. 15 | func stfle() facilityList 16 | func kmQuery() queryResult 17 | func kmcQuery() queryResult 18 | func kmctrQuery() queryResult 19 | func kmaQuery() queryResult 20 | func kimdQuery() queryResult 21 | func klmdQuery() queryResult 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gc_x86.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 (386 || amd64 || amd64p32) && gc 6 | 7 | package cpu 8 | 9 | // cpuid is implemented in cpu_gc_x86.s for gc compiler 10 | // and in cpu_gccgo.c for gccgo. 11 | func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) 12 | 13 | // xgetbv with ecx = 0 is implemented in cpu_gc_x86.s for gc compiler 14 | // and in cpu_gccgo.c for gccgo. 15 | func xgetbv() (eax, edx uint32) 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gc_x86.s: -------------------------------------------------------------------------------- 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 (386 || amd64 || amd64p32) && gc 6 | 7 | #include "textflag.h" 8 | 9 | // func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) 10 | TEXT ·cpuid(SB), NOSPLIT, $0-24 11 | MOVL eaxArg+0(FP), AX 12 | MOVL ecxArg+4(FP), CX 13 | CPUID 14 | MOVL AX, eax+8(FP) 15 | MOVL BX, ebx+12(FP) 16 | MOVL CX, ecx+16(FP) 17 | MOVL DX, edx+20(FP) 18 | RET 19 | 20 | // func xgetbv() (eax, edx uint32) 21 | TEXT ·xgetbv(SB), NOSPLIT, $0-8 22 | MOVL $0, CX 23 | XGETBV 24 | MOVL AX, eax+0(FP) 25 | MOVL DX, edx+4(FP) 26 | RET 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gccgo_arm64.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 gccgo 6 | 7 | package cpu 8 | 9 | func getisar0() uint64 { return 0 } 10 | func getisar1() uint64 { return 0 } 11 | func getpfr0() uint64 { return 0 } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gccgo_s390x.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 gccgo 6 | 7 | package cpu 8 | 9 | // haveAsmFunctions reports whether the other functions in this file can 10 | // be safely called. 11 | func haveAsmFunctions() bool { return false } 12 | 13 | // TODO(mundaym): the following feature detection functions are currently 14 | // stubs. See https://golang.org/cl/162887 for how to fix this. 15 | // They are likely to be expensive to call so the results should be cached. 16 | func stfle() facilityList { panic("not implemented for gccgo") } 17 | func kmQuery() queryResult { panic("not implemented for gccgo") } 18 | func kmcQuery() queryResult { panic("not implemented for gccgo") } 19 | func kmctrQuery() queryResult { panic("not implemented for gccgo") } 20 | func kmaQuery() queryResult { panic("not implemented for gccgo") } 21 | func kimdQuery() queryResult { panic("not implemented for gccgo") } 22 | func klmdQuery() queryResult { panic("not implemented for gccgo") } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.c: -------------------------------------------------------------------------------- 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 (386 || amd64 || amd64p32) && gccgo 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | // Need to wrap __get_cpuid_count because it's declared as static. 12 | int 13 | gccgoGetCpuidCount(uint32_t leaf, uint32_t subleaf, 14 | uint32_t *eax, uint32_t *ebx, 15 | uint32_t *ecx, uint32_t *edx) 16 | { 17 | return __get_cpuid_count(leaf, subleaf, eax, ebx, ecx, edx); 18 | } 19 | 20 | #pragma GCC diagnostic ignored "-Wunknown-pragmas" 21 | #pragma GCC push_options 22 | #pragma GCC target("xsave") 23 | #pragma clang attribute push (__attribute__((target("xsave"))), apply_to=function) 24 | 25 | // xgetbv reads the contents of an XCR (Extended Control Register) 26 | // specified in the ECX register into registers EDX:EAX. 27 | // Currently, the only supported value for XCR is 0. 28 | void 29 | gccgoXgetbv(uint32_t *eax, uint32_t *edx) 30 | { 31 | uint64_t v = _xgetbv(0); 32 | *eax = v & 0xffffffff; 33 | *edx = v >> 32; 34 | } 35 | 36 | #pragma clang attribute pop 37 | #pragma GCC pop_options 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_gccgo_x86.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 (386 || amd64 || amd64p32) && gccgo 6 | 7 | package cpu 8 | 9 | //extern gccgoGetCpuidCount 10 | func gccgoGetCpuidCount(eaxArg, ecxArg uint32, eax, ebx, ecx, edx *uint32) 11 | 12 | func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) { 13 | var a, b, c, d uint32 14 | gccgoGetCpuidCount(eaxArg, ecxArg, &a, &b, &c, &d) 15 | return a, b, c, d 16 | } 17 | 18 | //extern gccgoXgetbv 19 | func gccgoXgetbv(eax, edx *uint32) 20 | 21 | func xgetbv() (eax, edx uint32) { 22 | var a, d uint32 23 | gccgoXgetbv(&a, &d) 24 | return a, d 25 | } 26 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux.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 !386 && !amd64 && !amd64p32 && !arm64 6 | 7 | package cpu 8 | 9 | func archInit() { 10 | if err := readHWCAP(); err != nil { 11 | return 12 | } 13 | doinit() 14 | Initialized = true 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux_arm.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 cpu 6 | 7 | func doinit() { 8 | ARM.HasSWP = isSet(hwCap, hwcap_SWP) 9 | ARM.HasHALF = isSet(hwCap, hwcap_HALF) 10 | ARM.HasTHUMB = isSet(hwCap, hwcap_THUMB) 11 | ARM.Has26BIT = isSet(hwCap, hwcap_26BIT) 12 | ARM.HasFASTMUL = isSet(hwCap, hwcap_FAST_MULT) 13 | ARM.HasFPA = isSet(hwCap, hwcap_FPA) 14 | ARM.HasVFP = isSet(hwCap, hwcap_VFP) 15 | ARM.HasEDSP = isSet(hwCap, hwcap_EDSP) 16 | ARM.HasJAVA = isSet(hwCap, hwcap_JAVA) 17 | ARM.HasIWMMXT = isSet(hwCap, hwcap_IWMMXT) 18 | ARM.HasCRUNCH = isSet(hwCap, hwcap_CRUNCH) 19 | ARM.HasTHUMBEE = isSet(hwCap, hwcap_THUMBEE) 20 | ARM.HasNEON = isSet(hwCap, hwcap_NEON) 21 | ARM.HasVFPv3 = isSet(hwCap, hwcap_VFPv3) 22 | ARM.HasVFPv3D16 = isSet(hwCap, hwcap_VFPv3D16) 23 | ARM.HasTLS = isSet(hwCap, hwcap_TLS) 24 | ARM.HasVFPv4 = isSet(hwCap, hwcap_VFPv4) 25 | ARM.HasIDIVA = isSet(hwCap, hwcap_IDIVA) 26 | ARM.HasIDIVT = isSet(hwCap, hwcap_IDIVT) 27 | ARM.HasVFPD32 = isSet(hwCap, hwcap_VFPD32) 28 | ARM.HasLPAE = isSet(hwCap, hwcap_LPAE) 29 | ARM.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM) 30 | ARM.HasAES = isSet(hwCap2, hwcap2_AES) 31 | ARM.HasPMULL = isSet(hwCap2, hwcap2_PMULL) 32 | ARM.HasSHA1 = isSet(hwCap2, hwcap2_SHA1) 33 | ARM.HasSHA2 = isSet(hwCap2, hwcap2_SHA2) 34 | ARM.HasCRC32 = isSet(hwCap2, hwcap2_CRC32) 35 | } 36 | 37 | func isSet(hwc uint, value uint) bool { 38 | return hwc&value != 0 39 | } 40 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux_arm64.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 cpu 6 | 7 | import ( 8 | "strings" 9 | "syscall" 10 | ) 11 | 12 | // HWCAP/HWCAP2 bits. These are exposed by Linux. 13 | const ( 14 | hwcap_FP = 1 << 0 15 | hwcap_ASIMD = 1 << 1 16 | hwcap_EVTSTRM = 1 << 2 17 | hwcap_AES = 1 << 3 18 | hwcap_PMULL = 1 << 4 19 | hwcap_SHA1 = 1 << 5 20 | hwcap_SHA2 = 1 << 6 21 | hwcap_CRC32 = 1 << 7 22 | hwcap_ATOMICS = 1 << 8 23 | hwcap_FPHP = 1 << 9 24 | hwcap_ASIMDHP = 1 << 10 25 | hwcap_CPUID = 1 << 11 26 | hwcap_ASIMDRDM = 1 << 12 27 | hwcap_JSCVT = 1 << 13 28 | hwcap_FCMA = 1 << 14 29 | hwcap_LRCPC = 1 << 15 30 | hwcap_DCPOP = 1 << 16 31 | hwcap_SHA3 = 1 << 17 32 | hwcap_SM3 = 1 << 18 33 | hwcap_SM4 = 1 << 19 34 | hwcap_ASIMDDP = 1 << 20 35 | hwcap_SHA512 = 1 << 21 36 | hwcap_SVE = 1 << 22 37 | hwcap_ASIMDFHM = 1 << 23 38 | hwcap_DIT = 1 << 24 39 | 40 | hwcap2_SVE2 = 1 << 1 41 | hwcap2_I8MM = 1 << 13 42 | ) 43 | 44 | // linuxKernelCanEmulateCPUID reports whether we're running 45 | // on Linux 4.11+. Ideally we'd like to ask the question about 46 | // whether the current kernel contains 47 | // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=77c97b4ee21290f5f083173d957843b615abbff2 48 | // but the version number will have to do. 49 | func linuxKernelCanEmulateCPUID() bool { 50 | var un syscall.Utsname 51 | syscall.Uname(&un) 52 | var sb strings.Builder 53 | for _, b := range un.Release[:] { 54 | if b == 0 { 55 | break 56 | } 57 | sb.WriteByte(byte(b)) 58 | } 59 | major, minor, _, ok := parseRelease(sb.String()) 60 | return ok && (major > 4 || major == 4 && minor >= 11) 61 | } 62 | 63 | func doinit() { 64 | if err := readHWCAP(); err != nil { 65 | // We failed to read /proc/self/auxv. This can happen if the binary has 66 | // been given extra capabilities(7) with /bin/setcap. 67 | // 68 | // When this happens, we have two options. If the Linux kernel is new 69 | // enough (4.11+), we can read the arm64 registers directly which'll 70 | // trap into the kernel and then return back to userspace. 71 | // 72 | // But on older kernels, such as Linux 4.4.180 as used on many Synology 73 | // devices, calling readARM64Registers (specifically getisar0) will 74 | // cause a SIGILL and we'll die. So for older kernels, parse /proc/cpuinfo 75 | // instead. 76 | // 77 | // See golang/go#57336. 78 | if linuxKernelCanEmulateCPUID() { 79 | readARM64Registers() 80 | } else { 81 | readLinuxProcCPUInfo() 82 | } 83 | return 84 | } 85 | 86 | // HWCAP feature bits 87 | ARM64.HasFP = isSet(hwCap, hwcap_FP) 88 | ARM64.HasASIMD = isSet(hwCap, hwcap_ASIMD) 89 | ARM64.HasEVTSTRM = isSet(hwCap, hwcap_EVTSTRM) 90 | ARM64.HasAES = isSet(hwCap, hwcap_AES) 91 | ARM64.HasPMULL = isSet(hwCap, hwcap_PMULL) 92 | ARM64.HasSHA1 = isSet(hwCap, hwcap_SHA1) 93 | ARM64.HasSHA2 = isSet(hwCap, hwcap_SHA2) 94 | ARM64.HasCRC32 = isSet(hwCap, hwcap_CRC32) 95 | ARM64.HasATOMICS = isSet(hwCap, hwcap_ATOMICS) 96 | ARM64.HasFPHP = isSet(hwCap, hwcap_FPHP) 97 | ARM64.HasASIMDHP = isSet(hwCap, hwcap_ASIMDHP) 98 | ARM64.HasCPUID = isSet(hwCap, hwcap_CPUID) 99 | ARM64.HasASIMDRDM = isSet(hwCap, hwcap_ASIMDRDM) 100 | ARM64.HasJSCVT = isSet(hwCap, hwcap_JSCVT) 101 | ARM64.HasFCMA = isSet(hwCap, hwcap_FCMA) 102 | ARM64.HasLRCPC = isSet(hwCap, hwcap_LRCPC) 103 | ARM64.HasDCPOP = isSet(hwCap, hwcap_DCPOP) 104 | ARM64.HasSHA3 = isSet(hwCap, hwcap_SHA3) 105 | ARM64.HasSM3 = isSet(hwCap, hwcap_SM3) 106 | ARM64.HasSM4 = isSet(hwCap, hwcap_SM4) 107 | ARM64.HasASIMDDP = isSet(hwCap, hwcap_ASIMDDP) 108 | ARM64.HasSHA512 = isSet(hwCap, hwcap_SHA512) 109 | ARM64.HasSVE = isSet(hwCap, hwcap_SVE) 110 | ARM64.HasASIMDFHM = isSet(hwCap, hwcap_ASIMDFHM) 111 | ARM64.HasDIT = isSet(hwCap, hwcap_DIT) 112 | 113 | // HWCAP2 feature bits 114 | ARM64.HasSVE2 = isSet(hwCap2, hwcap2_SVE2) 115 | ARM64.HasI8MM = isSet(hwCap2, hwcap2_I8MM) 116 | } 117 | 118 | func isSet(hwc uint, value uint) bool { 119 | return hwc&value != 0 120 | } 121 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux_mips64x.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 | //go:build linux && (mips64 || mips64le) 6 | 7 | package cpu 8 | 9 | // HWCAP bits. These are exposed by the Linux kernel 5.4. 10 | const ( 11 | // CPU features 12 | hwcap_MIPS_MSA = 1 << 1 13 | ) 14 | 15 | func doinit() { 16 | // HWCAP feature bits 17 | MIPS64X.HasMSA = isSet(hwCap, hwcap_MIPS_MSA) 18 | } 19 | 20 | func isSet(hwc uint, value uint) bool { 21 | return hwc&value != 0 22 | } 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux_noinit.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 linux && !arm && !arm64 && !mips64 && !mips64le && !ppc64 && !ppc64le && !s390x && !riscv64 6 | 7 | package cpu 8 | 9 | func doinit() {} 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux_ppc64x.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 linux && (ppc64 || ppc64le) 6 | 7 | package cpu 8 | 9 | // HWCAP/HWCAP2 bits. These are exposed by the kernel. 10 | const ( 11 | // ISA Level 12 | _PPC_FEATURE2_ARCH_2_07 = 0x80000000 13 | _PPC_FEATURE2_ARCH_3_00 = 0x00800000 14 | 15 | // CPU features 16 | _PPC_FEATURE2_DARN = 0x00200000 17 | _PPC_FEATURE2_SCV = 0x00100000 18 | ) 19 | 20 | func doinit() { 21 | // HWCAP2 feature bits 22 | PPC64.IsPOWER8 = isSet(hwCap2, _PPC_FEATURE2_ARCH_2_07) 23 | PPC64.IsPOWER9 = isSet(hwCap2, _PPC_FEATURE2_ARCH_3_00) 24 | PPC64.HasDARN = isSet(hwCap2, _PPC_FEATURE2_DARN) 25 | PPC64.HasSCV = isSet(hwCap2, _PPC_FEATURE2_SCV) 26 | } 27 | 28 | func isSet(hwc uint, value uint) bool { 29 | return hwc&value != 0 30 | } 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_linux_s390x.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 cpu 6 | 7 | const ( 8 | // bit mask values from /usr/include/bits/hwcap.h 9 | hwcap_ZARCH = 2 10 | hwcap_STFLE = 4 11 | hwcap_MSA = 8 12 | hwcap_LDISP = 16 13 | hwcap_EIMM = 32 14 | hwcap_DFP = 64 15 | hwcap_ETF3EH = 256 16 | hwcap_VX = 2048 17 | hwcap_VXE = 8192 18 | ) 19 | 20 | func initS390Xbase() { 21 | // test HWCAP bit vector 22 | has := func(featureMask uint) bool { 23 | return hwCap&featureMask == featureMask 24 | } 25 | 26 | // mandatory 27 | S390X.HasZARCH = has(hwcap_ZARCH) 28 | 29 | // optional 30 | S390X.HasSTFLE = has(hwcap_STFLE) 31 | S390X.HasLDISP = has(hwcap_LDISP) 32 | S390X.HasEIMM = has(hwcap_EIMM) 33 | S390X.HasETF3EH = has(hwcap_ETF3EH) 34 | S390X.HasDFP = has(hwcap_DFP) 35 | S390X.HasMSA = has(hwcap_MSA) 36 | S390X.HasVX = has(hwcap_VX) 37 | if S390X.HasVX { 38 | S390X.HasVXE = has(hwcap_VXE) 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_loong64.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 loong64 6 | 7 | package cpu 8 | 9 | const cacheLineSize = 64 10 | 11 | func initOptions() { 12 | } 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_mips64x.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 mips64 || mips64le 6 | 7 | package cpu 8 | 9 | const cacheLineSize = 32 10 | 11 | func initOptions() { 12 | options = []option{ 13 | {Name: "msa", Feature: &MIPS64X.HasMSA}, 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_mipsx.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 mips || mipsle 6 | 7 | package cpu 8 | 9 | const cacheLineSize = 32 10 | 11 | func initOptions() {} 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_netbsd_arm64.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 cpu 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | // Minimal copy of functionality from x/sys/unix so the cpu package can call 13 | // sysctl without depending on x/sys/unix. 14 | 15 | const ( 16 | _CTL_QUERY = -2 17 | 18 | _SYSCTL_VERS_1 = 0x1000000 19 | ) 20 | 21 | var _zero uintptr 22 | 23 | func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { 24 | var _p0 unsafe.Pointer 25 | if len(mib) > 0 { 26 | _p0 = unsafe.Pointer(&mib[0]) 27 | } else { 28 | _p0 = unsafe.Pointer(&_zero) 29 | } 30 | _, _, errno := syscall.Syscall6( 31 | syscall.SYS___SYSCTL, 32 | uintptr(_p0), 33 | uintptr(len(mib)), 34 | uintptr(unsafe.Pointer(old)), 35 | uintptr(unsafe.Pointer(oldlen)), 36 | uintptr(unsafe.Pointer(new)), 37 | uintptr(newlen)) 38 | if errno != 0 { 39 | return errno 40 | } 41 | return nil 42 | } 43 | 44 | type sysctlNode struct { 45 | Flags uint32 46 | Num int32 47 | Name [32]int8 48 | Ver uint32 49 | __rsvd uint32 50 | Un [16]byte 51 | _sysctl_size [8]byte 52 | _sysctl_func [8]byte 53 | _sysctl_parent [8]byte 54 | _sysctl_desc [8]byte 55 | } 56 | 57 | func sysctlNodes(mib []int32) ([]sysctlNode, error) { 58 | var olen uintptr 59 | 60 | // Get a list of all sysctl nodes below the given MIB by performing 61 | // a sysctl for the given MIB with CTL_QUERY appended. 62 | mib = append(mib, _CTL_QUERY) 63 | qnode := sysctlNode{Flags: _SYSCTL_VERS_1} 64 | qp := (*byte)(unsafe.Pointer(&qnode)) 65 | sz := unsafe.Sizeof(qnode) 66 | if err := sysctl(mib, nil, &olen, qp, sz); err != nil { 67 | return nil, err 68 | } 69 | 70 | // Now that we know the size, get the actual nodes. 71 | nodes := make([]sysctlNode, olen/sz) 72 | np := (*byte)(unsafe.Pointer(&nodes[0])) 73 | if err := sysctl(mib, np, &olen, qp, sz); err != nil { 74 | return nil, err 75 | } 76 | 77 | return nodes, nil 78 | } 79 | 80 | func nametomib(name string) ([]int32, error) { 81 | // Split name into components. 82 | var parts []string 83 | last := 0 84 | for i := 0; i < len(name); i++ { 85 | if name[i] == '.' { 86 | parts = append(parts, name[last:i]) 87 | last = i + 1 88 | } 89 | } 90 | parts = append(parts, name[last:]) 91 | 92 | mib := []int32{} 93 | // Discover the nodes and construct the MIB OID. 94 | for partno, part := range parts { 95 | nodes, err := sysctlNodes(mib) 96 | if err != nil { 97 | return nil, err 98 | } 99 | for _, node := range nodes { 100 | n := make([]byte, 0) 101 | for i := range node.Name { 102 | if node.Name[i] != 0 { 103 | n = append(n, byte(node.Name[i])) 104 | } 105 | } 106 | if string(n) == part { 107 | mib = append(mib, int32(node.Num)) 108 | break 109 | } 110 | } 111 | if len(mib) != partno+1 { 112 | return nil, err 113 | } 114 | } 115 | 116 | return mib, nil 117 | } 118 | 119 | // aarch64SysctlCPUID is struct aarch64_sysctl_cpu_id from NetBSD's 120 | type aarch64SysctlCPUID struct { 121 | midr uint64 /* Main ID Register */ 122 | revidr uint64 /* Revision ID Register */ 123 | mpidr uint64 /* Multiprocessor Affinity Register */ 124 | aa64dfr0 uint64 /* A64 Debug Feature Register 0 */ 125 | aa64dfr1 uint64 /* A64 Debug Feature Register 1 */ 126 | aa64isar0 uint64 /* A64 Instruction Set Attribute Register 0 */ 127 | aa64isar1 uint64 /* A64 Instruction Set Attribute Register 1 */ 128 | aa64mmfr0 uint64 /* A64 Memory Model Feature Register 0 */ 129 | aa64mmfr1 uint64 /* A64 Memory Model Feature Register 1 */ 130 | aa64mmfr2 uint64 /* A64 Memory Model Feature Register 2 */ 131 | aa64pfr0 uint64 /* A64 Processor Feature Register 0 */ 132 | aa64pfr1 uint64 /* A64 Processor Feature Register 1 */ 133 | aa64zfr0 uint64 /* A64 SVE Feature ID Register 0 */ 134 | mvfr0 uint32 /* Media and VFP Feature Register 0 */ 135 | mvfr1 uint32 /* Media and VFP Feature Register 1 */ 136 | mvfr2 uint32 /* Media and VFP Feature Register 2 */ 137 | pad uint32 138 | clidr uint64 /* Cache Level ID Register */ 139 | ctr uint64 /* Cache Type Register */ 140 | } 141 | 142 | func sysctlCPUID(name string) (*aarch64SysctlCPUID, error) { 143 | mib, err := nametomib(name) 144 | if err != nil { 145 | return nil, err 146 | } 147 | 148 | out := aarch64SysctlCPUID{} 149 | n := unsafe.Sizeof(out) 150 | _, _, errno := syscall.Syscall6( 151 | syscall.SYS___SYSCTL, 152 | uintptr(unsafe.Pointer(&mib[0])), 153 | uintptr(len(mib)), 154 | uintptr(unsafe.Pointer(&out)), 155 | uintptr(unsafe.Pointer(&n)), 156 | uintptr(0), 157 | uintptr(0)) 158 | if errno != 0 { 159 | return nil, errno 160 | } 161 | return &out, nil 162 | } 163 | 164 | func doinit() { 165 | cpuid, err := sysctlCPUID("machdep.cpu0.cpu_id") 166 | if err != nil { 167 | setMinimalFeatures() 168 | return 169 | } 170 | parseARM64SystemRegisters(cpuid.aa64isar0, cpuid.aa64isar1, cpuid.aa64pfr0) 171 | 172 | Initialized = true 173 | } 174 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.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 cpu 6 | 7 | import ( 8 | "syscall" 9 | "unsafe" 10 | ) 11 | 12 | // Minimal copy of functionality from x/sys/unix so the cpu package can call 13 | // sysctl without depending on x/sys/unix. 14 | 15 | const ( 16 | // From OpenBSD's sys/sysctl.h. 17 | _CTL_MACHDEP = 7 18 | 19 | // From OpenBSD's machine/cpu.h. 20 | _CPU_ID_AA64ISAR0 = 2 21 | _CPU_ID_AA64ISAR1 = 3 22 | ) 23 | 24 | // Implemented in the runtime package (runtime/sys_openbsd3.go) 25 | func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) 26 | 27 | //go:linkname syscall_syscall6 syscall.syscall6 28 | 29 | func sysctl(mib []uint32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) { 30 | _, _, errno := syscall_syscall6(libc_sysctl_trampoline_addr, uintptr(unsafe.Pointer(&mib[0])), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), uintptr(newlen)) 31 | if errno != 0 { 32 | return errno 33 | } 34 | return nil 35 | } 36 | 37 | var libc_sysctl_trampoline_addr uintptr 38 | 39 | //go:cgo_import_dynamic libc_sysctl sysctl "libc.so" 40 | 41 | func sysctlUint64(mib []uint32) (uint64, bool) { 42 | var out uint64 43 | nout := unsafe.Sizeof(out) 44 | if err := sysctl(mib, (*byte)(unsafe.Pointer(&out)), &nout, nil, 0); err != nil { 45 | return 0, false 46 | } 47 | return out, true 48 | } 49 | 50 | func doinit() { 51 | setMinimalFeatures() 52 | 53 | // Get ID_AA64ISAR0 and ID_AA64ISAR1 from sysctl. 54 | isar0, ok := sysctlUint64([]uint32{_CTL_MACHDEP, _CPU_ID_AA64ISAR0}) 55 | if !ok { 56 | return 57 | } 58 | isar1, ok := sysctlUint64([]uint32{_CTL_MACHDEP, _CPU_ID_AA64ISAR1}) 59 | if !ok { 60 | return 61 | } 62 | parseARM64SystemRegisters(isar0, isar1, 0) 63 | 64 | Initialized = true 65 | } 66 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_openbsd_arm64.s: -------------------------------------------------------------------------------- 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 | #include "textflag.h" 6 | 7 | TEXT libc_sysctl_trampoline<>(SB),NOSPLIT,$0-0 8 | JMP libc_sysctl(SB) 9 | 10 | GLOBL ·libc_sysctl_trampoline_addr(SB), RODATA, $8 11 | DATA ·libc_sysctl_trampoline_addr(SB)/8, $libc_sysctl_trampoline<>(SB) 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_other_arm.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 | //go:build !linux && arm 6 | 7 | package cpu 8 | 9 | func archInit() {} 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_other_arm64.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 !linux && !netbsd && !openbsd && arm64 6 | 7 | package cpu 8 | 9 | func doinit() {} 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_other_mips64x.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 | //go:build !linux && (mips64 || mips64le) 6 | 7 | package cpu 8 | 9 | func archInit() { 10 | Initialized = true 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_other_ppc64x.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 !aix && !linux && (ppc64 || ppc64le) 6 | 7 | package cpu 8 | 9 | func archInit() { 10 | PPC64.IsPOWER8 = true 11 | Initialized = true 12 | } 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_other_riscv64.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 !linux && riscv64 6 | 7 | package cpu 8 | 9 | func archInit() { 10 | Initialized = true 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_other_x86.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 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 386 || amd64p32 || (amd64 && (!darwin || !gc)) 6 | 7 | package cpu 8 | 9 | func darwinSupportsAVX512() bool { 10 | panic("only implemented for gc && amd64 && darwin") 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_ppc64x.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 | //go:build ppc64 || ppc64le 6 | 7 | package cpu 8 | 9 | const cacheLineSize = 128 10 | 11 | func initOptions() { 12 | options = []option{ 13 | {Name: "darn", Feature: &PPC64.HasDARN}, 14 | {Name: "scv", Feature: &PPC64.HasSCV}, 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_riscv64.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 riscv64 6 | 7 | package cpu 8 | 9 | const cacheLineSize = 64 10 | 11 | func initOptions() { 12 | options = []option{ 13 | {Name: "fastmisaligned", Feature: &RISCV64.HasFastMisaligned}, 14 | {Name: "c", Feature: &RISCV64.HasC}, 15 | {Name: "v", Feature: &RISCV64.HasV}, 16 | {Name: "zba", Feature: &RISCV64.HasZba}, 17 | {Name: "zbb", Feature: &RISCV64.HasZbb}, 18 | {Name: "zbs", Feature: &RISCV64.HasZbs}, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_s390x.s: -------------------------------------------------------------------------------- 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 gc 6 | 7 | #include "textflag.h" 8 | 9 | // func stfle() facilityList 10 | TEXT ·stfle(SB), NOSPLIT|NOFRAME, $0-32 11 | MOVD $ret+0(FP), R1 12 | MOVD $3, R0 // last doubleword index to store 13 | XC $32, (R1), (R1) // clear 4 doublewords (32 bytes) 14 | WORD $0xb2b01000 // store facility list extended (STFLE) 15 | RET 16 | 17 | // func kmQuery() queryResult 18 | TEXT ·kmQuery(SB), NOSPLIT|NOFRAME, $0-16 19 | MOVD $0, R0 // set function code to 0 (KM-Query) 20 | MOVD $ret+0(FP), R1 // address of 16-byte return value 21 | WORD $0xB92E0024 // cipher message (KM) 22 | RET 23 | 24 | // func kmcQuery() queryResult 25 | TEXT ·kmcQuery(SB), NOSPLIT|NOFRAME, $0-16 26 | MOVD $0, R0 // set function code to 0 (KMC-Query) 27 | MOVD $ret+0(FP), R1 // address of 16-byte return value 28 | WORD $0xB92F0024 // cipher message with chaining (KMC) 29 | RET 30 | 31 | // func kmctrQuery() queryResult 32 | TEXT ·kmctrQuery(SB), NOSPLIT|NOFRAME, $0-16 33 | MOVD $0, R0 // set function code to 0 (KMCTR-Query) 34 | MOVD $ret+0(FP), R1 // address of 16-byte return value 35 | WORD $0xB92D4024 // cipher message with counter (KMCTR) 36 | RET 37 | 38 | // func kmaQuery() queryResult 39 | TEXT ·kmaQuery(SB), NOSPLIT|NOFRAME, $0-16 40 | MOVD $0, R0 // set function code to 0 (KMA-Query) 41 | MOVD $ret+0(FP), R1 // address of 16-byte return value 42 | WORD $0xb9296024 // cipher message with authentication (KMA) 43 | RET 44 | 45 | // func kimdQuery() queryResult 46 | TEXT ·kimdQuery(SB), NOSPLIT|NOFRAME, $0-16 47 | MOVD $0, R0 // set function code to 0 (KIMD-Query) 48 | MOVD $ret+0(FP), R1 // address of 16-byte return value 49 | WORD $0xB93E0024 // compute intermediate message digest (KIMD) 50 | RET 51 | 52 | // func klmdQuery() queryResult 53 | TEXT ·klmdQuery(SB), NOSPLIT|NOFRAME, $0-16 54 | MOVD $0, R0 // set function code to 0 (KLMD-Query) 55 | MOVD $ret+0(FP), R1 // address of 16-byte return value 56 | WORD $0xB93F0024 // compute last message digest (KLMD) 57 | RET 58 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_wasm.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 wasm 6 | 7 | package cpu 8 | 9 | // We're compiling the cpu package for an unknown (software-abstracted) CPU. 10 | // Make CacheLinePad an empty struct and hope that the usual struct alignment 11 | // rules are good enough. 12 | 13 | const cacheLineSize = 0 14 | 15 | func initOptions() {} 16 | 17 | func archInit() {} 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_zos.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 cpu 6 | 7 | func archInit() { 8 | doinit() 9 | Initialized = true 10 | } 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/cpu_zos_s390x.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 cpu 6 | 7 | func initS390Xbase() { 8 | // get the facilities list 9 | facilities := stfle() 10 | 11 | // mandatory 12 | S390X.HasZARCH = facilities.Has(zarch) 13 | S390X.HasSTFLE = facilities.Has(stflef) 14 | S390X.HasLDISP = facilities.Has(ldisp) 15 | S390X.HasEIMM = facilities.Has(eimm) 16 | 17 | // optional 18 | S390X.HasETF3EH = facilities.Has(etf3eh) 19 | S390X.HasDFP = facilities.Has(dfp) 20 | S390X.HasMSA = facilities.Has(msa) 21 | S390X.HasVX = facilities.Has(vx) 22 | if S390X.HasVX { 23 | S390X.HasVXE = facilities.Has(vxe) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/endian_big.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 | //go:build armbe || arm64be || m68k || mips || mips64 || mips64p32 || ppc || ppc64 || s390 || s390x || shbe || sparc || sparc64 6 | 7 | package cpu 8 | 9 | // IsBigEndian records whether the GOARCH's byte order is big endian. 10 | const IsBigEndian = true 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/endian_little.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 | //go:build 386 || amd64 || amd64p32 || alpha || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || nios2 || ppc64le || riscv || riscv64 || sh || wasm 6 | 7 | package cpu 8 | 9 | // IsBigEndian records whether the GOARCH's byte order is big endian. 10 | const IsBigEndian = false 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/hwcap_linux.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 cpu 6 | 7 | import ( 8 | "os" 9 | ) 10 | 11 | const ( 12 | _AT_HWCAP = 16 13 | _AT_HWCAP2 = 26 14 | 15 | procAuxv = "/proc/self/auxv" 16 | 17 | uintSize = int(32 << (^uint(0) >> 63)) 18 | ) 19 | 20 | // For those platforms don't have a 'cpuid' equivalent we use HWCAP/HWCAP2 21 | // These are initialized in cpu_$GOARCH.go 22 | // and should not be changed after they are initialized. 23 | var hwCap uint 24 | var hwCap2 uint 25 | 26 | func readHWCAP() error { 27 | // For Go 1.21+, get auxv from the Go runtime. 28 | if a := getAuxv(); len(a) > 0 { 29 | for len(a) >= 2 { 30 | tag, val := a[0], uint(a[1]) 31 | a = a[2:] 32 | switch tag { 33 | case _AT_HWCAP: 34 | hwCap = val 35 | case _AT_HWCAP2: 36 | hwCap2 = val 37 | } 38 | } 39 | return nil 40 | } 41 | 42 | buf, err := os.ReadFile(procAuxv) 43 | if err != nil { 44 | // e.g. on android /proc/self/auxv is not accessible, so silently 45 | // ignore the error and leave Initialized = false. On some 46 | // architectures (e.g. arm64) doinit() implements a fallback 47 | // readout and will set Initialized = true again. 48 | return err 49 | } 50 | bo := hostByteOrder() 51 | for len(buf) >= 2*(uintSize/8) { 52 | var tag, val uint 53 | switch uintSize { 54 | case 32: 55 | tag = uint(bo.Uint32(buf[0:])) 56 | val = uint(bo.Uint32(buf[4:])) 57 | buf = buf[8:] 58 | case 64: 59 | tag = uint(bo.Uint64(buf[0:])) 60 | val = uint(bo.Uint64(buf[8:])) 61 | buf = buf[16:] 62 | } 63 | switch tag { 64 | case _AT_HWCAP: 65 | hwCap = val 66 | case _AT_HWCAP2: 67 | hwCap2 = val 68 | } 69 | } 70 | return nil 71 | } 72 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/parse.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 cpu 6 | 7 | import "strconv" 8 | 9 | // parseRelease parses a dot-separated version number. It follows the semver 10 | // syntax, but allows the minor and patch versions to be elided. 11 | // 12 | // This is a copy of the Go runtime's parseRelease from 13 | // https://golang.org/cl/209597. 14 | func parseRelease(rel string) (major, minor, patch int, ok bool) { 15 | // Strip anything after a dash or plus. 16 | for i := 0; i < len(rel); i++ { 17 | if rel[i] == '-' || rel[i] == '+' { 18 | rel = rel[:i] 19 | break 20 | } 21 | } 22 | 23 | next := func() (int, bool) { 24 | for i := 0; i < len(rel); i++ { 25 | if rel[i] == '.' { 26 | ver, err := strconv.Atoi(rel[:i]) 27 | rel = rel[i+1:] 28 | return ver, err == nil 29 | } 30 | } 31 | ver, err := strconv.Atoi(rel) 32 | rel = "" 33 | return ver, err == nil 34 | } 35 | if major, ok = next(); !ok || rel == "" { 36 | return 37 | } 38 | if minor, ok = next(); !ok || rel == "" { 39 | return 40 | } 41 | patch, ok = next() 42 | return 43 | } 44 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/proc_cpuinfo_linux.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 linux && arm64 6 | 7 | package cpu 8 | 9 | import ( 10 | "errors" 11 | "io" 12 | "os" 13 | "strings" 14 | ) 15 | 16 | func readLinuxProcCPUInfo() error { 17 | f, err := os.Open("/proc/cpuinfo") 18 | if err != nil { 19 | return err 20 | } 21 | defer f.Close() 22 | 23 | var buf [1 << 10]byte // enough for first CPU 24 | n, err := io.ReadFull(f, buf[:]) 25 | if err != nil && err != io.ErrUnexpectedEOF { 26 | return err 27 | } 28 | in := string(buf[:n]) 29 | const features = "\nFeatures : " 30 | i := strings.Index(in, features) 31 | if i == -1 { 32 | return errors.New("no CPU features found") 33 | } 34 | in = in[i+len(features):] 35 | if i := strings.Index(in, "\n"); i != -1 { 36 | in = in[:i] 37 | } 38 | m := map[string]*bool{} 39 | 40 | initOptions() // need it early here; it's harmless to call twice 41 | for _, o := range options { 42 | m[o.Name] = o.Feature 43 | } 44 | // The EVTSTRM field has alias "evstrm" in Go, but Linux calls it "evtstrm". 45 | m["evtstrm"] = &ARM64.HasEVTSTRM 46 | 47 | for _, f := range strings.Fields(in) { 48 | if p, ok := m[f]; ok { 49 | *p = true 50 | } 51 | } 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/runtime_auxv.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 cpu 6 | 7 | // getAuxvFn is non-nil on Go 1.21+ (via runtime_auxv_go121.go init) 8 | // on platforms that use auxv. 9 | var getAuxvFn func() []uintptr 10 | 11 | func getAuxv() []uintptr { 12 | if getAuxvFn == nil { 13 | return nil 14 | } 15 | return getAuxvFn() 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/runtime_auxv_go121.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 | //go:build go1.21 6 | 7 | package cpu 8 | 9 | import ( 10 | _ "unsafe" // for linkname 11 | ) 12 | 13 | //go:linkname runtime_getAuxv runtime.getAuxv 14 | func runtime_getAuxv() []uintptr 15 | 16 | func init() { 17 | getAuxvFn = runtime_getAuxv 18 | } 19 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/syscall_aix_gccgo.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 | // Recreate a getsystemcfg syscall handler instead of 6 | // using the one provided by x/sys/unix to avoid having 7 | // the dependency between them. (See golang.org/issue/32102) 8 | // Moreover, this file will be used during the building of 9 | // gccgo's libgo and thus must not used a CGo method. 10 | 11 | //go:build aix && gccgo 12 | 13 | package cpu 14 | 15 | import ( 16 | "syscall" 17 | ) 18 | 19 | //extern getsystemcfg 20 | func gccgoGetsystemcfg(label uint32) (r uint64) 21 | 22 | func callgetsystemcfg(label int) (r1 uintptr, e1 syscall.Errno) { 23 | r1 = uintptr(gccgoGetsystemcfg(uint32(label))) 24 | e1 = syscall.GetErrno() 25 | return 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/syscall_aix_ppc64_gc.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 | // Minimal copy of x/sys/unix so the cpu package can make a 6 | // system call on AIX without depending on x/sys/unix. 7 | // (See golang.org/issue/32102) 8 | 9 | //go:build aix && ppc64 && gc 10 | 11 | package cpu 12 | 13 | import ( 14 | "syscall" 15 | "unsafe" 16 | ) 17 | 18 | //go:cgo_import_dynamic libc_getsystemcfg getsystemcfg "libc.a/shr_64.o" 19 | 20 | //go:linkname libc_getsystemcfg libc_getsystemcfg 21 | 22 | type syscallFunc uintptr 23 | 24 | var libc_getsystemcfg syscallFunc 25 | 26 | type errno = syscall.Errno 27 | 28 | // Implemented in runtime/syscall_aix.go. 29 | func rawSyscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err errno) 30 | func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err errno) 31 | 32 | func callgetsystemcfg(label int) (r1 uintptr, e1 errno) { 33 | r1, _, e1 = syscall6(uintptr(unsafe.Pointer(&libc_getsystemcfg)), 1, uintptr(label), 0, 0, 0, 0, 0) 34 | return 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/cpu/syscall_darwin_x86_gc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2024 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 | // Minimal copy of x/sys/unix so the cpu package can make a 6 | // system call on Darwin without depending on x/sys/unix. 7 | 8 | //go:build darwin && amd64 && gc 9 | 10 | package cpu 11 | 12 | import ( 13 | "syscall" 14 | "unsafe" 15 | ) 16 | 17 | type _C_int int32 18 | 19 | // adapted from unix.Uname() at x/sys/unix/syscall_darwin.go L419 20 | func darwinOSRelease(release *[256]byte) error { 21 | // from x/sys/unix/zerrors_openbsd_amd64.go 22 | const ( 23 | CTL_KERN = 0x1 24 | KERN_OSRELEASE = 0x2 25 | ) 26 | 27 | mib := []_C_int{CTL_KERN, KERN_OSRELEASE} 28 | n := unsafe.Sizeof(*release) 29 | 30 | return sysctl(mib, &release[0], &n, nil, 0) 31 | } 32 | 33 | type Errno = syscall.Errno 34 | 35 | var _zero uintptr // Single-word zero for use when we need a valid pointer to 0 bytes. 36 | 37 | // from x/sys/unix/zsyscall_darwin_amd64.go L791-807 38 | func sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error { 39 | var _p0 unsafe.Pointer 40 | if len(mib) > 0 { 41 | _p0 = unsafe.Pointer(&mib[0]) 42 | } else { 43 | _p0 = unsafe.Pointer(&_zero) 44 | } 45 | if _, _, err := syscall_syscall6( 46 | libc_sysctl_trampoline_addr, 47 | uintptr(_p0), 48 | uintptr(len(mib)), 49 | uintptr(unsafe.Pointer(old)), 50 | uintptr(unsafe.Pointer(oldlen)), 51 | uintptr(unsafe.Pointer(new)), 52 | uintptr(newlen), 53 | ); err != 0 { 54 | return err 55 | } 56 | 57 | return nil 58 | } 59 | 60 | var libc_sysctl_trampoline_addr uintptr 61 | 62 | // adapted from internal/cpu/cpu_arm64_darwin.go 63 | func darwinSysctlEnabled(name []byte) bool { 64 | out := int32(0) 65 | nout := unsafe.Sizeof(out) 66 | if ret := sysctlbyname(&name[0], (*byte)(unsafe.Pointer(&out)), &nout, nil, 0); ret != nil { 67 | return false 68 | } 69 | return out > 0 70 | } 71 | 72 | //go:cgo_import_dynamic libc_sysctl sysctl "/usr/lib/libSystem.B.dylib" 73 | 74 | var libc_sysctlbyname_trampoline_addr uintptr 75 | 76 | // adapted from runtime/sys_darwin.go in the pattern of sysctl() above, as defined in x/sys/unix 77 | func sysctlbyname(name *byte, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error { 78 | if _, _, err := syscall_syscall6( 79 | libc_sysctlbyname_trampoline_addr, 80 | uintptr(unsafe.Pointer(name)), 81 | uintptr(unsafe.Pointer(old)), 82 | uintptr(unsafe.Pointer(oldlen)), 83 | uintptr(unsafe.Pointer(new)), 84 | uintptr(newlen), 85 | 0, 86 | ); err != 0 { 87 | return err 88 | } 89 | 90 | return nil 91 | } 92 | 93 | //go:cgo_import_dynamic libc_sysctlbyname sysctlbyname "/usr/lib/libSystem.B.dylib" 94 | 95 | // Implemented in the runtime package (runtime/sys_darwin.go) 96 | func syscall_syscall6(fn, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) 97 | 98 | //go:linkname syscall_syscall6 syscall.syscall6 99 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | This project is covered by two different licenses: MIT and Apache. 3 | 4 | #### MIT License #### 5 | 6 | The following files were ported to Go from C files of libyaml, and thus 7 | are still covered by their original MIT license, with the additional 8 | copyright staring in 2011 when the project was ported over: 9 | 10 | apic.go emitterc.go parserc.go readerc.go scannerc.go 11 | writerc.go yamlh.go yamlprivateh.go 12 | 13 | Copyright (c) 2006-2010 Kirill Simonov 14 | Copyright (c) 2006-2011 Kirill Simonov 15 | 16 | Permission is hereby granted, free of charge, to any person obtaining a copy of 17 | this software and associated documentation files (the "Software"), to deal in 18 | the Software without restriction, including without limitation the rights to 19 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 20 | of the Software, and to permit persons to whom the Software is furnished to do 21 | so, subject to the following conditions: 22 | 23 | The above copyright notice and this permission notice shall be included in all 24 | copies or substantial portions of the Software. 25 | 26 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 32 | SOFTWARE. 33 | 34 | ### Apache License ### 35 | 36 | All the remaining project files are covered by the Apache license: 37 | 38 | Copyright (c) 2011-2019 Canonical Ltd 39 | 40 | Licensed under the Apache License, Version 2.0 (the "License"); 41 | you may not use this file except in compliance with the License. 42 | You may obtain a copy of the License at 43 | 44 | http://www.apache.org/licenses/LICENSE-2.0 45 | 46 | Unless required by applicable law or agreed to in writing, software 47 | distributed under the License is distributed on an "AS IS" BASIS, 48 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | See the License for the specific language governing permissions and 50 | limitations under the License. 51 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2011-2016 Canonical Ltd. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/README.md: -------------------------------------------------------------------------------- 1 | # YAML support for the Go language 2 | 3 | Introduction 4 | ------------ 5 | 6 | The yaml package enables Go programs to comfortably encode and decode YAML 7 | values. It was developed within [Canonical](https://www.canonical.com) as 8 | part of the [juju](https://juju.ubuntu.com) project, and is based on a 9 | pure Go port of the well-known [libyaml](http://pyyaml.org/wiki/LibYAML) 10 | C library to parse and generate YAML data quickly and reliably. 11 | 12 | Compatibility 13 | ------------- 14 | 15 | The yaml package supports most of YAML 1.2, but preserves some behavior 16 | from 1.1 for backwards compatibility. 17 | 18 | Specifically, as of v3 of the yaml package: 19 | 20 | - YAML 1.1 bools (_yes/no, on/off_) are supported as long as they are being 21 | decoded into a typed bool value. Otherwise they behave as a string. Booleans 22 | in YAML 1.2 are _true/false_ only. 23 | - Octals encode and decode as _0777_ per YAML 1.1, rather than _0o777_ 24 | as specified in YAML 1.2, because most parsers still use the old format. 25 | Octals in the _0o777_ format are supported though, so new files work. 26 | - Does not support base-60 floats. These are gone from YAML 1.2, and were 27 | actually never supported by this package as it's clearly a poor choice. 28 | 29 | and offers backwards 30 | compatibility with YAML 1.1 in some cases. 31 | 1.2, including support for 32 | anchors, tags, map merging, etc. Multi-document unmarshalling is not yet 33 | implemented, and base-60 floats from YAML 1.1 are purposefully not 34 | supported since they're a poor design and are gone in YAML 1.2. 35 | 36 | Installation and usage 37 | ---------------------- 38 | 39 | The import path for the package is *gopkg.in/yaml.v3*. 40 | 41 | To install it, run: 42 | 43 | go get gopkg.in/yaml.v3 44 | 45 | API documentation 46 | ----------------- 47 | 48 | If opened in a browser, the import path itself leads to the API documentation: 49 | 50 | - [https://gopkg.in/yaml.v3](https://gopkg.in/yaml.v3) 51 | 52 | API stability 53 | ------------- 54 | 55 | The package API for yaml v3 will remain stable as described in [gopkg.in](https://gopkg.in). 56 | 57 | 58 | License 59 | ------- 60 | 61 | The yaml package is licensed under the MIT and Apache License 2.0 licenses. 62 | Please see the LICENSE file for details. 63 | 64 | 65 | Example 66 | ------- 67 | 68 | ```Go 69 | package main 70 | 71 | import ( 72 | "fmt" 73 | "log" 74 | 75 | "gopkg.in/yaml.v3" 76 | ) 77 | 78 | var data = ` 79 | a: Easy! 80 | b: 81 | c: 2 82 | d: [3, 4] 83 | ` 84 | 85 | // Note: struct fields must be public in order for unmarshal to 86 | // correctly populate the data. 87 | type T struct { 88 | A string 89 | B struct { 90 | RenamedC int `yaml:"c"` 91 | D []int `yaml:",flow"` 92 | } 93 | } 94 | 95 | func main() { 96 | t := T{} 97 | 98 | err := yaml.Unmarshal([]byte(data), &t) 99 | if err != nil { 100 | log.Fatalf("error: %v", err) 101 | } 102 | fmt.Printf("--- t:\n%v\n\n", t) 103 | 104 | d, err := yaml.Marshal(&t) 105 | if err != nil { 106 | log.Fatalf("error: %v", err) 107 | } 108 | fmt.Printf("--- t dump:\n%s\n\n", string(d)) 109 | 110 | m := make(map[interface{}]interface{}) 111 | 112 | err = yaml.Unmarshal([]byte(data), &m) 113 | if err != nil { 114 | log.Fatalf("error: %v", err) 115 | } 116 | fmt.Printf("--- m:\n%v\n\n", m) 117 | 118 | d, err = yaml.Marshal(&m) 119 | if err != nil { 120 | log.Fatalf("error: %v", err) 121 | } 122 | fmt.Printf("--- m dump:\n%s\n\n", string(d)) 123 | } 124 | ``` 125 | 126 | This example will generate the following output: 127 | 128 | ``` 129 | --- t: 130 | {Easy! {2 [3 4]}} 131 | 132 | --- t dump: 133 | a: Easy! 134 | b: 135 | c: 2 136 | d: [3, 4] 137 | 138 | 139 | --- m: 140 | map[a:Easy! b:map[c:2 d:[3 4]]] 141 | 142 | --- m dump: 143 | a: Easy! 144 | b: 145 | c: 2 146 | d: 147 | - 3 148 | - 4 149 | ``` 150 | 151 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/sorter.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011-2019 Canonical Ltd 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package yaml 17 | 18 | import ( 19 | "reflect" 20 | "unicode" 21 | ) 22 | 23 | type keyList []reflect.Value 24 | 25 | func (l keyList) Len() int { return len(l) } 26 | func (l keyList) Swap(i, j int) { l[i], l[j] = l[j], l[i] } 27 | func (l keyList) Less(i, j int) bool { 28 | a := l[i] 29 | b := l[j] 30 | ak := a.Kind() 31 | bk := b.Kind() 32 | for (ak == reflect.Interface || ak == reflect.Ptr) && !a.IsNil() { 33 | a = a.Elem() 34 | ak = a.Kind() 35 | } 36 | for (bk == reflect.Interface || bk == reflect.Ptr) && !b.IsNil() { 37 | b = b.Elem() 38 | bk = b.Kind() 39 | } 40 | af, aok := keyFloat(a) 41 | bf, bok := keyFloat(b) 42 | if aok && bok { 43 | if af != bf { 44 | return af < bf 45 | } 46 | if ak != bk { 47 | return ak < bk 48 | } 49 | return numLess(a, b) 50 | } 51 | if ak != reflect.String || bk != reflect.String { 52 | return ak < bk 53 | } 54 | ar, br := []rune(a.String()), []rune(b.String()) 55 | digits := false 56 | for i := 0; i < len(ar) && i < len(br); i++ { 57 | if ar[i] == br[i] { 58 | digits = unicode.IsDigit(ar[i]) 59 | continue 60 | } 61 | al := unicode.IsLetter(ar[i]) 62 | bl := unicode.IsLetter(br[i]) 63 | if al && bl { 64 | return ar[i] < br[i] 65 | } 66 | if al || bl { 67 | if digits { 68 | return al 69 | } else { 70 | return bl 71 | } 72 | } 73 | var ai, bi int 74 | var an, bn int64 75 | if ar[i] == '0' || br[i] == '0' { 76 | for j := i - 1; j >= 0 && unicode.IsDigit(ar[j]); j-- { 77 | if ar[j] != '0' { 78 | an = 1 79 | bn = 1 80 | break 81 | } 82 | } 83 | } 84 | for ai = i; ai < len(ar) && unicode.IsDigit(ar[ai]); ai++ { 85 | an = an*10 + int64(ar[ai]-'0') 86 | } 87 | for bi = i; bi < len(br) && unicode.IsDigit(br[bi]); bi++ { 88 | bn = bn*10 + int64(br[bi]-'0') 89 | } 90 | if an != bn { 91 | return an < bn 92 | } 93 | if ai != bi { 94 | return ai < bi 95 | } 96 | return ar[i] < br[i] 97 | } 98 | return len(ar) < len(br) 99 | } 100 | 101 | // keyFloat returns a float value for v if it is a number/bool 102 | // and whether it is a number/bool or not. 103 | func keyFloat(v reflect.Value) (f float64, ok bool) { 104 | switch v.Kind() { 105 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 106 | return float64(v.Int()), true 107 | case reflect.Float32, reflect.Float64: 108 | return v.Float(), true 109 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 110 | return float64(v.Uint()), true 111 | case reflect.Bool: 112 | if v.Bool() { 113 | return 1, true 114 | } 115 | return 0, true 116 | } 117 | return 0, false 118 | } 119 | 120 | // numLess returns whether a < b. 121 | // a and b must necessarily have the same kind. 122 | func numLess(a, b reflect.Value) bool { 123 | switch a.Kind() { 124 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: 125 | return a.Int() < b.Int() 126 | case reflect.Float32, reflect.Float64: 127 | return a.Float() < b.Float() 128 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: 129 | return a.Uint() < b.Uint() 130 | case reflect.Bool: 131 | return !a.Bool() && b.Bool() 132 | } 133 | panic("not a number") 134 | } 135 | -------------------------------------------------------------------------------- /vendor/gopkg.in/yaml.v3/writerc.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) 2011-2019 Canonical Ltd 3 | // Copyright (c) 2006-2010 Kirill Simonov 4 | // 5 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | // this software and associated documentation files (the "Software"), to deal in 7 | // the Software without restriction, including without limitation the rights to 8 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | // of the Software, and to permit persons to whom the Software is furnished to do 10 | // so, subject to the following conditions: 11 | // 12 | // The above copyright notice and this permission notice shall be included in all 13 | // 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 THE 21 | // SOFTWARE. 22 | 23 | package yaml 24 | 25 | // Set the writer error and return false. 26 | func yaml_emitter_set_writer_error(emitter *yaml_emitter_t, problem string) bool { 27 | emitter.error = yaml_WRITER_ERROR 28 | emitter.problem = problem 29 | return false 30 | } 31 | 32 | // Flush the output buffer. 33 | func yaml_emitter_flush(emitter *yaml_emitter_t) bool { 34 | if emitter.write_handler == nil { 35 | panic("write handler not set") 36 | } 37 | 38 | // Check if the buffer is empty. 39 | if emitter.buffer_pos == 0 { 40 | return true 41 | } 42 | 43 | if err := emitter.write_handler(emitter, emitter.buffer[:emitter.buffer_pos]); err != nil { 44 | return yaml_emitter_set_writer_error(emitter, "write error: "+err.Error()) 45 | } 46 | emitter.buffer_pos = 0 47 | return true 48 | } 49 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/davecgh/go-spew v1.1.1 2 | ## explicit 3 | github.com/davecgh/go-spew/spew 4 | # github.com/go-pkgz/lgr v0.11.1 5 | ## explicit; go 1.20 6 | github.com/go-pkgz/lgr 7 | # github.com/go-pkgz/rest v1.20.2 8 | ## explicit; go 1.21 9 | github.com/go-pkgz/rest 10 | github.com/go-pkgz/rest/logger 11 | github.com/go-pkgz/rest/realip 12 | # github.com/pmezard/go-difflib v1.0.0 13 | ## explicit 14 | github.com/pmezard/go-difflib/difflib 15 | # github.com/stretchr/testify v1.10.0 16 | ## explicit; go 1.17 17 | github.com/stretchr/testify/assert 18 | github.com/stretchr/testify/assert/yaml 19 | github.com/stretchr/testify/require 20 | # github.com/umputun/go-flags v1.5.1 21 | ## explicit; go 1.12 22 | github.com/umputun/go-flags 23 | # golang.org/x/crypto v0.31.0 24 | ## explicit; go 1.20 25 | golang.org/x/crypto/argon2 26 | golang.org/x/crypto/bcrypt 27 | golang.org/x/crypto/blake2b 28 | golang.org/x/crypto/blowfish 29 | # golang.org/x/sys v0.28.0 30 | ## explicit; go 1.18 31 | golang.org/x/sys/cpu 32 | # gopkg.in/yaml.v3 v3.0.1 33 | ## explicit 34 | gopkg.in/yaml.v3 35 | --------------------------------------------------------------------------------