From df9e730ac6c1eb7616ed40a7b622d0316841f900 Mon Sep 17 00:00:00 2001 From: Philippe Richard Date: Thu, 23 May 2024 12:46:50 -0400 Subject: [PATCH] chore: Dependency updates (#322) * dep: bump go to 1.22 * dep: bump go-kit from v0.10.0 to v.0.13.0 * dep: bump snappy from v0.0.0 to v.0.0.4 * dep: remove deprecated pkg/errors package * dep: bump node_exporter from v1.0.1 to v1.8.1 * dep: bump golangci-lint from v1.50.1 to v1.58.21 --- .golangci.yml | 8 +- Dockerfile | 2 +- Makefile | 4 +- cmd/do-agent/config.go | 6 +- cmd/do-agent/config_linux.go | 2 +- cmd/do-agent/run.go | 3 +- cmd/do-agent/version.go | 4 +- go.mod | 78 +- go.sum | 597 +- internal/flags/flags.go | 2 +- internal/process/collector.go | 2 +- pkg/aggregate/aggregate.go | 5 +- pkg/clients/tsclient/client.go | 7 +- pkg/collector/node.go | 3 +- pkg/collector/scraper.go | 13 +- pkg/collector/scraper_test.go | 12 +- pkg/writer/sonar.go | 6 +- .../alecthomas/kingpin/v2/.travis.yml | 14 + .../alecthomas/kingpin/v2}/COPYING | 0 .../alecthomas/kingpin/v2}/README.md | 101 +- .../alecthomas/kingpin/v2}/actions.go | 0 .../alecthomas/kingpin/v2}/app.go | 27 +- .../alecthomas/kingpin/v2}/args.go | 21 + .../alecthomas/kingpin/v2}/cmd.go | 55 +- .../alecthomas/kingpin/v2}/completions.go | 0 .../alecthomas/kingpin/v2}/doc.go | 2 +- .../alecthomas/kingpin/v2}/envar.go | 9 +- .../alecthomas/kingpin/v2}/flags.go | 24 + .../alecthomas/kingpin/v2}/global.go | 2 + .../alecthomas/kingpin/v2}/guesswidth.go | 0 .../alecthomas/kingpin/v2}/guesswidth_unix.go | 0 .../alecthomas/kingpin/v2}/model.go | 74 +- .../alecthomas/kingpin/v2}/parser.go | 16 +- .../alecthomas/kingpin/v2}/parsers.go | 4 + .../alecthomas/kingpin/v2/templates.go | 262 + .../alecthomas/kingpin/v2}/usage.go | 42 +- .../alecthomas/kingpin/v2}/values.go | 27 +- .../alecthomas/kingpin/v2}/values.json | 0 .../kingpin/v2}/values_generated.go | 0 .../github.com/alecthomas/template/README.md | 25 - vendor/github.com/alecthomas/template/doc.go | 406 - vendor/github.com/alecthomas/template/exec.go | 845 --- .../github.com/alecthomas/template/funcs.go | 598 -- .../github.com/alecthomas/template/helper.go | 108 - .../alecthomas/template/parse/lex.go | 556 -- .../alecthomas/template/parse/node.go | 834 --- .../alecthomas/template/parse/parse.go | 700 -- .../alecthomas/template/template.go | 218 - vendor/github.com/alecthomas/units/README.md | 2 + vendor/github.com/alecthomas/units/bytes.go | 130 +- vendor/github.com/beevik/ntp/.travis.yml | 14 - vendor/github.com/beevik/ntp/CONTRIBUTORS | 4 +- vendor/github.com/beevik/ntp/LICENSE | 2 +- vendor/github.com/beevik/ntp/README.md | 98 +- vendor/github.com/beevik/ntp/RELEASE_NOTES.md | 126 +- vendor/github.com/beevik/ntp/auth.go | 240 + vendor/github.com/beevik/ntp/ntp.go | 542 +- .../github.com/cespare/xxhash/v2/.travis.yml | 8 - vendor/github.com/cespare/xxhash/v2/README.md | 37 +- .../github.com/cespare/xxhash/v2/testall.sh | 10 + vendor/github.com/cespare/xxhash/v2/xxhash.go | 48 +- .../cespare/xxhash/v2/xxhash_amd64.s | 336 +- .../cespare/xxhash/v2/xxhash_arm64.s | 183 + .../v2/{xxhash_amd64.go => xxhash_asm.go} | 2 + .../cespare/xxhash/v2/xxhash_other.go | 22 +- .../cespare/xxhash/v2/xxhash_safe.go | 1 + .../cespare/xxhash/v2/xxhash_unsafe.go | 54 +- .../coreos/go-systemd/dbus/methods.go | 600 -- .../coreos/go-systemd/{ => v22}/LICENSE | 0 .../coreos/go-systemd/{ => v22}/NOTICE | 0 .../coreos/go-systemd/{ => v22}/dbus/dbus.go | 68 +- .../coreos/go-systemd/v22/dbus/methods.go | 864 +++ .../go-systemd/{ => v22}/dbus/properties.go | 4 +- .../coreos/go-systemd/{ => v22}/dbus/set.go | 0 .../go-systemd/{ => v22}/dbus/subscription.go | 2 +- .../{ => v22}/dbus/subscription_set.go | 0 vendor/github.com/dennwc/btrfs/LICENSE | 201 + vendor/github.com/dennwc/btrfs/README.md | 2 + vendor/github.com/dennwc/btrfs/btrfs.go | 300 + vendor/github.com/dennwc/btrfs/btrfs_h.go | 73 + vendor/github.com/dennwc/btrfs/btrfs_list.go | 22 + vendor/github.com/dennwc/btrfs/btrfs_tree.go | 299 + .../github.com/dennwc/btrfs/btrfs_tree_h.go | 745 ++ .../github.com/dennwc/btrfs/btrfs_tree_hc.go | 502 ++ vendor/github.com/dennwc/btrfs/errors.go | 52 + vendor/github.com/dennwc/btrfs/headers.go | 4 + vendor/github.com/dennwc/btrfs/ioctl_h.go | 876 +++ vendor/github.com/dennwc/btrfs/mtab/mtab.go | 43 + vendor/github.com/dennwc/btrfs/receive.go | 58 + vendor/github.com/dennwc/btrfs/send.go | 245 + vendor/github.com/dennwc/btrfs/subvolume.go | 379 + vendor/github.com/dennwc/btrfs/usage.go | 176 + vendor/github.com/dennwc/btrfs/utils.go | 107 + vendor/github.com/dennwc/btrfs/uuid_tree.go | 49 + vendor/github.com/dennwc/btrfs/xattr.go | 66 + vendor/github.com/dennwc/ioctl/ioctl.go | 82 + vendor/github.com/ema/qdisc/Makefile | 2 +- vendor/github.com/ema/qdisc/README.md | 4 +- vendor/github.com/ema/qdisc/get.go | 43 +- vendor/github.com/go-kit/kit/log/README.md | 9 + vendor/github.com/go-kit/kit/log/doc.go | 6 +- .../github.com/go-kit/kit/log/json_logger.go | 82 +- vendor/github.com/go-kit/kit/log/log.go | 120 +- .../go-kit/kit/log/logfmt_logger.go | 51 +- .../github.com/go-kit/kit/log/nop_logger.go | 8 +- vendor/github.com/go-kit/kit/log/stdlib.go | 100 +- vendor/github.com/go-kit/kit/log/sync.go | 89 +- vendor/github.com/go-kit/kit/log/value.go | 82 +- vendor/github.com/go-kit/log/.gitignore | 15 + vendor/github.com/go-kit/log/LICENSE | 21 + vendor/github.com/go-kit/log/README.md | 156 + vendor/github.com/go-kit/log/doc.go | 116 + vendor/github.com/go-kit/log/json_logger.go | 91 + .../go-kit/{kit => }/log/level/doc.go | 11 + .../go-kit/{kit => }/log/level/level.go | 55 +- vendor/github.com/go-kit/log/log.go | 179 + vendor/github.com/go-kit/log/logfmt_logger.go | 62 + vendor/github.com/go-kit/log/nop_logger.go | 8 + vendor/github.com/go-kit/log/staticcheck.conf | 1 + vendor/github.com/go-kit/log/stdlib.go | 151 + vendor/github.com/go-kit/log/sync.go | 113 + vendor/github.com/go-kit/log/value.go | 110 + .../github.com/go-logfmt/logfmt/.travis.yml | 18 - vendor/github.com/go-logfmt/logfmt/README.md | 66 +- vendor/github.com/godbus/dbus/.travis.yml | 46 - vendor/github.com/godbus/dbus/homedir.go | 28 - .../github.com/godbus/dbus/homedir_dynamic.go | 15 - .../github.com/godbus/dbus/homedir_static.go | 45 - .../godbus/dbus/{ => v5}/CONTRIBUTING.md | 0 .../github.com/godbus/dbus/{ => v5}/LICENSE | 0 .../godbus/dbus/{ => v5}/MAINTAINERS | 0 .../dbus/{README.markdown => v5/README.md} | 14 +- .../github.com/godbus/dbus/{ => v5}/auth.go | 29 +- .../godbus/dbus/{ => v5}/auth_anonymous.go | 0 .../godbus/dbus/{ => v5}/auth_external.go | 0 .../godbus/dbus/{ => v5}/auth_sha1.go | 2 +- .../github.com/godbus/dbus/{ => v5}/call.go | 9 + .../github.com/godbus/dbus/{ => v5}/conn.go | 369 +- .../godbus/dbus/{ => v5}/conn_darwin.go | 0 .../godbus/dbus/{ => v5}/conn_other.go | 15 +- .../godbus/dbus/{ => v5}/conn_unix.go | 5 +- .../godbus/dbus/{ => v5}/conn_windows.go | 0 .../github.com/godbus/dbus/{ => v5}/dbus.go | 19 +- .../godbus/dbus/{ => v5}/decoder.go | 69 +- .../godbus/dbus/{ => v5}/default_handler.go | 137 +- vendor/github.com/godbus/dbus/{ => v5}/doc.go | 12 +- .../godbus/dbus/{ => v5}/encoder.go | 63 +- vendor/github.com/godbus/dbus/v5/escape.go | 84 + .../github.com/godbus/dbus/{ => v5}/export.go | 117 +- vendor/github.com/godbus/dbus/v5/homedir.go | 25 + vendor/github.com/godbus/dbus/v5/match.go | 89 + .../godbus/dbus/{ => v5}/message.go | 83 +- .../github.com/godbus/dbus/{ => v5}/object.go | 108 +- vendor/github.com/godbus/dbus/v5/sequence.go | 24 + .../godbus/dbus/v5/sequential_handler.go | 125 + .../godbus/dbus/{ => v5}/server_interfaces.go | 10 +- vendor/github.com/godbus/dbus/{ => v5}/sig.go | 68 +- .../godbus/dbus/{ => v5}/transport_darwin.go | 0 .../godbus/dbus/{ => v5}/transport_generic.go | 10 +- .../dbus/{ => v5}/transport_nonce_tcp.go | 0 .../godbus/dbus/{ => v5}/transport_tcp.go | 2 - .../godbus/dbus/{ => v5}/transport_unix.go | 36 +- .../{ => v5}/transport_unixcred_dragonfly.go | 0 .../{ => v5}/transport_unixcred_freebsd.go | 1 + .../dbus/{ => v5}/transport_unixcred_linux.go | 0 .../transport_unixcred_netbsd.go} | 0 .../dbus/v5/transport_unixcred_openbsd.go | 14 + .../godbus/dbus/v5/transport_zos.go | 6 + .../godbus/dbus/{ => v5}/variant.go | 12 +- .../godbus/dbus/{ => v5}/variant_lexer.go | 8 +- .../godbus/dbus/{ => v5}/variant_parser.go | 0 vendor/github.com/golang/protobuf/AUTHORS | 3 - .../github.com/golang/protobuf/CONTRIBUTORS | 3 - .../golang/protobuf/proto/buffer.go | 324 - .../golang/protobuf/proto/defaults.go | 63 - .../golang/protobuf/proto/deprecated.go | 113 - .../golang/protobuf/proto/discard.go | 58 - .../golang/protobuf/proto/extensions.go | 356 - .../golang/protobuf/proto/properties.go | 306 - .../github.com/golang/protobuf/proto/proto.go | 167 - .../golang/protobuf/proto/registry.go | 323 - .../golang/protobuf/proto/text_decode.go | 801 -- .../golang/protobuf/proto/text_encode.go | 560 -- .../github.com/golang/protobuf/proto/wire.go | 78 - .../golang/protobuf/proto/wrappers.go | 34 - .../github.com/golang/protobuf/ptypes/any.go | 165 - .../golang/protobuf/ptypes/any/any.pb.go | 62 - .../github.com/golang/protobuf/ptypes/doc.go | 6 - .../golang/protobuf/ptypes/duration.go | 72 - .../protobuf/ptypes/duration/duration.pb.go | 63 - .../golang/protobuf/ptypes/timestamp.go | 103 - .../protobuf/ptypes/timestamp/timestamp.pb.go | 64 - vendor/github.com/golang/snappy/AUTHORS | 3 + vendor/github.com/golang/snappy/CONTRIBUTORS | 4 + vendor/github.com/golang/snappy/decode.go | 87 +- .../github.com/golang/snappy/decode_arm64.s | 494 ++ .../snappy/{decode_amd64.go => decode_asm.go} | 1 + .../github.com/golang/snappy/decode_other.go | 24 +- vendor/github.com/golang/snappy/encode.go | 4 + .../github.com/golang/snappy/encode_arm64.s | 722 ++ .../snappy/{encode_amd64.go => encode_asm.go} | 1 + .../github.com/golang/snappy/encode_other.go | 2 +- .../template => google/go-cmp}/LICENSE | 2 +- .../github.com/google/go-cmp/cmp/compare.go | 671 ++ vendor/github.com/google/go-cmp/cmp/export.go | 31 + .../go-cmp/cmp/internal/diff/debug_disable.go | 18 + .../go-cmp/cmp/internal/diff/debug_enable.go | 123 + .../google/go-cmp/cmp/internal/diff/diff.go | 402 + .../google/go-cmp/cmp/internal/flags/flags.go | 9 + .../go-cmp/cmp/internal/function/func.go | 99 + .../google/go-cmp/cmp/internal/value/name.go | 164 + .../go-cmp/cmp/internal/value/pointer.go | 34 + .../google/go-cmp/cmp/internal/value/sort.go | 106 + .../github.com/google/go-cmp/cmp/options.go | 554 ++ vendor/github.com/google/go-cmp/cmp/path.go | 390 + vendor/github.com/google/go-cmp/cmp/report.go | 54 + .../google/go-cmp/cmp/report_compare.go | 433 ++ .../google/go-cmp/cmp/report_references.go | 264 + .../google/go-cmp/cmp/report_reflect.go | 414 ++ .../google/go-cmp/cmp/report_slices.go | 614 ++ .../google/go-cmp/cmp/report_text.go | 432 ++ .../google/go-cmp/cmp/report_value.go | 121 + .../hashicorp/go-envparse/.gitignore | 14 + .../github.com/hashicorp/go-envparse/LICENSE | 373 + .../hashicorp/go-envparse/NOTICES.txt | 2 + .../hashicorp/go-envparse/README.md | 91 + .../hashicorp/go-envparse/envparse.go | 338 + .../github.com/hodgesds/perf-utils/.gitignore | 1 + .../github.com/hodgesds/perf-utils/Gopkg.lock | 15 - .../github.com/hodgesds/perf-utils/Gopkg.toml | 34 - .../github.com/hodgesds/perf-utils/README.md | 88 +- vendor/github.com/hodgesds/perf-utils/bpf.go | 1 + .../hodgesds/perf-utils/cache_profiler.go | 372 +- .../github.com/hodgesds/perf-utils/events.go | 45 +- .../hodgesds/perf-utils/fs_utils.go | 11 +- .../hodgesds/perf-utils/group_profiler.go | 76 +- .../hodgesds/perf-utils/hardware_profiler.go | 170 +- vendor/github.com/hodgesds/perf-utils/msr.go | 76 + vendor/github.com/hodgesds/perf-utils/pmu.go | 36 + .../hodgesds/perf-utils/process_profile.go | 105 +- .../hodgesds/perf-utils/software_profiler.go | 148 +- .../github.com/hodgesds/perf-utils/utils.go | 425 ++ .../go-kstat/.gitignore | 0 .../{siebenmann => illumos}/go-kstat/LICENSE | 0 .../{siebenmann => illumos}/go-kstat/Makefile | 0 .../{siebenmann => illumos}/go-kstat/README | 15 +- .../{siebenmann => illumos}/go-kstat/doc.go | 0 .../go-kstat/kstat-godoc.txt | 0 .../go-kstat/kstat_solaris.go | 0 .../go-kstat/raw_solaris.go | 0 .../go-kstat/types_solaris_amd64.go | 0 vendor/github.com/josharian/native/doc.go | 8 + .../github.com/josharian/native/endian_big.go | 14 + .../josharian/native/endian_generic.go | 31 + .../josharian/native/endian_little.go | 14 + vendor/github.com/josharian/native/license | 7 + vendor/github.com/josharian/native/readme.md | 10 + .../jsimonetti/rtnetlink/.gitignore | 1 + .../jsimonetti/rtnetlink/.golangci.yml | 18 + .../jsimonetti/rtnetlink/LICENSE.md | 10 + .../jsimonetti/rtnetlink/Makefile.fuzz | 32 + .../github.com/jsimonetti/rtnetlink/README.md | 43 + .../jsimonetti/rtnetlink/address.go | 269 + .../github.com/jsimonetti/rtnetlink/conn.go | 197 + vendor/github.com/jsimonetti/rtnetlink/doc.go | 27 + .../github.com/jsimonetti/rtnetlink/endian.go | 13 + .../jsimonetti/rtnetlink/fuzz-shell.nix | 15 + .../rtnetlink/internal/unix/types_linux.go | 150 + .../rtnetlink/internal/unix/types_other.go | 146 + .../github.com/jsimonetti/rtnetlink/link.go | 622 ++ .../github.com/jsimonetti/rtnetlink/neigh.go | 216 + .../github.com/jsimonetti/rtnetlink/route.go | 626 ++ .../github.com/jsimonetti/rtnetlink/rule.go | 394 + vendor/github.com/lufia/iostat/README.md | 8 +- .../github.com/lufia/iostat/iostat_darwin.c | 6 +- .../github.com/lufia/iostat/iostat_darwin.go | 14 +- .../github.com/lufia/iostat/iostat_darwin.h | 9 +- .../github.com/lufia/iostat/iostat_linux.go | 3 +- .../golang_protobuf_extensions/NOTICE | 1 - .../pbutil/.gitignore | 1 - .../pbutil/Makefile | 7 - .../pbutil/decode.go | 75 - .../pbutil/encode.go | 46 - vendor/github.com/mdlayher/ethtool/LICENSE.md | 9 + vendor/github.com/mdlayher/ethtool/README.md | 5 + .../mdlayher/ethtool/bitset_linux.go | 84 + vendor/github.com/mdlayher/ethtool/client.go | 288 + .../mdlayher/ethtool/client_linux.go | 803 ++ .../mdlayher/ethtool/client_others.go | 36 + vendor/github.com/mdlayher/ethtool/doc.go | 4 + .../mdlayher/ethtool/linkmodes_linux.go | 106 + vendor/github.com/mdlayher/ethtool/string.go | 70 + .../mdlayher/genetlink/CHANGELOG.md | 32 +- .../github.com/mdlayher/genetlink/LICENSE.md | 5 +- .../github.com/mdlayher/genetlink/README.md | 13 +- vendor/github.com/mdlayher/genetlink/conn.go | 19 +- .../mdlayher/genetlink/family_linux.go | 66 +- .../mdlayher/genetlink/family_others.go | 3 +- vendor/github.com/mdlayher/genetlink/fuzz.go | 3 +- vendor/github.com/mdlayher/netlink/.gitignore | 4 +- .../github.com/mdlayher/netlink/CHANGELOG.md | 156 +- vendor/github.com/mdlayher/netlink/LICENSE.md | 5 +- vendor/github.com/mdlayher/netlink/README.md | 148 +- .../github.com/mdlayher/netlink/attribute.go | 170 +- vendor/github.com/mdlayher/netlink/conn.go | 159 +- .../github.com/mdlayher/netlink/conn_linux.go | 649 +- .../mdlayher/netlink/conn_others.go | 3 +- vendor/github.com/mdlayher/netlink/doc.go | 21 +- vendor/github.com/mdlayher/netlink/errors.go | 34 +- .../mdlayher/netlink/fdcall_gteq_1.12.go | 44 - .../mdlayher/netlink/fdcall_lt_1.12.go | 29 - vendor/github.com/mdlayher/netlink/fuzz.go | 82 +- vendor/github.com/mdlayher/netlink/message.go | 105 +- .../github.com/mdlayher/netlink/netlink.dot | 86 - .../github.com/mdlayher/netlink/netlink.svg | 436 -- .../github.com/mdlayher/netlink/nlenc/doc.go | 12 + .../mdlayher/netlink/nlenc/endian.go | 14 - .../mdlayher/netlink/rawconn_gteq_1.12.go | 12 - .../mdlayher/netlink/rawconn_lt_1.12.go | 32 - .../github.com/mdlayher/socket/CHANGELOG.md | 80 + vendor/github.com/mdlayher/socket/LICENSE.md | 9 + vendor/github.com/mdlayher/socket/README.md | 23 + vendor/github.com/mdlayher/socket/accept.go | 23 + vendor/github.com/mdlayher/socket/accept4.go | 15 + vendor/github.com/mdlayher/socket/conn.go | 880 +++ .../github.com/mdlayher/socket/conn_linux.go | 118 + vendor/github.com/mdlayher/socket/doc.go | 13 + .../{netlink => socket}/netns_linux.go | 75 +- .../mdlayher/socket/netns_others.go | 14 + .../mdlayher/socket/setbuffer_linux.go | 24 + .../mdlayher/socket/setbuffer_others.go | 16 + .../mdlayher/socket/typ_cloexec_nonblock.go | 12 + vendor/github.com/mdlayher/socket/typ_none.go | 11 + vendor/github.com/mdlayher/wifi/.travis.yml | 16 - vendor/github.com/mdlayher/wifi/LICENSE.md | 5 +- vendor/github.com/mdlayher/wifi/README.md | 15 +- vendor/github.com/mdlayher/wifi/client.go | 37 +- .../github.com/mdlayher/wifi/client_linux.go | 322 +- .../github.com/mdlayher/wifi/client_others.go | 43 +- vendor/github.com/mdlayher/wifi/doc.go | 3 +- .../mdlayher/wifi/internal/nl80211/const.go | 1694 ----- .../mdlayher/wifi/internal/nl80211/doc.go | 15 - .../mdlayher/wifi/internal/nl80211/nl80211.h | 5080 ------------- .../wifi/internal/nl80211/nl80211.yml | 20 - vendor/github.com/mdlayher/wifi/wifi.go | 6 +- .../selinux}/LICENSE | 0 .../opencontainers/selinux/go-selinux/doc.go | 13 + .../selinux/go-selinux/selinux.go | 314 + .../selinux/go-selinux/selinux_linux.go | 1295 ++++ .../selinux/go-selinux/selinux_stub.go | 155 + .../selinux/go-selinux/xattrs_linux.go | 71 + .../selinux/pkg/pwalkdir/README.md | 54 + .../selinux/pkg/pwalkdir/pwalkdir.go | 116 + vendor/github.com/pkg/errors/.travis.yml | 10 - vendor/github.com/pkg/errors/LICENSE | 23 - vendor/github.com/pkg/errors/Makefile | 44 - vendor/github.com/pkg/errors/README.md | 59 - vendor/github.com/pkg/errors/appveyor.yml | 32 - vendor/github.com/pkg/errors/errors.go | 288 - vendor/github.com/pkg/errors/go113.go | 38 - vendor/github.com/pkg/errors/stack.go | 177 - .../go-runit/LICENSE | 0 .../go-runit/runit/runit.go | 17 +- .../client_golang/prometheus/README.md | 2 +- .../prometheus/build_info_collector.go | 38 + .../client_golang/prometheus/collector.go | 14 +- .../client_golang/prometheus/counter.go | 65 +- .../client_golang/prometheus/desc.go | 57 +- .../client_golang/prometheus/doc.go | 107 +- .../prometheus/expvar_collector.go | 2 +- .../client_golang/prometheus/gauge.go | 36 +- .../client_golang/prometheus/get_pid.go | 26 + .../prometheus/get_pid_gopherjs.go | 23 + .../client_golang/prometheus/go_collector.go | 496 +- .../prometheus/go_collector_go116.go | 122 + .../prometheus/go_collector_latest.go | 567 ++ .../client_golang/prometheus/histogram.go | 1123 ++- .../prometheus/internal/almost_equal.go | 60 + .../prometheus/internal/difflib.go | 654 ++ .../internal/go_collector_options.go | 32 + .../prometheus/internal/go_runtime_metrics.go | 142 + .../prometheus/internal/metric.go | 28 +- .../client_golang/prometheus/labels.go | 109 +- .../client_golang/prometheus/metric.go | 121 +- .../client_golang/prometheus/num_threads.go | 25 + .../prometheus/num_threads_gopherjs.go | 22 + .../client_golang/prometheus/observer.go | 2 +- .../prometheus/process_collector.go | 10 +- .../prometheus/process_collector_js.go | 26 + .../prometheus/process_collector_other.go | 3 +- .../prometheus/process_collector_wasip1.go | 26 + .../prometheus/promhttp/delegator.go | 18 +- .../client_golang/prometheus/promhttp/http.go | 39 +- .../prometheus/promhttp/instrument_client.go | 46 +- .../prometheus/promhttp/instrument_server.go | 149 +- .../prometheus/promhttp/option.go | 65 +- .../client_golang/prometheus/registry.go | 171 +- .../client_golang/prometheus/summary.go | 81 +- .../client_golang/prometheus/timer.go | 39 +- .../client_golang/prometheus/value.go | 108 +- .../client_golang/prometheus/vec.go | 181 +- .../client_golang/prometheus/vnext.go | 23 + .../client_golang/prometheus/wrap.go | 8 +- .../prometheus/client_model/go/metrics.pb.go | 1602 ++-- .../prometheus/common/expfmt/decode.go | 70 +- .../prometheus/common/expfmt/encode.go | 87 +- .../prometheus/common/expfmt/expfmt.go | 166 +- .../prometheus/common/expfmt/fuzz.go | 5 +- .../common/expfmt/openmetrics_create.go | 301 +- .../prometheus/common/expfmt/text_create.go | 121 +- .../prometheus/common/expfmt/text_parse.go | 16 +- .../bitbucket.org/ww/goautoneg/autoneg.go | 22 +- .../prometheus/common/model/alert.go | 31 +- .../prometheus/common/model/labels.go | 22 +- .../prometheus/common/model/labelset.go | 11 - .../common/model/labelset_string.go | 45 + .../common/model/labelset_string_go120.go | 39 + .../prometheus/common/model/metadata.go | 28 + .../prometheus/common/model/metric.go | 369 +- .../prometheus/common/model/signature.go | 6 +- .../prometheus/common/model/silence.go | 2 +- .../prometheus/common/model/time.go | 91 +- .../prometheus/common/model/value.go | 262 +- .../prometheus/common/model/value_float.go | 98 + .../common/model/value_histogram.go | 178 + .../prometheus/common/model/value_type.go | 83 + .../node_exporter/collector/arp_linux.go | 116 +- .../node_exporter/collector/bcache_linux.go | 114 +- .../node_exporter/collector/bonding_linux.go | 19 +- .../node_exporter/collector/boot_time_bsd.go | 23 +- .../collector/boot_time_solaris.go | 6 +- .../node_exporter/collector/btrfs_linux.go | 267 +- .../node_exporter/collector/buddyinfo.go | 10 +- .../node_exporter/collector/cgroups_linux.go | 73 + .../node_exporter/collector/collector.go | 74 +- .../collector/conntrack_linux.go | 135 +- .../node_exporter/collector/cpu_common.go | 3 +- .../node_exporter/collector/cpu_darwin.go | 4 +- .../node_exporter/collector/cpu_dragonfly.go | 5 +- .../node_exporter/collector/cpu_freebsd.go | 5 +- .../node_exporter/collector/cpu_linux.go | 265 +- .../node_exporter/collector/cpu_netbsd.go | 277 + .../node_exporter/collector/cpu_openbsd.go | 52 +- .../node_exporter/collector/cpu_solaris.go | 16 +- .../collector/cpu_vulnerabilities_linux.go | 69 + .../node_exporter/collector/cpufreq_common.go | 59 + .../node_exporter/collector/cpufreq_linux.go | 75 +- .../collector/cpufreq_solaris.go | 24 +- .../node_exporter/collector/device_filter.go | 41 + .../collector/devstat_dragonfly.go | 3 +- .../collector/devstat_freebsd.go | 3 +- .../collector/diskstats_common.go | 46 + .../collector/diskstats_darwin.go | 25 +- .../collector/diskstats_linux.go | 281 +- .../collector/diskstats_openbsd.go | 24 +- .../collector/diskstats_openbsd_amd64.go | 105 + .../prometheus/node_exporter/collector/dmi.go | 106 + .../node_exporter/collector/drbd_linux.go | 8 +- .../node_exporter/collector/drm_linux.go | 140 + .../node_exporter/collector/edac_linux.go | 15 +- .../node_exporter/collector/entropy_linux.go | 37 +- .../node_exporter/collector/ethtool_linux.go | 509 ++ .../node_exporter/collector/exec_bsd.go | 3 +- .../collector/fibrechannel_linux.go | 137 + .../node_exporter/collector/filefd_linux.go | 11 +- .../node_exporter/collector/filesystem_bsd.go | 15 +- .../collector/filesystem_common.go | 111 +- .../collector/filesystem_freebsd.go | 30 +- .../collector/filesystem_linux.go | 173 +- .../collector/filesystem_openbsd.go | 77 + .../node_exporter/collector/helper.go | 32 +- .../node_exporter/collector/hwmon_linux.go | 67 +- .../collector/infiniband_linux.go | 23 +- .../collector/interrupts_common.go | 3 +- .../collector/interrupts_linux.go | 40 +- .../collector/interrupts_openbsd.go | 5 +- .../collector/interrupts_openbsd_amd64.go | 110 + .../node_exporter/collector/ipvs_linux.go | 133 +- .../node_exporter/collector/ksmd_linux.go | 3 +- .../node_exporter/collector/kvm_bsd.go | 1 + .../node_exporter/collector/lnstat_linux.go | 72 + .../node_exporter/collector/loadavg.go | 7 +- .../node_exporter/collector/loadavg_bsd.go | 1 + .../node_exporter/collector/loadavg_linux.go | 7 +- .../collector/loadavg_solaris.go | 3 +- .../node_exporter/collector/logind_linux.go | 11 +- .../node_exporter/collector/mdadm_linux.go | 29 +- .../node_exporter/collector/meminfo.go | 9 +- .../node_exporter/collector/meminfo_darwin.go | 3 + .../node_exporter/collector/meminfo_linux.go | 3 +- .../node_exporter/collector/meminfo_netbsd.go | 43 + .../collector/meminfo_numa_linux.go | 9 +- .../collector/meminfo_openbsd.go | 6 +- .../collector/meminfo_openbsd_amd64.go | 81 + .../node_exporter/collector/memory_bsd.go | 22 +- .../collector/mountstats_linux.go | 5 +- .../node_exporter/collector/netclass_linux.go | 170 +- .../collector/netclass_rtnl_linux.go | 230 + .../node_exporter/collector/netdev_bsd.go | 59 +- .../node_exporter/collector/netdev_common.go | 222 +- .../node_exporter/collector/netdev_darwin.go | 47 +- .../node_exporter/collector/netdev_linux.go | 186 +- .../node_exporter/collector/netdev_openbsd.go | 59 +- .../collector/netdev_openbsd_amd64.go | 78 + .../node_exporter/collector/netisr_freebsd.go | 105 + .../node_exporter/collector/netstat_linux.go | 18 +- .../collector/network_route_linux.go | 204 + .../node_exporter/collector/nfs_linux.go | 8 +- .../node_exporter/collector/nfsd_linux.go | 14 +- .../prometheus/node_exporter/collector/ntp.go | 15 +- .../node_exporter/collector/nvme_linux.go | 74 + .../node_exporter/collector/os_release.go | 234 + .../node_exporter/collector/paths.go | 13 +- .../node_exporter/collector/perf_linux.go | 272 +- .../collector/powersupplyclass.go | 159 +- .../collector/powersupplyclass_darwin.go | 420 ++ .../collector/powersupplyclass_linux.go | 176 + .../node_exporter/collector/pressure_linux.go | 27 +- .../collector/processes_linux.go | 114 +- .../node_exporter/collector/qdisc_linux.go | 73 +- .../node_exporter/collector/rapl_linux.go | 103 +- .../node_exporter/collector/runit.go | 11 +- .../collector/schedstat_linux.go | 8 +- .../node_exporter/collector/selinux_linux.go | 78 + .../node_exporter/collector/slabinfo_linux.go | 121 + .../node_exporter/collector/sockstat_linux.go | 10 +- .../node_exporter/collector/softirq_linux.go | 68 + .../collector/softirqs_common.go | 50 + .../node_exporter/collector/softnet_linux.go | 69 +- .../node_exporter/collector/stat_linux.go | 34 +- .../node_exporter/collector/supervisord.go | 13 +- .../node_exporter/collector/sysctl_bsd.go | 26 +- .../node_exporter/collector/sysctl_linux.go | 218 + .../collector/sysctl_openbsd_amd64.go | 86 + .../node_exporter/collector/systemd_linux.go | 152 +- .../collector/tapestats_linux.go | 152 + .../node_exporter/collector/tcpstat_linux.go | 142 +- .../node_exporter/collector/textfile.go | 123 +- .../node_exporter/collector/thermal_darwin.go | 187 + .../collector/thermal_zone_linux.go | 10 +- .../node_exporter/collector/time.go | 47 +- .../node_exporter/collector/time_linux.go | 48 + .../node_exporter/collector/time_other.go | 25 + .../node_exporter/collector/timex.go | 18 +- .../collector/udp_queues_linux.go | 18 +- .../node_exporter/collector/uname.go | 5 +- .../node_exporter/collector/uname_bsd.go | 14 +- .../node_exporter/collector/uname_linux.go | 19 +- .../node_exporter/collector/vmstat_linux.go | 5 +- .../node_exporter/collector/watchdog.go | 140 + .../node_exporter/collector/wifi_linux.go | 23 +- .../node_exporter/collector/xfrm.go | 228 + .../node_exporter/collector/xfs_linux.go | 38 +- .../prometheus/node_exporter/collector/zfs.go | 35 +- .../node_exporter/collector/zfs_freebsd.go | 32 +- .../node_exporter/collector/zfs_linux.go | 82 +- .../node_exporter/collector/zfs_solaris.go | 9 +- .../node_exporter/collector/zoneinfo_linux.go | 240 + .../github.com/prometheus/procfs/.gitignore | 3 +- .../prometheus/procfs/.golangci.yml | 13 +- .../prometheus/procfs/CODE_OF_CONDUCT.md | 4 +- .../prometheus/procfs/CONTRIBUTING.md | 4 +- .../prometheus/procfs/MAINTAINERS.md | 3 +- vendor/github.com/prometheus/procfs/Makefile | 10 +- .../prometheus/procfs/Makefile.common | 133 +- vendor/github.com/prometheus/procfs/README.md | 8 +- .../github.com/prometheus/procfs/SECURITY.md | 2 +- vendor/github.com/prometheus/procfs/arp.go | 51 +- .../prometheus/procfs/bcache/bcache.go | 2 +- .../prometheus/procfs/bcache/get.go | 13 +- .../prometheus/procfs/blockdevice/stats.go | 476 ++ .../prometheus/procfs/btrfs/btrfs.go | 10 + .../github.com/prometheus/procfs/btrfs/get.go | 69 +- .../github.com/prometheus/procfs/buddyinfo.go | 6 +- .../github.com/prometheus/procfs/cmdline.go | 30 + .../github.com/prometheus/procfs/cpuinfo.go | 58 +- .../prometheus/procfs/cpuinfo_armx.go | 1 + .../procfs/cpuinfo_loong64.go} | 13 +- .../prometheus/procfs/cpuinfo_mipsx.go | 1 + .../prometheus/procfs/cpuinfo_others.go | 4 +- .../prometheus/procfs/cpuinfo_ppcx.go | 1 + .../prometheus/procfs/cpuinfo_riscvx.go | 1 + .../prometheus/procfs/cpuinfo_s390x.go | 1 + .../prometheus/procfs/cpuinfo_x86.go | 1 + vendor/github.com/prometheus/procfs/crypto.go | 7 +- vendor/github.com/prometheus/procfs/doc.go | 51 +- .../prometheus/procfs/fixtures.ttar | 6553 ----------------- vendor/github.com/prometheus/procfs/fs.go | 11 +- .../prometheus/procfs/fs_statfs_notype.go | 23 + .../prometheus/procfs/fs_statfs_type.go | 33 + .../github.com/prometheus/procfs/fscache.go | 6 +- .../prometheus/procfs/internal/fs/fs.go | 2 +- .../prometheus/procfs/internal/util/parse.go | 21 +- .../procfs/internal/util/readfile.go | 11 +- .../procfs/internal/util/sysreadfile.go | 8 +- .../internal/util/sysreadfile_compat.go | 3 +- vendor/github.com/prometheus/procfs/ipvs.go | 10 +- .../prometheus/procfs/kernel_random.go | 1 + .../github.com/prometheus/procfs/loadavg.go | 6 +- vendor/github.com/prometheus/procfs/mdstat.go | 125 +- .../github.com/prometheus/procfs/meminfo.go | 220 +- .../github.com/prometheus/procfs/mountinfo.go | 10 +- .../prometheus/procfs/mountstats.go | 115 +- .../prometheus/procfs/net_conntrackstat.go | 101 +- .../github.com/prometheus/procfs/net_dev.go | 8 +- .../prometheus/procfs/net_ip_socket.go | 66 +- .../prometheus/procfs/net_protocols.go | 8 +- .../github.com/prometheus/procfs/net_route.go | 143 + .../prometheus/procfs/net_sockstat.go | 9 +- .../prometheus/procfs/net_softnet.go | 87 +- .../prometheus/procfs/net_tls_stat.go | 119 + .../github.com/prometheus/procfs/net_unix.go | 16 +- .../prometheus/procfs/net_wireless.go | 182 + .../procfs/{xfrm.go => net_xfrm.go} | 11 +- .../github.com/prometheus/procfs/netstat.go | 82 + .../github.com/prometheus/procfs/nfs/nfs.go | 93 +- .../github.com/prometheus/procfs/nfs/parse.go | 84 +- .../prometheus/procfs/nfs/parse_nfs.go | 2 +- .../prometheus/procfs/nfs/parse_nfsd.go | 4 +- vendor/github.com/prometheus/procfs/proc.go | 47 +- .../prometheus/procfs/proc_cgroup.go | 14 +- .../prometheus/procfs/proc_cgroups.go | 98 + .../prometheus/procfs/proc_environ.go | 2 +- .../prometheus/procfs/proc_fdinfo.go | 13 +- .../prometheus/procfs/proc_interrupts.go | 98 + .../prometheus/procfs/proc_limits.go | 6 +- .../github.com/prometheus/procfs/proc_maps.go | 36 +- .../prometheus/procfs/proc_netstat.go | 443 ++ .../github.com/prometheus/procfs/proc_ns.go | 6 +- .../github.com/prometheus/procfs/proc_psi.go | 20 +- .../prometheus/procfs/proc_smaps.go | 27 +- .../github.com/prometheus/procfs/proc_snmp.go | 353 + .../prometheus/procfs/proc_snmp6.go | 381 + .../github.com/prometheus/procfs/proc_stat.go | 62 +- .../prometheus/procfs/proc_status.go | 120 +- .../github.com/prometheus/procfs/proc_sys.go | 51 + .../github.com/prometheus/procfs/schedstat.go | 6 +- vendor/github.com/prometheus/procfs/slab.go | 4 +- .../github.com/prometheus/procfs/softirqs.go | 160 + vendor/github.com/prometheus/procfs/stat.go | 60 +- vendor/github.com/prometheus/procfs/swaps.go | 8 +- .../procfs/sysfs/class_cooling_device.go | 3 +- .../prometheus/procfs/sysfs/class_dmi.go | 131 + .../prometheus/procfs/sysfs/class_drm.go | 27 + .../procfs/sysfs/class_drm_amdgpu.go | 122 + .../procfs/sysfs/class_fibrechannel.go | 20 +- .../procfs/sysfs/class_infiniband.go | 263 +- .../prometheus/procfs/sysfs/class_nvme.go | 90 + .../procfs/sysfs/class_power_supply.go | 13 +- .../prometheus/procfs/sysfs/class_powercap.go | 23 +- .../procfs/sysfs/class_sas_device.go | 207 + .../prometheus/procfs/sysfs/class_sas_host.go | 122 + .../prometheus/procfs/sysfs/class_sas_phy.go | 164 + .../prometheus/procfs/sysfs/class_sas_port.go | 139 + .../prometheus/procfs/sysfs/class_scsitape.go | 141 + .../prometheus/procfs/sysfs/class_thermal.go | 3 +- .../prometheus/procfs/sysfs/class_watchdog.go | 123 + .../prometheus/procfs/sysfs/clocksource.go | 7 +- .../github.com/prometheus/procfs/sysfs/doc.go | 3 + .../github.com/prometheus/procfs/sysfs/fs.go | 3 + .../prometheus/procfs/sysfs/mdraid.go | 160 + .../prometheus/procfs/sysfs/net_class.go | 200 +- .../prometheus/procfs/sysfs/system_cpu.go | 134 +- .../prometheus/procfs/sysfs/vmstat_numa.go | 5 +- .../prometheus/procfs/sysfs/vulnerability.go | 102 +- vendor/github.com/prometheus/procfs/thread.go | 80 + vendor/github.com/prometheus/procfs/vm.go | 12 +- .../github.com/prometheus/procfs/xfs/parse.go | 14 +- .../github.com/prometheus/procfs/zoneinfo.go | 10 +- .../errors => safchain/ethtool}/.gitignore | 3 + .../github.com/safchain/ethtool/.golangci.yml | 14 + vendor/github.com/safchain/ethtool/LICENSE | 202 + vendor/github.com/safchain/ethtool/Makefile | 4 + vendor/github.com/safchain/ethtool/README.md | 55 + vendor/github.com/safchain/ethtool/ethtool.go | 800 ++ .../safchain/ethtool/ethtool_cmd.go | 208 + .../safchain/ethtool/ethtool_msglvl.go | 114 + .../xhit/go-str2duration/v2/LICENSE | 27 + .../xhit/go-str2duration/v2/README.md | 88 + .../xhit/go-str2duration/v2/str2duration.go | 331 + vendor/go.uber.org/atomic/.codecov.yml | 4 + vendor/go.uber.org/atomic/.gitignore | 3 + vendor/go.uber.org/atomic/.travis.yml | 27 - vendor/go.uber.org/atomic/CHANGELOG.md | 54 +- vendor/go.uber.org/atomic/Makefile | 52 +- vendor/go.uber.org/atomic/README.md | 4 +- vendor/go.uber.org/atomic/atomic.go | 356 - vendor/go.uber.org/atomic/bool.go | 81 + .../{multierr/go113.go => atomic/bool_ext.go} | 49 +- vendor/go.uber.org/atomic/doc.go | 23 + vendor/go.uber.org/atomic/duration.go | 82 + vendor/go.uber.org/atomic/duration_ext.go | 40 + vendor/go.uber.org/atomic/error.go | 48 +- vendor/go.uber.org/atomic/error_ext.go | 39 + vendor/go.uber.org/atomic/float64.go | 77 + vendor/go.uber.org/atomic/float64_ext.go | 69 + vendor/go.uber.org/atomic/gen.go | 27 + vendor/go.uber.org/atomic/int32.go | 102 + vendor/go.uber.org/atomic/int64.go | 102 + vendor/go.uber.org/atomic/nocmp.go | 35 + vendor/go.uber.org/atomic/string.go | 41 +- vendor/go.uber.org/atomic/string_ext.go | 45 + vendor/go.uber.org/atomic/time.go | 55 + vendor/go.uber.org/atomic/time_ext.go | 36 + vendor/go.uber.org/atomic/uint32.go | 102 + vendor/go.uber.org/atomic/uint64.go | 102 + vendor/go.uber.org/atomic/uintptr.go | 102 + vendor/go.uber.org/atomic/unsafe_pointer.go | 58 + vendor/go.uber.org/atomic/value.go | 31 + vendor/go.uber.org/multierr/.travis.yml | 29 - vendor/go.uber.org/multierr/CHANGELOG.md | 12 + vendor/go.uber.org/multierr/LICENSE.txt | 2 +- vendor/go.uber.org/multierr/Makefile | 10 +- vendor/go.uber.org/multierr/README.md | 8 +- vendor/go.uber.org/multierr/error.go | 208 +- .../protobuf => golang.org/x/crypto}/LICENSE | 9 +- vendor/golang.org/x/crypto/PATENTS | 22 + vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go | 77 + vendor/golang.org/x/exp/LICENSE | 27 + vendor/golang.org/x/exp/PATENTS | 22 + vendor/golang.org/x/exp/maps/maps.go | 94 + .../x/net/internal/socket/cmsghdr.go | 1 - .../x/net/internal/socket/cmsghdr_bsd.go | 1 - .../internal/socket/cmsghdr_linux_32bit.go | 2 - .../internal/socket/cmsghdr_linux_64bit.go | 2 - .../internal/socket/cmsghdr_solaris_64bit.go | 1 - .../x/net/internal/socket/cmsghdr_stub.go | 1 - .../x/net/internal/socket/cmsghdr_unix.go | 1 - .../net/internal/socket/complete_dontwait.go | 1 - .../internal/socket/complete_nodontwait.go | 1 - .../golang.org/x/net/internal/socket/empty.s | 1 - .../x/net/internal/socket/error_unix.go | 1 - .../x/net/internal/socket/iovec_32bit.go | 2 - .../x/net/internal/socket/iovec_64bit.go | 2 - .../internal/socket/iovec_solaris_64bit.go | 1 - .../x/net/internal/socket/iovec_stub.go | 1 - .../x/net/internal/socket/mmsghdr_stub.go | 1 - .../x/net/internal/socket/mmsghdr_unix.go | 1 - .../x/net/internal/socket/msghdr_bsd.go | 1 - .../x/net/internal/socket/msghdr_bsdvar.go | 1 - .../net/internal/socket/msghdr_linux_32bit.go | 2 - .../net/internal/socket/msghdr_linux_64bit.go | 2 - .../internal/socket/msghdr_solaris_64bit.go | 1 - .../x/net/internal/socket/msghdr_stub.go | 1 - .../x/net/internal/socket/msghdr_zos_s390x.go | 1 - .../x/net/internal/socket/norace.go | 1 - .../golang.org/x/net/internal/socket/race.go | 1 - .../x/net/internal/socket/rawconn_mmsg.go | 1 - .../x/net/internal/socket/rawconn_msg.go | 1 - .../x/net/internal/socket/rawconn_nommsg.go | 1 - .../x/net/internal/socket/rawconn_nomsg.go | 1 - .../x/net/internal/socket/sys_bsd.go | 1 - .../x/net/internal/socket/sys_const_unix.go | 1 - .../x/net/internal/socket/sys_linux.go | 1 - .../net/internal/socket/sys_linux_loong64.go | 1 - .../net/internal/socket/sys_linux_riscv64.go | 1 - .../x/net/internal/socket/sys_posix.go | 1 - .../x/net/internal/socket/sys_stub.go | 1 - .../x/net/internal/socket/sys_unix.go | 1 - .../x/net/internal/socket/zsys_aix_ppc64.go | 1 - .../net/internal/socket/zsys_linux_loong64.go | 1 - .../net/internal/socket/zsys_linux_riscv64.go | 1 - vendor/golang.org/x/net/ipv4/control_bsd.go | 1 - .../golang.org/x/net/ipv4/control_pktinfo.go | 1 - vendor/golang.org/x/net/ipv4/control_stub.go | 1 - vendor/golang.org/x/net/ipv4/control_unix.go | 1 - vendor/golang.org/x/net/ipv4/icmp_stub.go | 1 - vendor/golang.org/x/net/ipv4/payload_cmsg.go | 1 - .../golang.org/x/net/ipv4/payload_nocmsg.go | 1 - vendor/golang.org/x/net/ipv4/sockopt_posix.go | 1 - vendor/golang.org/x/net/ipv4/sockopt_stub.go | 1 - vendor/golang.org/x/net/ipv4/sys_aix.go | 1 - vendor/golang.org/x/net/ipv4/sys_asmreq.go | 1 - .../golang.org/x/net/ipv4/sys_asmreq_stub.go | 1 - vendor/golang.org/x/net/ipv4/sys_asmreqn.go | 1 - .../golang.org/x/net/ipv4/sys_asmreqn_stub.go | 1 - vendor/golang.org/x/net/ipv4/sys_bpf.go | 1 - vendor/golang.org/x/net/ipv4/sys_bpf_stub.go | 1 - vendor/golang.org/x/net/ipv4/sys_bsd.go | 1 - vendor/golang.org/x/net/ipv4/sys_ssmreq.go | 1 - .../golang.org/x/net/ipv4/sys_ssmreq_stub.go | 1 - vendor/golang.org/x/net/ipv4/sys_stub.go | 1 - .../golang.org/x/net/ipv4/zsys_aix_ppc64.go | 1 - .../x/net/ipv4/zsys_linux_loong64.go | 1 - .../x/net/ipv4/zsys_linux_riscv64.go | 1 - vendor/golang.org/x/sync/AUTHORS | 3 - vendor/golang.org/x/sync/CONTRIBUTORS | 3 - vendor/golang.org/x/sync/errgroup/errgroup.go | 85 +- vendor/golang.org/x/sync/errgroup/go120.go | 13 + .../golang.org/x/sync/errgroup/pre_go120.go | 14 + .../sys/internal/unsafeheader/unsafeheader.go | 30 - vendor/golang.org/x/sys/unix/aliases.go | 4 +- vendor/golang.org/x/sys/unix/asm_aix_ppc64.s | 1 - vendor/golang.org/x/sys/unix/asm_bsd_386.s | 2 - vendor/golang.org/x/sys/unix/asm_bsd_amd64.s | 2 - vendor/golang.org/x/sys/unix/asm_bsd_arm.s | 2 - vendor/golang.org/x/sys/unix/asm_bsd_arm64.s | 2 - vendor/golang.org/x/sys/unix/asm_bsd_ppc64.s | 2 - .../golang.org/x/sys/unix/asm_bsd_riscv64.s | 2 - vendor/golang.org/x/sys/unix/asm_linux_386.s | 1 - .../golang.org/x/sys/unix/asm_linux_amd64.s | 1 - vendor/golang.org/x/sys/unix/asm_linux_arm.s | 1 - .../golang.org/x/sys/unix/asm_linux_arm64.s | 3 - .../golang.org/x/sys/unix/asm_linux_loong64.s | 3 - .../golang.org/x/sys/unix/asm_linux_mips64x.s | 3 - .../golang.org/x/sys/unix/asm_linux_mipsx.s | 3 - .../golang.org/x/sys/unix/asm_linux_ppc64x.s | 3 - .../golang.org/x/sys/unix/asm_linux_riscv64.s | 2 - .../golang.org/x/sys/unix/asm_linux_s390x.s | 3 - .../x/sys/unix/asm_openbsd_mips64.s | 1 - .../golang.org/x/sys/unix/asm_solaris_amd64.s | 1 - vendor/golang.org/x/sys/unix/asm_zos_s390x.s | 3 - vendor/golang.org/x/sys/unix/cap_freebsd.go | 1 - vendor/golang.org/x/sys/unix/constants.go | 1 - vendor/golang.org/x/sys/unix/dev_aix_ppc.go | 1 - vendor/golang.org/x/sys/unix/dev_aix_ppc64.go | 1 - vendor/golang.org/x/sys/unix/dev_zos.go | 1 - vendor/golang.org/x/sys/unix/dirent.go | 1 - vendor/golang.org/x/sys/unix/endian_big.go | 1 - vendor/golang.org/x/sys/unix/endian_little.go | 1 - vendor/golang.org/x/sys/unix/env_unix.go | 1 - vendor/golang.org/x/sys/unix/epoll_zos.go | 1 - vendor/golang.org/x/sys/unix/fcntl.go | 3 +- .../x/sys/unix/fcntl_linux_32bit.go | 1 - vendor/golang.org/x/sys/unix/fdset.go | 1 - vendor/golang.org/x/sys/unix/fstatfs_zos.go | 1 - vendor/golang.org/x/sys/unix/gccgo.go | 1 - vendor/golang.org/x/sys/unix/gccgo_c.c | 1 - .../x/sys/unix/gccgo_linux_amd64.go | 1 - vendor/golang.org/x/sys/unix/ifreq_linux.go | 1 - vendor/golang.org/x/sys/unix/ioctl_linux.go | 5 + vendor/golang.org/x/sys/unix/ioctl_signed.go | 69 + .../sys/unix/{ioctl.go => ioctl_unsigned.go} | 20 +- vendor/golang.org/x/sys/unix/ioctl_zos.go | 21 +- vendor/golang.org/x/sys/unix/mkall.sh | 2 +- vendor/golang.org/x/sys/unix/mkerrors.sh | 57 +- vendor/golang.org/x/sys/unix/mmap_nomremap.go | 13 + vendor/golang.org/x/sys/unix/mremap.go | 52 + vendor/golang.org/x/sys/unix/pagesize_unix.go | 1 - .../golang.org/x/sys/unix/pledge_openbsd.go | 92 +- vendor/golang.org/x/sys/unix/ptrace_darwin.go | 1 - vendor/golang.org/x/sys/unix/ptrace_ios.go | 1 - vendor/golang.org/x/sys/unix/race.go | 1 - vendor/golang.org/x/sys/unix/race0.go | 1 - .../x/sys/unix/readdirent_getdents.go | 1 - .../x/sys/unix/readdirent_getdirentries.go | 1 - vendor/golang.org/x/sys/unix/sockcmsg_unix.go | 1 - .../x/sys/unix/sockcmsg_unix_other.go | 1 - vendor/golang.org/x/sys/unix/syscall.go | 1 - vendor/golang.org/x/sys/unix/syscall_aix.go | 28 +- .../golang.org/x/sys/unix/syscall_aix_ppc.go | 2 - .../x/sys/unix/syscall_aix_ppc64.go | 2 - vendor/golang.org/x/sys/unix/syscall_bsd.go | 20 +- .../golang.org/x/sys/unix/syscall_darwin.go | 251 +- .../x/sys/unix/syscall_darwin_amd64.go | 1 - .../x/sys/unix/syscall_darwin_arm64.go | 1 - .../x/sys/unix/syscall_darwin_libSystem.go | 3 +- .../x/sys/unix/syscall_dragonfly.go | 200 +- .../x/sys/unix/syscall_dragonfly_amd64.go | 1 - .../golang.org/x/sys/unix/syscall_freebsd.go | 248 +- .../x/sys/unix/syscall_freebsd_386.go | 18 +- .../x/sys/unix/syscall_freebsd_amd64.go | 18 +- .../x/sys/unix/syscall_freebsd_arm.go | 16 +- .../x/sys/unix/syscall_freebsd_arm64.go | 16 +- .../x/sys/unix/syscall_freebsd_riscv64.go | 16 +- vendor/golang.org/x/sys/unix/syscall_hurd.go | 9 +- .../golang.org/x/sys/unix/syscall_hurd_386.go | 1 - .../golang.org/x/sys/unix/syscall_illumos.go | 1 - vendor/golang.org/x/sys/unix/syscall_linux.go | 398 +- .../x/sys/unix/syscall_linux_386.go | 28 - .../x/sys/unix/syscall_linux_alarm.go | 2 - .../x/sys/unix/syscall_linux_amd64.go | 4 +- .../x/sys/unix/syscall_linux_amd64_gc.go | 1 - .../x/sys/unix/syscall_linux_arm.go | 28 - .../x/sys/unix/syscall_linux_arm64.go | 13 +- .../golang.org/x/sys/unix/syscall_linux_gc.go | 1 - .../x/sys/unix/syscall_linux_gc_386.go | 1 - .../x/sys/unix/syscall_linux_gc_arm.go | 1 - .../x/sys/unix/syscall_linux_gccgo_386.go | 1 - .../x/sys/unix/syscall_linux_gccgo_arm.go | 1 - .../x/sys/unix/syscall_linux_loong64.go | 8 +- .../x/sys/unix/syscall_linux_mips64x.go | 5 +- .../x/sys/unix/syscall_linux_mipsx.go | 29 - .../x/sys/unix/syscall_linux_ppc.go | 28 - .../x/sys/unix/syscall_linux_ppc64x.go | 3 - .../x/sys/unix/syscall_linux_riscv64.go | 15 +- .../x/sys/unix/syscall_linux_s390x.go | 2 - .../x/sys/unix/syscall_linux_sparc64.go | 2 - .../golang.org/x/sys/unix/syscall_netbsd.go | 279 +- .../x/sys/unix/syscall_netbsd_386.go | 1 - .../x/sys/unix/syscall_netbsd_amd64.go | 1 - .../x/sys/unix/syscall_netbsd_arm.go | 1 - .../x/sys/unix/syscall_netbsd_arm64.go | 1 - .../golang.org/x/sys/unix/syscall_openbsd.go | 121 +- .../x/sys/unix/syscall_openbsd_386.go | 1 - .../x/sys/unix/syscall_openbsd_amd64.go | 1 - .../x/sys/unix/syscall_openbsd_arm.go | 1 - .../x/sys/unix/syscall_openbsd_arm64.go | 1 - .../x/sys/unix/syscall_openbsd_libc.go | 1 - .../x/sys/unix/syscall_openbsd_ppc64.go | 1 - .../x/sys/unix/syscall_openbsd_riscv64.go | 1 - .../golang.org/x/sys/unix/syscall_solaris.go | 73 +- .../x/sys/unix/syscall_solaris_amd64.go | 1 - vendor/golang.org/x/sys/unix/syscall_unix.go | 19 +- .../golang.org/x/sys/unix/syscall_unix_gc.go | 2 - .../x/sys/unix/syscall_unix_gc_ppc64x.go | 3 - .../x/sys/unix/syscall_zos_s390x.go | 32 +- vendor/golang.org/x/sys/unix/sysvshm_linux.go | 1 - vendor/golang.org/x/sys/unix/sysvshm_unix.go | 1 - .../x/sys/unix/sysvshm_unix_other.go | 1 - vendor/golang.org/x/sys/unix/timestruct.go | 1 - .../golang.org/x/sys/unix/unveil_openbsd.go | 41 +- vendor/golang.org/x/sys/unix/xattr_bsd.go | 1 - .../golang.org/x/sys/unix/zerrors_aix_ppc.go | 1 - .../x/sys/unix/zerrors_aix_ppc64.go | 1 - .../x/sys/unix/zerrors_darwin_amd64.go | 20 +- .../x/sys/unix/zerrors_darwin_arm64.go | 20 +- .../x/sys/unix/zerrors_dragonfly_amd64.go | 1 - .../x/sys/unix/zerrors_freebsd_386.go | 1 - .../x/sys/unix/zerrors_freebsd_amd64.go | 1 - .../x/sys/unix/zerrors_freebsd_arm.go | 1 - .../x/sys/unix/zerrors_freebsd_arm64.go | 1 - .../x/sys/unix/zerrors_freebsd_riscv64.go | 1 - vendor/golang.org/x/sys/unix/zerrors_linux.go | 180 +- .../x/sys/unix/zerrors_linux_386.go | 15 +- .../x/sys/unix/zerrors_linux_amd64.go | 15 +- .../x/sys/unix/zerrors_linux_arm.go | 15 +- .../x/sys/unix/zerrors_linux_arm64.go | 17 +- .../x/sys/unix/zerrors_linux_loong64.go | 18 +- .../x/sys/unix/zerrors_linux_mips.go | 15 +- .../x/sys/unix/zerrors_linux_mips64.go | 15 +- .../x/sys/unix/zerrors_linux_mips64le.go | 15 +- .../x/sys/unix/zerrors_linux_mipsle.go | 15 +- .../x/sys/unix/zerrors_linux_ppc.go | 15 +- .../x/sys/unix/zerrors_linux_ppc64.go | 15 +- .../x/sys/unix/zerrors_linux_ppc64le.go | 15 +- .../x/sys/unix/zerrors_linux_riscv64.go | 18 +- .../x/sys/unix/zerrors_linux_s390x.go | 15 +- .../x/sys/unix/zerrors_linux_sparc64.go | 63 +- .../x/sys/unix/zerrors_netbsd_386.go | 1 - .../x/sys/unix/zerrors_netbsd_amd64.go | 1 - .../x/sys/unix/zerrors_netbsd_arm.go | 1 - .../x/sys/unix/zerrors_netbsd_arm64.go | 1 - .../x/sys/unix/zerrors_openbsd_386.go | 1 - .../x/sys/unix/zerrors_openbsd_amd64.go | 1 - .../x/sys/unix/zerrors_openbsd_arm.go | 1 - .../x/sys/unix/zerrors_openbsd_arm64.go | 1 - .../x/sys/unix/zerrors_openbsd_mips64.go | 1 - .../x/sys/unix/zerrors_openbsd_ppc64.go | 1 - .../x/sys/unix/zerrors_openbsd_riscv64.go | 1 - .../x/sys/unix/zerrors_solaris_amd64.go | 1 - .../x/sys/unix/zerrors_zos_s390x.go | 1 - .../x/sys/unix/zptrace_armnn_linux.go | 10 +- .../x/sys/unix/zptrace_linux_arm64.go | 4 +- .../x/sys/unix/zptrace_mipsnn_linux.go | 10 +- .../x/sys/unix/zptrace_mipsnnle_linux.go | 10 +- .../x/sys/unix/zptrace_x86_linux.go | 10 +- .../golang.org/x/sys/unix/zsyscall_aix_ppc.go | 46 +- .../x/sys/unix/zsyscall_aix_ppc64.go | 47 +- .../x/sys/unix/zsyscall_aix_ppc64_gc.go | 18 +- .../x/sys/unix/zsyscall_aix_ppc64_gccgo.go | 19 +- .../x/sys/unix/zsyscall_darwin_amd64.go | 72 +- .../x/sys/unix/zsyscall_darwin_amd64.s | 160 +- .../x/sys/unix/zsyscall_darwin_arm64.go | 72 +- .../x/sys/unix/zsyscall_darwin_arm64.s | 160 +- .../x/sys/unix/zsyscall_dragonfly_amd64.go | 43 +- .../x/sys/unix/zsyscall_freebsd_386.go | 53 +- .../x/sys/unix/zsyscall_freebsd_amd64.go | 53 +- .../x/sys/unix/zsyscall_freebsd_arm.go | 53 +- .../x/sys/unix/zsyscall_freebsd_arm64.go | 53 +- .../x/sys/unix/zsyscall_freebsd_riscv64.go | 53 +- .../x/sys/unix/zsyscall_illumos_amd64.go | 11 +- .../golang.org/x/sys/unix/zsyscall_linux.go | 125 +- .../x/sys/unix/zsyscall_linux_386.go | 11 - .../x/sys/unix/zsyscall_linux_amd64.go | 11 - .../x/sys/unix/zsyscall_linux_arm.go | 11 - .../x/sys/unix/zsyscall_linux_arm64.go | 11 - .../x/sys/unix/zsyscall_linux_loong64.go | 1 - .../x/sys/unix/zsyscall_linux_mips.go | 11 - .../x/sys/unix/zsyscall_linux_mips64.go | 11 - .../x/sys/unix/zsyscall_linux_mips64le.go | 11 - .../x/sys/unix/zsyscall_linux_mipsle.go | 11 - .../x/sys/unix/zsyscall_linux_ppc.go | 11 - .../x/sys/unix/zsyscall_linux_ppc64.go | 11 - .../x/sys/unix/zsyscall_linux_ppc64le.go | 11 - .../x/sys/unix/zsyscall_linux_riscv64.go | 27 +- .../x/sys/unix/zsyscall_linux_s390x.go | 11 - .../x/sys/unix/zsyscall_linux_sparc64.go | 11 - .../x/sys/unix/zsyscall_netbsd_386.go | 50 +- .../x/sys/unix/zsyscall_netbsd_amd64.go | 50 +- .../x/sys/unix/zsyscall_netbsd_arm.go | 50 +- .../x/sys/unix/zsyscall_netbsd_arm64.go | 50 +- .../x/sys/unix/zsyscall_openbsd_386.go | 116 +- .../x/sys/unix/zsyscall_openbsd_386.s | 35 +- .../x/sys/unix/zsyscall_openbsd_amd64.go | 116 +- .../x/sys/unix/zsyscall_openbsd_amd64.s | 35 +- .../x/sys/unix/zsyscall_openbsd_arm.go | 116 +- .../x/sys/unix/zsyscall_openbsd_arm.s | 35 +- .../x/sys/unix/zsyscall_openbsd_arm64.go | 116 +- .../x/sys/unix/zsyscall_openbsd_arm64.s | 35 +- .../x/sys/unix/zsyscall_openbsd_mips64.go | 116 +- .../x/sys/unix/zsyscall_openbsd_mips64.s | 35 +- .../x/sys/unix/zsyscall_openbsd_ppc64.go | 116 +- .../x/sys/unix/zsyscall_openbsd_ppc64.s | 42 +- .../x/sys/unix/zsyscall_openbsd_riscv64.go | 116 +- .../x/sys/unix/zsyscall_openbsd_riscv64.s | 35 +- .../x/sys/unix/zsyscall_solaris_amd64.go | 281 +- .../x/sys/unix/zsyscall_zos_s390x.go | 24 +- .../x/sys/unix/zsysctl_openbsd_386.go | 1 - .../x/sys/unix/zsysctl_openbsd_amd64.go | 1 - .../x/sys/unix/zsysctl_openbsd_arm.go | 1 - .../x/sys/unix/zsysctl_openbsd_arm64.go | 1 - .../x/sys/unix/zsysctl_openbsd_mips64.go | 1 - .../x/sys/unix/zsysctl_openbsd_ppc64.go | 1 - .../x/sys/unix/zsysctl_openbsd_riscv64.go | 1 - .../x/sys/unix/zsysnum_darwin_amd64.go | 1 - .../x/sys/unix/zsysnum_darwin_arm64.go | 1 - .../x/sys/unix/zsysnum_dragonfly_amd64.go | 1 - .../x/sys/unix/zsysnum_freebsd_386.go | 1 - .../x/sys/unix/zsysnum_freebsd_amd64.go | 1 - .../x/sys/unix/zsysnum_freebsd_arm.go | 1 - .../x/sys/unix/zsysnum_freebsd_arm64.go | 1 - .../x/sys/unix/zsysnum_freebsd_riscv64.go | 1 - .../x/sys/unix/zsysnum_linux_386.go | 7 +- .../x/sys/unix/zsysnum_linux_amd64.go | 7 +- .../x/sys/unix/zsysnum_linux_arm.go | 7 +- .../x/sys/unix/zsysnum_linux_arm64.go | 7 +- .../x/sys/unix/zsysnum_linux_loong64.go | 7 +- .../x/sys/unix/zsysnum_linux_mips.go | 7 +- .../x/sys/unix/zsysnum_linux_mips64.go | 7 +- .../x/sys/unix/zsysnum_linux_mips64le.go | 7 +- .../x/sys/unix/zsysnum_linux_mipsle.go | 7 +- .../x/sys/unix/zsysnum_linux_ppc.go | 7 +- .../x/sys/unix/zsysnum_linux_ppc64.go | 7 +- .../x/sys/unix/zsysnum_linux_ppc64le.go | 7 +- .../x/sys/unix/zsysnum_linux_riscv64.go | 9 +- .../x/sys/unix/zsysnum_linux_s390x.go | 8 +- .../x/sys/unix/zsysnum_linux_sparc64.go | 7 +- .../x/sys/unix/zsysnum_netbsd_386.go | 1 - .../x/sys/unix/zsysnum_netbsd_amd64.go | 1 - .../x/sys/unix/zsysnum_netbsd_arm.go | 1 - .../x/sys/unix/zsysnum_netbsd_arm64.go | 1 - .../x/sys/unix/zsysnum_openbsd_386.go | 1 - .../x/sys/unix/zsysnum_openbsd_amd64.go | 1 - .../x/sys/unix/zsysnum_openbsd_arm.go | 1 - .../x/sys/unix/zsysnum_openbsd_arm64.go | 1 - .../x/sys/unix/zsysnum_openbsd_mips64.go | 1 - .../x/sys/unix/zsysnum_openbsd_ppc64.go | 1 - .../x/sys/unix/zsysnum_openbsd_riscv64.go | 1 - .../x/sys/unix/zsysnum_zos_s390x.go | 1 - .../golang.org/x/sys/unix/ztypes_aix_ppc.go | 1 - .../golang.org/x/sys/unix/ztypes_aix_ppc64.go | 1 - .../x/sys/unix/ztypes_darwin_amd64.go | 12 +- .../x/sys/unix/ztypes_darwin_arm64.go | 12 +- .../x/sys/unix/ztypes_dragonfly_amd64.go | 1 - .../x/sys/unix/ztypes_freebsd_386.go | 3 +- .../x/sys/unix/ztypes_freebsd_amd64.go | 3 +- .../x/sys/unix/ztypes_freebsd_arm.go | 3 +- .../x/sys/unix/ztypes_freebsd_arm64.go | 3 +- .../x/sys/unix/ztypes_freebsd_riscv64.go | 3 +- vendor/golang.org/x/sys/unix/ztypes_linux.go | 343 +- .../golang.org/x/sys/unix/ztypes_linux_386.go | 5 +- .../x/sys/unix/ztypes_linux_amd64.go | 5 +- .../golang.org/x/sys/unix/ztypes_linux_arm.go | 5 +- .../x/sys/unix/ztypes_linux_arm64.go | 5 +- .../x/sys/unix/ztypes_linux_loong64.go | 5 +- .../x/sys/unix/ztypes_linux_mips.go | 5 +- .../x/sys/unix/ztypes_linux_mips64.go | 5 +- .../x/sys/unix/ztypes_linux_mips64le.go | 5 +- .../x/sys/unix/ztypes_linux_mipsle.go | 5 +- .../golang.org/x/sys/unix/ztypes_linux_ppc.go | 5 +- .../x/sys/unix/ztypes_linux_ppc64.go | 5 +- .../x/sys/unix/ztypes_linux_ppc64le.go | 5 +- .../x/sys/unix/ztypes_linux_riscv64.go | 32 +- .../x/sys/unix/ztypes_linux_s390x.go | 5 +- .../x/sys/unix/ztypes_linux_sparc64.go | 5 +- .../x/sys/unix/ztypes_netbsd_386.go | 1 - .../x/sys/unix/ztypes_netbsd_amd64.go | 1 - .../x/sys/unix/ztypes_netbsd_arm.go | 1 - .../x/sys/unix/ztypes_netbsd_arm64.go | 1 - .../x/sys/unix/ztypes_openbsd_386.go | 1 - .../x/sys/unix/ztypes_openbsd_amd64.go | 1 - .../x/sys/unix/ztypes_openbsd_arm.go | 1 - .../x/sys/unix/ztypes_openbsd_arm64.go | 1 - .../x/sys/unix/ztypes_openbsd_mips64.go | 1 - .../x/sys/unix/ztypes_openbsd_ppc64.go | 1 - .../x/sys/unix/ztypes_openbsd_riscv64.go | 1 - .../x/sys/unix/ztypes_solaris_amd64.go | 1 - .../golang.org/x/sys/unix/ztypes_zos_s390x.go | 1 - vendor/golang.org/x/sys/windows/aliases.go | 1 - vendor/golang.org/x/sys/windows/empty.s | 1 - .../golang.org/x/sys/windows/env_windows.go | 17 +- vendor/golang.org/x/sys/windows/eventlog.go | 1 - .../golang.org/x/sys/windows/exec_windows.go | 92 +- vendor/golang.org/x/sys/windows/mksyscall.go | 1 - vendor/golang.org/x/sys/windows/race.go | 1 - vendor/golang.org/x/sys/windows/race0.go | 1 - .../x/sys/windows/security_windows.go | 21 +- vendor/golang.org/x/sys/windows/service.go | 12 +- vendor/golang.org/x/sys/windows/str.go | 1 - vendor/golang.org/x/sys/windows/syscall.go | 1 - .../x/sys/windows/syscall_windows.go | 168 +- .../golang.org/x/sys/windows/types_windows.go | 154 +- .../x/sys/windows/zsyscall_windows.go | 243 +- vendor/google.golang.org/protobuf/AUTHORS | 3 - .../google.golang.org/protobuf/CONTRIBUTORS | 3 - .../encoding/protodelim/protodelim.go | 160 + .../protobuf/encoding/prototext/decode.go | 127 +- .../protobuf/encoding/prototext/encode.go | 57 +- .../protobuf/encoding/protowire/wire.go | 59 +- .../protobuf/internal/descfmt/stringer.go | 229 +- .../internal/editiondefaults/defaults.go | 12 + .../editiondefaults/editions_defaults.binpb | 4 + .../internal/encoding/defval/default.go | 78 +- .../encoding/messageset/messageset.go | 7 +- .../protobuf/internal/encoding/tag/tag.go | 96 +- .../protobuf/internal/encoding/text/decode.go | 37 +- .../internal/encoding/text/decode_number.go | 49 +- .../protobuf/internal/encoding/text/doc.go | 4 +- .../protobuf/internal/encoding/text/encode.go | 15 +- .../protobuf/internal/errors/is_go112.go | 1 + .../protobuf/internal/errors/is_go113.go | 1 + .../protobuf/internal/filedesc/build.go | 19 +- .../protobuf/internal/filedesc/desc.go | 460 +- .../protobuf/internal/filedesc/desc_init.go | 88 +- .../protobuf/internal/filedesc/desc_lazy.go | 108 +- .../protobuf/internal/filedesc/desc_list.go | 167 +- .../protobuf/internal/filedesc/editions.go | 142 + .../protobuf/internal/filedesc/placeholder.go | 136 +- .../protobuf/internal/filetype/build.go | 87 +- .../internal/flags/proto_legacy_disable.go | 1 + .../internal/flags/proto_legacy_enable.go | 1 + .../protobuf/internal/genid/descriptor_gen.go | 458 +- .../internal/genid/go_features_gen.go | 31 + .../protobuf/internal/genid/struct_gen.go | 5 + .../protobuf/internal/genid/type_gen.go | 44 + .../protobuf/internal/impl/api_export.go | 42 +- .../protobuf/internal/impl/checkinit.go | 12 +- .../protobuf/internal/impl/codec_extension.go | 56 +- .../protobuf/internal/impl/codec_field.go | 90 +- .../protobuf/internal/impl/codec_gen.go | 113 +- .../protobuf/internal/impl/codec_map.go | 20 +- .../protobuf/internal/impl/codec_map_go111.go | 1 + .../protobuf/internal/impl/codec_map_go112.go | 1 + .../protobuf/internal/impl/codec_message.go | 30 +- .../protobuf/internal/impl/codec_reflect.go | 1 + .../protobuf/internal/impl/codec_tables.go | 290 +- .../protobuf/internal/impl/codec_unsafe.go | 1 + .../protobuf/internal/impl/convert.go | 229 +- .../protobuf/internal/impl/convert_list.go | 42 +- .../protobuf/internal/impl/convert_map.go | 32 +- .../protobuf/internal/impl/decode.go | 29 +- .../protobuf/internal/impl/enum.go | 10 +- .../protobuf/internal/impl/extension.go | 26 +- .../protobuf/internal/impl/legacy_enum.go | 57 +- .../protobuf/internal/impl/legacy_export.go | 18 +- .../internal/impl/legacy_extension.go | 100 +- .../protobuf/internal/impl/legacy_message.go | 146 +- .../protobuf/internal/impl/merge.go | 32 +- .../protobuf/internal/impl/message.go | 58 +- .../protobuf/internal/impl/message_reflect.go | 74 +- .../internal/impl/message_reflect_field.go | 120 +- .../protobuf/internal/impl/pointer_reflect.go | 37 + .../protobuf/internal/impl/pointer_unsafe.go | 41 + .../protobuf/internal/impl/validate.go | 50 +- .../protobuf/internal/impl/weak.go | 16 +- .../protobuf/internal/order/order.go | 18 +- .../protobuf/internal/order/range.go | 22 +- .../protobuf/internal/strs/strings.go | 2 +- .../protobuf/internal/strs/strings_pure.go | 1 + ...ings_unsafe.go => strings_unsafe_go120.go} | 11 +- .../internal/strs/strings_unsafe_go121.go | 74 + .../protobuf/internal/version/version.go | 56 +- .../protobuf/proto/decode.go | 22 +- .../google.golang.org/protobuf/proto/doc.go | 82 +- .../protobuf/proto/encode.go | 7 +- .../google.golang.org/protobuf/proto/equal.go | 178 +- .../protobuf/proto/extension.go | 2 +- .../google.golang.org/protobuf/proto/merge.go | 2 +- .../google.golang.org/protobuf/proto/proto.go | 18 +- .../protobuf/proto/proto_methods.go | 1 + .../protobuf/proto/proto_reflect.go | 1 + .../google.golang.org/protobuf/proto/size.go | 10 +- .../protobuf/reflect/protoreflect/methods.go | 1 + .../protobuf/reflect/protoreflect/proto.go | 93 +- .../protobuf/reflect/protoreflect/source.go | 1 + .../reflect/protoreflect/source_gen.go | 95 +- .../protobuf/reflect/protoreflect/type.go | 45 +- .../protobuf/reflect/protoreflect/value.go | 26 +- .../reflect/protoreflect/value_equal.go | 168 + .../reflect/protoreflect/value_pure.go | 1 + .../reflect/protoreflect/value_union.go | 65 +- ...{value_unsafe.go => value_unsafe_go120.go} | 3 +- .../protoreflect/value_unsafe_go121.go | 87 + .../reflect/protoregistry/registry.go | 71 +- .../protobuf/runtime/protoiface/methods.go | 1 + .../protobuf/runtime/protoimpl/version.go | 8 +- .../protobuf/types/known/anypb/any.pb.go | 498 -- .../types/known/durationpb/duration.pb.go | 379 - .../types/known/timestamppb/timestamp.pb.go | 63 +- .../alecthomas/kingpin.v2/.travis.yml | 4 - .../alecthomas/kingpin.v2/templates.go | 262 - vendor/howett.net/plist/.gitignore | 16 + vendor/howett.net/plist/.gitlab-ci.yml | 39 + vendor/howett.net/plist/LICENSE | 58 + vendor/howett.net/plist/README.md | 21 + vendor/howett.net/plist/bplist.go | 26 + vendor/howett.net/plist/bplist_generator.go | 303 + vendor/howett.net/plist/bplist_parser.go | 356 + vendor/howett.net/plist/decode.go | 119 + vendor/howett.net/plist/doc.go | 5 + vendor/howett.net/plist/encode.go | 126 + vendor/howett.net/plist/fuzz.go | 17 + vendor/howett.net/plist/marshal.go | 192 + vendor/howett.net/plist/must.go | 50 + vendor/howett.net/plist/plist.go | 83 + vendor/howett.net/plist/plist_types.go | 172 + vendor/howett.net/plist/text_generator.go | 228 + vendor/howett.net/plist/text_parser.go | 586 ++ vendor/howett.net/plist/text_tables.go | 61 + vendor/howett.net/plist/typeinfo.go | 170 + vendor/howett.net/plist/unmarshal.go | 331 + vendor/howett.net/plist/util.go | 25 + vendor/howett.net/plist/xml_generator.go | 178 + vendor/howett.net/plist/xml_parser.go | 211 + vendor/howett.net/plist/zerocopy.go | 20 + vendor/howett.net/plist/zerocopy_appengine.go | 7 + vendor/modules.txt | 192 +- 1228 files changed, 63076 insertions(+), 38248 deletions(-) create mode 100644 vendor/github.com/alecthomas/kingpin/v2/.travis.yml rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/COPYING (100%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/README.md (89%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/actions.go (100%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/app.go (97%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/args.go (88%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/cmd.go (80%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/completions.go (100%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/doc.go (97%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/envar.go (81%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/flags.go (94%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/global.go (97%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/guesswidth.go (100%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/guesswidth_unix.go (100%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/model.go (77%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/parser.go (95%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/parsers.go (98%) create mode 100644 vendor/github.com/alecthomas/kingpin/v2/templates.go rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/usage.go (87%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/values.go (95%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/values.json (100%) rename vendor/{gopkg.in/alecthomas/kingpin.v2 => github.com/alecthomas/kingpin/v2}/values_generated.go (100%) delete mode 100644 vendor/github.com/alecthomas/template/README.md delete mode 100644 vendor/github.com/alecthomas/template/doc.go delete mode 100644 vendor/github.com/alecthomas/template/exec.go delete mode 100644 vendor/github.com/alecthomas/template/funcs.go delete mode 100644 vendor/github.com/alecthomas/template/helper.go delete mode 100644 vendor/github.com/alecthomas/template/parse/lex.go delete mode 100644 vendor/github.com/alecthomas/template/parse/node.go delete mode 100644 vendor/github.com/alecthomas/template/parse/parse.go delete mode 100644 vendor/github.com/alecthomas/template/template.go delete mode 100644 vendor/github.com/beevik/ntp/.travis.yml create mode 100644 vendor/github.com/beevik/ntp/auth.go delete mode 100644 vendor/github.com/cespare/xxhash/v2/.travis.yml create mode 100644 vendor/github.com/cespare/xxhash/v2/testall.sh create mode 100644 vendor/github.com/cespare/xxhash/v2/xxhash_arm64.s rename vendor/github.com/cespare/xxhash/v2/{xxhash_amd64.go => xxhash_asm.go} (73%) delete mode 100644 vendor/github.com/coreos/go-systemd/dbus/methods.go rename vendor/github.com/coreos/go-systemd/{ => v22}/LICENSE (100%) rename vendor/github.com/coreos/go-systemd/{ => v22}/NOTICE (100%) rename vendor/github.com/coreos/go-systemd/{ => v22}/dbus/dbus.go (73%) create mode 100644 vendor/github.com/coreos/go-systemd/v22/dbus/methods.go rename vendor/github.com/coreos/go-systemd/{ => v22}/dbus/properties.go (99%) rename vendor/github.com/coreos/go-systemd/{ => v22}/dbus/set.go (100%) rename vendor/github.com/coreos/go-systemd/{ => v22}/dbus/subscription.go (99%) rename vendor/github.com/coreos/go-systemd/{ => v22}/dbus/subscription_set.go (100%) create mode 100644 vendor/github.com/dennwc/btrfs/LICENSE create mode 100644 vendor/github.com/dennwc/btrfs/README.md create mode 100644 vendor/github.com/dennwc/btrfs/btrfs.go create mode 100644 vendor/github.com/dennwc/btrfs/btrfs_h.go create mode 100644 vendor/github.com/dennwc/btrfs/btrfs_list.go create mode 100644 vendor/github.com/dennwc/btrfs/btrfs_tree.go create mode 100644 vendor/github.com/dennwc/btrfs/btrfs_tree_h.go create mode 100644 vendor/github.com/dennwc/btrfs/btrfs_tree_hc.go create mode 100644 vendor/github.com/dennwc/btrfs/errors.go create mode 100644 vendor/github.com/dennwc/btrfs/headers.go create mode 100644 vendor/github.com/dennwc/btrfs/ioctl_h.go create mode 100644 vendor/github.com/dennwc/btrfs/mtab/mtab.go create mode 100644 vendor/github.com/dennwc/btrfs/receive.go create mode 100644 vendor/github.com/dennwc/btrfs/send.go create mode 100644 vendor/github.com/dennwc/btrfs/subvolume.go create mode 100644 vendor/github.com/dennwc/btrfs/usage.go create mode 100644 vendor/github.com/dennwc/btrfs/utils.go create mode 100644 vendor/github.com/dennwc/btrfs/uuid_tree.go create mode 100644 vendor/github.com/dennwc/btrfs/xattr.go create mode 100644 vendor/github.com/dennwc/ioctl/ioctl.go create mode 100644 vendor/github.com/go-kit/log/.gitignore create mode 100644 vendor/github.com/go-kit/log/LICENSE create mode 100644 vendor/github.com/go-kit/log/README.md create mode 100644 vendor/github.com/go-kit/log/doc.go create mode 100644 vendor/github.com/go-kit/log/json_logger.go rename vendor/github.com/go-kit/{kit => }/log/level/doc.go (65%) rename vendor/github.com/go-kit/{kit => }/log/level/level.go (82%) create mode 100644 vendor/github.com/go-kit/log/log.go create mode 100644 vendor/github.com/go-kit/log/logfmt_logger.go create mode 100644 vendor/github.com/go-kit/log/nop_logger.go create mode 100644 vendor/github.com/go-kit/log/staticcheck.conf create mode 100644 vendor/github.com/go-kit/log/stdlib.go create mode 100644 vendor/github.com/go-kit/log/sync.go create mode 100644 vendor/github.com/go-kit/log/value.go delete mode 100644 vendor/github.com/go-logfmt/logfmt/.travis.yml delete mode 100644 vendor/github.com/godbus/dbus/.travis.yml delete mode 100644 vendor/github.com/godbus/dbus/homedir.go delete mode 100644 vendor/github.com/godbus/dbus/homedir_dynamic.go delete mode 100644 vendor/github.com/godbus/dbus/homedir_static.go rename vendor/github.com/godbus/dbus/{ => v5}/CONTRIBUTING.md (100%) rename vendor/github.com/godbus/dbus/{ => v5}/LICENSE (100%) rename vendor/github.com/godbus/dbus/{ => v5}/MAINTAINERS (100%) rename vendor/github.com/godbus/dbus/{README.markdown => v5/README.md} (66%) rename vendor/github.com/godbus/dbus/{ => v5}/auth.go (91%) rename vendor/github.com/godbus/dbus/{ => v5}/auth_anonymous.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/auth_external.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/auth_sha1.go (96%) rename vendor/github.com/godbus/dbus/{ => v5}/call.go (69%) rename vendor/github.com/godbus/dbus/{ => v5}/conn.go (70%) rename vendor/github.com/godbus/dbus/{ => v5}/conn_darwin.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/conn_other.go (90%) rename vendor/github.com/godbus/dbus/{ => v5}/conn_unix.go (84%) rename vendor/github.com/godbus/dbus/{ => v5}/conn_windows.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/dbus.go (96%) rename vendor/github.com/godbus/dbus/{ => v5}/decoder.go (75%) rename vendor/github.com/godbus/dbus/{ => v5}/default_handler.go (76%) rename vendor/github.com/godbus/dbus/{ => v5}/doc.go (83%) rename vendor/github.com/godbus/dbus/{ => v5}/encoder.go (78%) create mode 100644 vendor/github.com/godbus/dbus/v5/escape.go rename vendor/github.com/godbus/dbus/{ => v5}/export.go (81%) create mode 100644 vendor/github.com/godbus/dbus/v5/homedir.go create mode 100644 vendor/github.com/godbus/dbus/v5/match.go rename vendor/github.com/godbus/dbus/{ => v5}/message.go (86%) rename vendor/github.com/godbus/dbus/{ => v5}/object.go (70%) create mode 100644 vendor/github.com/godbus/dbus/v5/sequence.go create mode 100644 vendor/github.com/godbus/dbus/v5/sequential_handler.go rename vendor/github.com/godbus/dbus/{ => v5}/server_interfaces.go (92%) rename vendor/github.com/godbus/dbus/{ => v5}/sig.go (75%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_darwin.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_generic.go (85%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_nonce_tcp.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_tcp.go (97%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_unix.go (88%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_unixcred_dragonfly.go (100%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_unixcred_freebsd.go (99%) rename vendor/github.com/godbus/dbus/{ => v5}/transport_unixcred_linux.go (100%) rename vendor/github.com/godbus/dbus/{transport_unixcred_openbsd.go => v5/transport_unixcred_netbsd.go} (100%) create mode 100644 vendor/github.com/godbus/dbus/v5/transport_unixcred_openbsd.go create mode 100644 vendor/github.com/godbus/dbus/v5/transport_zos.go rename vendor/github.com/godbus/dbus/{ => v5}/variant.go (89%) rename vendor/github.com/godbus/dbus/{ => v5}/variant_lexer.go (95%) rename vendor/github.com/godbus/dbus/{ => v5}/variant_parser.go (100%) delete mode 100644 vendor/github.com/golang/protobuf/AUTHORS delete mode 100644 vendor/github.com/golang/protobuf/CONTRIBUTORS delete mode 100644 vendor/github.com/golang/protobuf/proto/buffer.go delete mode 100644 vendor/github.com/golang/protobuf/proto/defaults.go delete mode 100644 vendor/github.com/golang/protobuf/proto/deprecated.go delete mode 100644 vendor/github.com/golang/protobuf/proto/discard.go delete mode 100644 vendor/github.com/golang/protobuf/proto/extensions.go delete mode 100644 vendor/github.com/golang/protobuf/proto/properties.go delete mode 100644 vendor/github.com/golang/protobuf/proto/proto.go delete mode 100644 vendor/github.com/golang/protobuf/proto/registry.go delete mode 100644 vendor/github.com/golang/protobuf/proto/text_decode.go delete mode 100644 vendor/github.com/golang/protobuf/proto/text_encode.go delete mode 100644 vendor/github.com/golang/protobuf/proto/wire.go delete mode 100644 vendor/github.com/golang/protobuf/proto/wrappers.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/any.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/any/any.pb.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/doc.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/duration.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/duration/duration.pb.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/timestamp.go delete mode 100644 vendor/github.com/golang/protobuf/ptypes/timestamp/timestamp.pb.go create mode 100644 vendor/github.com/golang/snappy/decode_arm64.s rename vendor/github.com/golang/snappy/{decode_amd64.go => decode_asm.go} (93%) create mode 100644 vendor/github.com/golang/snappy/encode_arm64.s rename vendor/github.com/golang/snappy/{encode_amd64.go => encode_asm.go} (97%) rename vendor/github.com/{alecthomas/template => google/go-cmp}/LICENSE (96%) create mode 100644 vendor/github.com/google/go-cmp/cmp/compare.go create mode 100644 vendor/github.com/google/go-cmp/cmp/export.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/diff/debug_disable.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/diff/debug_enable.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/flags/flags.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/function/func.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/value/name.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/value/pointer.go create mode 100644 vendor/github.com/google/go-cmp/cmp/internal/value/sort.go create mode 100644 vendor/github.com/google/go-cmp/cmp/options.go create mode 100644 vendor/github.com/google/go-cmp/cmp/path.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report_compare.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report_references.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report_reflect.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report_slices.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report_text.go create mode 100644 vendor/github.com/google/go-cmp/cmp/report_value.go create mode 100644 vendor/github.com/hashicorp/go-envparse/.gitignore create mode 100644 vendor/github.com/hashicorp/go-envparse/LICENSE create mode 100644 vendor/github.com/hashicorp/go-envparse/NOTICES.txt create mode 100644 vendor/github.com/hashicorp/go-envparse/README.md create mode 100644 vendor/github.com/hashicorp/go-envparse/envparse.go delete mode 100644 vendor/github.com/hodgesds/perf-utils/Gopkg.lock delete mode 100644 vendor/github.com/hodgesds/perf-utils/Gopkg.toml create mode 100644 vendor/github.com/hodgesds/perf-utils/msr.go create mode 100644 vendor/github.com/hodgesds/perf-utils/pmu.go rename vendor/github.com/{siebenmann => illumos}/go-kstat/.gitignore (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/LICENSE (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/Makefile (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/README (66%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/doc.go (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/kstat-godoc.txt (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/kstat_solaris.go (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/raw_solaris.go (100%) rename vendor/github.com/{siebenmann => illumos}/go-kstat/types_solaris_amd64.go (100%) create mode 100644 vendor/github.com/josharian/native/doc.go create mode 100644 vendor/github.com/josharian/native/endian_big.go create mode 100644 vendor/github.com/josharian/native/endian_generic.go create mode 100644 vendor/github.com/josharian/native/endian_little.go create mode 100644 vendor/github.com/josharian/native/license create mode 100644 vendor/github.com/josharian/native/readme.md create mode 100644 vendor/github.com/jsimonetti/rtnetlink/.gitignore create mode 100644 vendor/github.com/jsimonetti/rtnetlink/.golangci.yml create mode 100644 vendor/github.com/jsimonetti/rtnetlink/LICENSE.md create mode 100644 vendor/github.com/jsimonetti/rtnetlink/Makefile.fuzz create mode 100644 vendor/github.com/jsimonetti/rtnetlink/README.md create mode 100644 vendor/github.com/jsimonetti/rtnetlink/address.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/conn.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/doc.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/endian.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/fuzz-shell.nix create mode 100644 vendor/github.com/jsimonetti/rtnetlink/internal/unix/types_linux.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/internal/unix/types_other.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/link.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/neigh.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/route.go create mode 100644 vendor/github.com/jsimonetti/rtnetlink/rule.go delete mode 100644 vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE delete mode 100644 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/.gitignore delete mode 100644 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/Makefile delete mode 100644 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go delete mode 100644 vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go create mode 100644 vendor/github.com/mdlayher/ethtool/LICENSE.md create mode 100644 vendor/github.com/mdlayher/ethtool/README.md create mode 100644 vendor/github.com/mdlayher/ethtool/bitset_linux.go create mode 100644 vendor/github.com/mdlayher/ethtool/client.go create mode 100644 vendor/github.com/mdlayher/ethtool/client_linux.go create mode 100644 vendor/github.com/mdlayher/ethtool/client_others.go create mode 100644 vendor/github.com/mdlayher/ethtool/doc.go create mode 100644 vendor/github.com/mdlayher/ethtool/linkmodes_linux.go create mode 100644 vendor/github.com/mdlayher/ethtool/string.go delete mode 100644 vendor/github.com/mdlayher/netlink/fdcall_gteq_1.12.go delete mode 100644 vendor/github.com/mdlayher/netlink/fdcall_lt_1.12.go delete mode 100644 vendor/github.com/mdlayher/netlink/netlink.dot delete mode 100644 vendor/github.com/mdlayher/netlink/netlink.svg delete mode 100644 vendor/github.com/mdlayher/netlink/nlenc/endian.go delete mode 100644 vendor/github.com/mdlayher/netlink/rawconn_gteq_1.12.go delete mode 100644 vendor/github.com/mdlayher/netlink/rawconn_lt_1.12.go create mode 100644 vendor/github.com/mdlayher/socket/CHANGELOG.md create mode 100644 vendor/github.com/mdlayher/socket/LICENSE.md create mode 100644 vendor/github.com/mdlayher/socket/README.md create mode 100644 vendor/github.com/mdlayher/socket/accept.go create mode 100644 vendor/github.com/mdlayher/socket/accept4.go create mode 100644 vendor/github.com/mdlayher/socket/conn.go create mode 100644 vendor/github.com/mdlayher/socket/conn_linux.go create mode 100644 vendor/github.com/mdlayher/socket/doc.go rename vendor/github.com/mdlayher/{netlink => socket}/netns_linux.go (54%) create mode 100644 vendor/github.com/mdlayher/socket/netns_others.go create mode 100644 vendor/github.com/mdlayher/socket/setbuffer_linux.go create mode 100644 vendor/github.com/mdlayher/socket/setbuffer_others.go create mode 100644 vendor/github.com/mdlayher/socket/typ_cloexec_nonblock.go create mode 100644 vendor/github.com/mdlayher/socket/typ_none.go delete mode 100644 vendor/github.com/mdlayher/wifi/.travis.yml delete mode 100644 vendor/github.com/mdlayher/wifi/internal/nl80211/const.go delete mode 100644 vendor/github.com/mdlayher/wifi/internal/nl80211/doc.go delete mode 100644 vendor/github.com/mdlayher/wifi/internal/nl80211/nl80211.h delete mode 100644 vendor/github.com/mdlayher/wifi/internal/nl80211/nl80211.yml rename vendor/github.com/{matttproud/golang_protobuf_extensions => opencontainers/selinux}/LICENSE (100%) create mode 100644 vendor/github.com/opencontainers/selinux/go-selinux/doc.go create mode 100644 vendor/github.com/opencontainers/selinux/go-selinux/selinux.go create mode 100644 vendor/github.com/opencontainers/selinux/go-selinux/selinux_linux.go create mode 100644 vendor/github.com/opencontainers/selinux/go-selinux/selinux_stub.go create mode 100644 vendor/github.com/opencontainers/selinux/go-selinux/xattrs_linux.go create mode 100644 vendor/github.com/opencontainers/selinux/pkg/pwalkdir/README.md create mode 100644 vendor/github.com/opencontainers/selinux/pkg/pwalkdir/pwalkdir.go delete mode 100644 vendor/github.com/pkg/errors/.travis.yml delete mode 100644 vendor/github.com/pkg/errors/LICENSE delete mode 100644 vendor/github.com/pkg/errors/Makefile delete mode 100644 vendor/github.com/pkg/errors/README.md delete mode 100644 vendor/github.com/pkg/errors/appveyor.yml delete mode 100644 vendor/github.com/pkg/errors/errors.go delete mode 100644 vendor/github.com/pkg/errors/go113.go delete mode 100644 vendor/github.com/pkg/errors/stack.go rename vendor/github.com/{soundcloud => prometheus-community}/go-runit/LICENSE (100%) rename vendor/github.com/{soundcloud => prometheus-community}/go-runit/runit/runit.go (87%) create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/build_info_collector.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/get_pid.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/get_pid_gopherjs.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/go_collector_go116.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/go_collector_latest.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/internal/almost_equal.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/internal/difflib.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/internal/go_collector_options.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/internal/go_runtime_metrics.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/num_threads.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/num_threads_gopherjs.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/process_collector_js.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/process_collector_wasip1.go create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/vnext.go create mode 100644 vendor/github.com/prometheus/common/model/labelset_string.go create mode 100644 vendor/github.com/prometheus/common/model/labelset_string_go120.go create mode 100644 vendor/github.com/prometheus/common/model/metadata.go create mode 100644 vendor/github.com/prometheus/common/model/value_float.go create mode 100644 vendor/github.com/prometheus/common/model/value_histogram.go create mode 100644 vendor/github.com/prometheus/common/model/value_type.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/cgroups_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/cpu_netbsd.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/cpu_vulnerabilities_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/cpufreq_common.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/device_filter.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/diskstats_openbsd_amd64.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/dmi.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/drm_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/ethtool_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/fibrechannel_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/filesystem_openbsd.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/interrupts_openbsd_amd64.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/lnstat_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/meminfo_netbsd.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/meminfo_openbsd_amd64.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/netclass_rtnl_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/netdev_openbsd_amd64.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/netisr_freebsd.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/network_route_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/nvme_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/os_release.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/powersupplyclass_darwin.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/powersupplyclass_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/selinux_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/slabinfo_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/softirq_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/softirqs_common.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/sysctl_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/sysctl_openbsd_amd64.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/tapestats_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/thermal_darwin.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/time_linux.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/time_other.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/watchdog.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/xfrm.go create mode 100644 vendor/github.com/prometheus/node_exporter/collector/zoneinfo_linux.go create mode 100644 vendor/github.com/prometheus/procfs/blockdevice/stats.go create mode 100644 vendor/github.com/prometheus/procfs/cmdline.go rename vendor/github.com/{matttproud/golang_protobuf_extensions/pbutil/doc.go => prometheus/procfs/cpuinfo_loong64.go} (73%) delete mode 100644 vendor/github.com/prometheus/procfs/fixtures.ttar create mode 100644 vendor/github.com/prometheus/procfs/fs_statfs_notype.go create mode 100644 vendor/github.com/prometheus/procfs/fs_statfs_type.go create mode 100644 vendor/github.com/prometheus/procfs/net_route.go create mode 100644 vendor/github.com/prometheus/procfs/net_tls_stat.go create mode 100644 vendor/github.com/prometheus/procfs/net_wireless.go rename vendor/github.com/prometheus/procfs/{xfrm.go => net_xfrm.go} (94%) create mode 100644 vendor/github.com/prometheus/procfs/netstat.go create mode 100644 vendor/github.com/prometheus/procfs/proc_cgroups.go create mode 100644 vendor/github.com/prometheus/procfs/proc_interrupts.go create mode 100644 vendor/github.com/prometheus/procfs/proc_netstat.go create mode 100644 vendor/github.com/prometheus/procfs/proc_snmp.go create mode 100644 vendor/github.com/prometheus/procfs/proc_snmp6.go create mode 100644 vendor/github.com/prometheus/procfs/proc_sys.go create mode 100644 vendor/github.com/prometheus/procfs/softirqs.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_dmi.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_drm.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_drm_amdgpu.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_nvme.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_sas_device.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_sas_host.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_sas_phy.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_sas_port.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_scsitape.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/class_watchdog.go create mode 100644 vendor/github.com/prometheus/procfs/sysfs/mdraid.go create mode 100644 vendor/github.com/prometheus/procfs/thread.go rename vendor/github.com/{pkg/errors => safchain/ethtool}/.gitignore (83%) create mode 100644 vendor/github.com/safchain/ethtool/.golangci.yml create mode 100644 vendor/github.com/safchain/ethtool/LICENSE create mode 100644 vendor/github.com/safchain/ethtool/Makefile create mode 100644 vendor/github.com/safchain/ethtool/README.md create mode 100644 vendor/github.com/safchain/ethtool/ethtool.go create mode 100644 vendor/github.com/safchain/ethtool/ethtool_cmd.go create mode 100644 vendor/github.com/safchain/ethtool/ethtool_msglvl.go create mode 100644 vendor/github.com/xhit/go-str2duration/v2/LICENSE create mode 100644 vendor/github.com/xhit/go-str2duration/v2/README.md create mode 100644 vendor/github.com/xhit/go-str2duration/v2/str2duration.go delete mode 100644 vendor/go.uber.org/atomic/.travis.yml delete mode 100644 vendor/go.uber.org/atomic/atomic.go create mode 100644 vendor/go.uber.org/atomic/bool.go rename vendor/go.uber.org/{multierr/go113.go => atomic/bool_ext.go} (58%) create mode 100644 vendor/go.uber.org/atomic/doc.go create mode 100644 vendor/go.uber.org/atomic/duration.go create mode 100644 vendor/go.uber.org/atomic/duration_ext.go create mode 100644 vendor/go.uber.org/atomic/error_ext.go create mode 100644 vendor/go.uber.org/atomic/float64.go create mode 100644 vendor/go.uber.org/atomic/float64_ext.go create mode 100644 vendor/go.uber.org/atomic/gen.go create mode 100644 vendor/go.uber.org/atomic/int32.go create mode 100644 vendor/go.uber.org/atomic/int64.go create mode 100644 vendor/go.uber.org/atomic/nocmp.go create mode 100644 vendor/go.uber.org/atomic/string_ext.go create mode 100644 vendor/go.uber.org/atomic/time.go create mode 100644 vendor/go.uber.org/atomic/time_ext.go create mode 100644 vendor/go.uber.org/atomic/uint32.go create mode 100644 vendor/go.uber.org/atomic/uint64.go create mode 100644 vendor/go.uber.org/atomic/uintptr.go create mode 100644 vendor/go.uber.org/atomic/unsafe_pointer.go create mode 100644 vendor/go.uber.org/atomic/value.go delete mode 100644 vendor/go.uber.org/multierr/.travis.yml rename vendor/{github.com/golang/protobuf => golang.org/x/crypto}/LICENSE (83%) create mode 100644 vendor/golang.org/x/crypto/PATENTS create mode 100644 vendor/golang.org/x/crypto/pbkdf2/pbkdf2.go create mode 100644 vendor/golang.org/x/exp/LICENSE create mode 100644 vendor/golang.org/x/exp/PATENTS create mode 100644 vendor/golang.org/x/exp/maps/maps.go delete mode 100644 vendor/golang.org/x/sync/AUTHORS delete mode 100644 vendor/golang.org/x/sync/CONTRIBUTORS create mode 100644 vendor/golang.org/x/sync/errgroup/go120.go create mode 100644 vendor/golang.org/x/sync/errgroup/pre_go120.go delete mode 100644 vendor/golang.org/x/sys/internal/unsafeheader/unsafeheader.go create mode 100644 vendor/golang.org/x/sys/unix/ioctl_signed.go rename vendor/golang.org/x/sys/unix/{ioctl.go => ioctl_unsigned.go} (76%) create mode 100644 vendor/golang.org/x/sys/unix/mmap_nomremap.go create mode 100644 vendor/golang.org/x/sys/unix/mremap.go delete mode 100644 vendor/google.golang.org/protobuf/AUTHORS delete mode 100644 vendor/google.golang.org/protobuf/CONTRIBUTORS create mode 100644 vendor/google.golang.org/protobuf/encoding/protodelim/protodelim.go create mode 100644 vendor/google.golang.org/protobuf/internal/editiondefaults/defaults.go create mode 100644 vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb create mode 100644 vendor/google.golang.org/protobuf/internal/filedesc/editions.go create mode 100644 vendor/google.golang.org/protobuf/internal/genid/go_features_gen.go rename vendor/google.golang.org/protobuf/internal/strs/{strings_unsafe.go => strings_unsafe_go120.go} (87%) create mode 100644 vendor/google.golang.org/protobuf/internal/strs/strings_unsafe_go121.go create mode 100644 vendor/google.golang.org/protobuf/reflect/protoreflect/value_equal.go rename vendor/google.golang.org/protobuf/reflect/protoreflect/{value_unsafe.go => value_unsafe_go120.go} (97%) create mode 100644 vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go121.go delete mode 100644 vendor/google.golang.org/protobuf/types/known/anypb/any.pb.go delete mode 100644 vendor/google.golang.org/protobuf/types/known/durationpb/duration.pb.go delete mode 100644 vendor/gopkg.in/alecthomas/kingpin.v2/.travis.yml delete mode 100644 vendor/gopkg.in/alecthomas/kingpin.v2/templates.go create mode 100644 vendor/howett.net/plist/.gitignore create mode 100644 vendor/howett.net/plist/.gitlab-ci.yml create mode 100644 vendor/howett.net/plist/LICENSE create mode 100644 vendor/howett.net/plist/README.md create mode 100644 vendor/howett.net/plist/bplist.go create mode 100644 vendor/howett.net/plist/bplist_generator.go create mode 100644 vendor/howett.net/plist/bplist_parser.go create mode 100644 vendor/howett.net/plist/decode.go create mode 100644 vendor/howett.net/plist/doc.go create mode 100644 vendor/howett.net/plist/encode.go create mode 100644 vendor/howett.net/plist/fuzz.go create mode 100644 vendor/howett.net/plist/marshal.go create mode 100644 vendor/howett.net/plist/must.go create mode 100644 vendor/howett.net/plist/plist.go create mode 100644 vendor/howett.net/plist/plist_types.go create mode 100644 vendor/howett.net/plist/text_generator.go create mode 100644 vendor/howett.net/plist/text_parser.go create mode 100644 vendor/howett.net/plist/text_tables.go create mode 100644 vendor/howett.net/plist/typeinfo.go create mode 100644 vendor/howett.net/plist/unmarshal.go create mode 100644 vendor/howett.net/plist/util.go create mode 100644 vendor/howett.net/plist/xml_generator.go create mode 100644 vendor/howett.net/plist/xml_parser.go create mode 100644 vendor/howett.net/plist/zerocopy.go create mode 100644 vendor/howett.net/plist/zerocopy_appengine.go diff --git a/.golangci.yml b/.golangci.yml index 4a754ade..2405bb87 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,7 +1,3 @@ -run: - skip-files: - - ".*_test.go" - linters: disable-all: true enable: @@ -18,10 +14,12 @@ linters: - unconvert - unparam - unused - - vet + - govet - gosec issues: exclude: - G404 - G114 + exclude-files: + - ".*_test.go" diff --git a/Dockerfile b/Dockerfile index 0d893541..e52ec33c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18 as build +FROM golang:1.22 as build ENV DOCKER_BUILD=1 ADD . /home/do-agent WORKDIR /home/do-agent diff --git a/Makefile b/Makefile index b70f9d52..6ba40638 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,7 @@ linter = \ -e "GO111MODULE=on" \ -e "GOFLAGS=-mod=vendor" \ -v "$(CURDIR):$(docker_dir)" \ - golangci/golangci-lint:v1.50.1 + golangci/golangci-lint:v1.58.2 ############# ## targets ## @@ -83,7 +83,7 @@ test: build: $(binary) $(binary): $(gofiles) $(vendorgofiles) $(print) - $(go) build -ldflags $(ldflags) -o "$(docker_dir)/$@" ./cmd/$(project) + $(go) build -buildvcs=false -ldflags $(ldflags) -o "$(docker_dir)/$@" ./cmd/$(project) shell: $(print) diff --git a/cmd/do-agent/config.go b/cmd/do-agent/config.go index b8fb2bad..4da83090 100644 --- a/cmd/do-agent/config.go +++ b/cmd/do-agent/config.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "hash/fnv" "net/url" @@ -8,11 +9,10 @@ import ( "strings" "time" - "github.com/pkg/errors" + "github.com/alecthomas/kingpin/v2" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/model" - "gopkg.in/alecthomas/kingpin.v2" "github.com/digitalocean/do-agent/internal/flags" "github.com/digitalocean/do-agent/internal/log" @@ -161,7 +161,7 @@ func checkConfig() error { var err error for name, uri := range config.targets { if _, err = url.Parse(uri); err != nil { - return errors.Wrapf(err, "url for target %q is not valid", name) + return fmt.Errorf("url for target %q is not valid: %w", name, err) } } diff --git a/cmd/do-agent/config_linux.go b/cmd/do-agent/config_linux.go index 88117b7c..c5584b8f 100644 --- a/cmd/do-agent/config_linux.go +++ b/cmd/do-agent/config_linux.go @@ -1,6 +1,6 @@ package main -import "gopkg.in/alecthomas/kingpin.v2" +import "github.com/alecthomas/kingpin/v2" func init() { // Overwrite the default disk ignore list, add dm- to ignore LVM devices diff --git a/cmd/do-agent/run.go b/cmd/do-agent/run.go index 876f2b75..564893c1 100644 --- a/cmd/do-agent/run.go +++ b/cmd/do-agent/run.go @@ -4,7 +4,6 @@ import ( "fmt" "time" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" @@ -99,7 +98,7 @@ func run(w metricWriter, l limiter, dec decorate.Decorator, g gatherer, aggregat // writeDiagnostics filters all metrics and gathers only the diagnostic information and sends the metrics // in the event of a write failure func writeDiagnostics(w metricWriter, mfs []*dto.MetricFamily, err error) { - diagnosticMetric.WithLabelValues(errors.Cause(err).Error()).Inc() + diagnosticMetric.WithLabelValues(err.Error()).Inc() var diags []*dto.MetricFamily for _, mf := range mfs { diff --git a/cmd/do-agent/version.go b/cmd/do-agent/version.go index fa4badfb..ab6829aa 100644 --- a/cmd/do-agent/version.go +++ b/cmd/do-agent/version.go @@ -9,8 +9,8 @@ import ( "github.com/digitalocean/do-agent/internal/log" + "github.com/alecthomas/kingpin/v2" "github.com/prometheus/client_golang/prometheus" - kingpin "gopkg.in/alecthomas/kingpin.v2" ) var ( @@ -51,7 +51,7 @@ func init() { buildInfo.Set(1) kingpin.VersionFlag = kingpin.Flag("version", "Show the application version information"). Short('v'). - PreAction(func(c *kingpin.ParseContext) error { + PreAction(func(_ *kingpin.ParseContext) error { err := versionTmpl.Execute(os.Stdout, map[string]string{ "name": "do-agent", "version": version, diff --git a/go.mod b/go.mod index 7f11ae3f..8ee6e851 100644 --- a/go.mod +++ b/go.mod @@ -1,49 +1,61 @@ module github.com/digitalocean/do-agent -go 1.18 +go 1.22 require ( - github.com/go-kit/kit v0.10.0 - github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db - github.com/pkg/errors v0.9.1 - github.com/prometheus/client_golang v1.11.1 - github.com/prometheus/client_model v0.2.0 - github.com/prometheus/common v0.26.0 - github.com/prometheus/node_exporter v1.0.1 - github.com/prometheus/procfs v0.6.0 + github.com/alecthomas/kingpin/v2 v2.4.0 + github.com/go-kit/kit v0.13.0 + github.com/golang/snappy v0.0.4 + github.com/prometheus/client_golang v1.19.0 + github.com/prometheus/client_model v0.6.1 + github.com/prometheus/common v0.53.0 + github.com/prometheus/node_exporter v1.8.1 + github.com/prometheus/procfs v0.14.0 github.com/stretchr/testify v1.9.0 - gopkg.in/alecthomas/kingpin.v2 v2.2.6 ) require ( - github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect - github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect - github.com/beevik/ntp v0.3.0 // indirect + github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect + github.com/beevik/ntp v1.3.1 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.1.1 // indirect - github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/coreos/go-systemd/v22 v22.5.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 // indirect - github.com/go-logfmt/logfmt v0.5.0 // indirect - github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 // indirect - github.com/golang/protobuf v1.4.3 // indirect - github.com/hodgesds/perf-utils v0.0.8 // indirect - github.com/lufia/iostat v1.1.0 // indirect + github.com/dennwc/btrfs v0.0.0-20240418142341-0167142bde7a // indirect + github.com/dennwc/ioctl v1.0.0 // indirect + github.com/ema/qdisc v1.0.0 // indirect + github.com/go-kit/log v0.2.1 // indirect + github.com/go-logfmt/logfmt v0.5.1 // indirect + github.com/godbus/dbus/v5 v5.1.0 // indirect + github.com/google/go-cmp v0.6.0 // indirect + github.com/hashicorp/go-envparse v0.1.0 // indirect + github.com/hodgesds/perf-utils v0.7.0 // indirect + github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973 // indirect + github.com/josharian/native v1.1.0 // indirect + github.com/jsimonetti/rtnetlink v1.4.1 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/lufia/iostat v1.2.1 // indirect github.com/mattn/go-xmlrpc v0.0.3 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/mdlayher/genetlink v1.0.0 // indirect - github.com/mdlayher/netlink v1.1.0 // indirect - github.com/mdlayher/wifi v0.0.0-20190303161829-b1436901ddee // indirect + github.com/mdlayher/ethtool v0.1.0 // indirect + github.com/mdlayher/genetlink v1.3.2 // indirect + github.com/mdlayher/netlink v1.7.2 // indirect + github.com/mdlayher/socket v0.4.1 // indirect + github.com/mdlayher/wifi v0.1.0 // indirect + github.com/opencontainers/selinux v1.11.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/siebenmann/go-kstat v0.0.0-20200303194639-4e8294f9e9d5 // indirect - github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a // indirect - go.uber.org/atomic v1.6.0 // indirect - go.uber.org/multierr v1.5.0 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect - golang.org/x/sys v0.5.0 // indirect - google.golang.org/protobuf v1.26.0-rc.1 // indirect + github.com/prometheus-community/go-runit v0.1.0 // indirect + github.com/safchain/ethtool v0.3.0 // indirect + github.com/xhit/go-str2duration/v2 v2.1.0 // indirect + go.uber.org/atomic v1.9.0 // indirect + go.uber.org/multierr v1.7.0 // indirect + golang.org/x/crypto v0.21.0 // indirect + golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f // indirect + golang.org/x/net v0.23.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.19.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + howett.net/plist v1.0.1 // indirect ) replace github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 diff --git a/go.sum b/go.sum index 1c36ff87..216e6352 100644 --- a/go.sum +++ b/go.sum @@ -1,506 +1,127 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= -github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= -github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= -github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= -github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= -github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= -github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6lCRdSC2Tm3DSWRPvIPr6xNKyeHdqDQSQT+A= -github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU= -github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= -github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= -github.com/beevik/ntp v0.3.0 h1:xzVrPrE4ziasFXgBVBZJDP0Wg/KpMwk2KHJ4Ba8GrDw= -github.com/beevik/ntp v0.3.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY= +github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE= +github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= +github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= +github.com/beevik/ntp v1.3.1 h1:Y/srlT8L1yQr58kyPWFPZIxRL8ttx2SRIpVYJqZIlAM= +github.com/beevik/ntp v1.3.1/go.mod h1:fT6PylBq86Tsq23ZMEe47b7QQrZfYBFPnpzt0a9kJxw= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8= -github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= -github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU= -github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= -github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cilium/ebpf v0.12.3 h1:8ht6F9MquybnY97at+VDZb3eQQr8ev79RueWeVaEcG4= +github.com/cilium/ebpf v0.12.3/go.mod h1:TctK1ivibvI3znr66ljgi4hqOT8EYQjz1KWBfb1UVgM= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= -github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= -github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= -github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= -github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043 h1:I3hLsM87FSASssIrIOGwJCio31dvLkvpYDKn2+r31ec= -github.com/ema/qdisc v0.0.0-20190904071900-b82c76788043/go.mod h1:ix4kG2zvdUd8kEKSW0ZTr1XLks0epFpI4j745DXxlNE= -github.com/envoyproxy/go-control-plane v0.6.9/go.mod h1:SBwIajubJHhxtWwsL9s8ss4safvEdbitLhGGK48rN6g= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4= -github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.10.0 h1:dXFJfIHVvUcpSgDOV+Ne6t7jXri8Tfv2uOLHUZ2XNuo= -github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgOZ7o= -github.com/go-kit/log v0.1.0 h1:DGJh0Sm43HbOeYDNnVZFl8BvcYVvjD5bqYJvp0REbwQ= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0 h1:TrB8swr/68K7m9CcGut2g3UOihhbcbiMAYiuTXdEih4= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968 h1:s+PDl6lozQ+dEUtUtQnO7+A2iPG3sK1pI4liU+jxn90= -github.com/godbus/dbus v0.0.0-20190402143921-271e53dc4968/go.mod h1:/YcGZj5zSblfDWMMoOzV4fas9FZnQYTkDnsGvmh2Grw= -github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s= -github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= -github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= -github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= -github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= -github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= -github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w= -github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= -github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= -github.com/gorilla/websocket v0.0.0-20170926233335-4201258b820c/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= -github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de4/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= -github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= -github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= -github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= -github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= -github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= -github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= -github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= -github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= -github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= -github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= -github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hodgesds/perf-utils v0.0.8 h1:6BT6cddpouM0G7eHhLFS+XcqtPvhrzWbPreyIvgFEcg= -github.com/hodgesds/perf-utils v0.0.8/go.mod h1:F6TfvsbtrF88i++hou29dTXlI2sfsJv+gRZDtmTJkAs= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= -github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= -github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= -github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= -github.com/jsimonetti/rtnetlink v0.0.0-20190830100107-3784a6c7c552/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= -github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4 h1:nwOc1YaOrYJ37sEBrtWZrdqzK22hiJs3GpDmP3sR2Yw= -github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4/go.mod h1:WGuG/smIU4J/54PblvSbh+xvCZmpJnFgr3ds6Z55XMQ= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-bc2310a04743/go.mod h1:qklhhLq1aX+mtWk9cPHPzaBjWImj5ULL6C7HFJtXQMM= -github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4= -github.com/lufia/iostat v1.1.0 h1:Z1wa4Hhxwi8uSKfgRsFc5RLtt3SuFPIOgkiPGkUtHDY= -github.com/lufia/iostat v1.1.0/go.mod h1:rEPNA0xXgjHQjuI5Cy05sLlS2oRcSlWHRLrvh/AQ+Pg= -github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ= -github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= -github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= -github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= +github.com/dennwc/btrfs v0.0.0-20240418142341-0167142bde7a h1:KfFsGLJFVdCXlySUkV2FmxNtmiztpJb6tV+XYBmmv8E= +github.com/dennwc/btrfs v0.0.0-20240418142341-0167142bde7a/go.mod h1:MYsOV9Dgsec3FFSOjywi0QK5r6TeBbdWxdrMGtiYXHA= +github.com/dennwc/ioctl v1.0.0 h1:DsWAAjIxRqNcLn9x6mwfuf2pet3iB7aK90K4tF16rLg= +github.com/dennwc/ioctl v1.0.0/go.mod h1:ellh2YB5ldny99SBU/VX7Nq0xiZbHphf1DrtHxxjMk0= +github.com/ema/qdisc v1.0.0 h1:EHLG08FVRbWLg8uRICa3xzC9Zm0m7HyMHfXobWFnXYg= +github.com/ema/qdisc v1.0.0/go.mod h1:FhIc0fLYi7f+lK5maMsesDqwYojIOh3VfRs8EVd5YJQ= +github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU= +github.com/go-kit/kit v0.13.0/go.mod h1:phqEHMMUbyrCFCTgH48JueqrM3md2HcAZ8N3XE4FKDg= +github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= +github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= +github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hashicorp/go-envparse v0.1.0 h1:bE++6bhIsNCPLvgDZkYqo3nA+/PFI51pkrHdmPSDFPY= +github.com/hashicorp/go-envparse v0.1.0/go.mod h1:OHheN1GoygLlAkTlXLXvAdnXdZxy8JUweQ1rAXx1xnc= +github.com/hodgesds/perf-utils v0.7.0 h1:7KlHGMuig4FRH5fNw68PV6xLmgTe7jKs9hgAcEAbioU= +github.com/hodgesds/perf-utils v0.7.0/go.mod h1:LAklqfDadNKpkxoAJNHpD5tkY0rkZEVdnCEWN5k4QJY= +github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973 h1:hk4LPqXIY/c9XzRbe7dA6qQxaT6Axcbny0L/G5a4owQ= +github.com/illumos/go-kstat v0.0.0-20210513183136-173c9b0a9973/go.mod h1:PoK3ejP3LJkGTzKqRlpvCIFas3ncU02v8zzWDW+g0FY= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= +github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= +github.com/jsimonetti/rtnetlink v1.4.1 h1:JfD4jthWBqZMEffc5RjgmlzpYttAVw1sdnmiNaPO3hE= +github.com/jsimonetti/rtnetlink v1.4.1/go.mod h1:xJjT7t59UIZ62GLZbv6PLLo8VFrostJMPBAheR6OM8w= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lufia/iostat v1.2.1 h1:tnCdZBIglgxD47RyD55kfWQcJMGzO+1QBziSQfesf2k= +github.com/lufia/iostat v1.2.1/go.mod h1:rEPNA0xXgjHQjuI5Cy05sLlS2oRcSlWHRLrvh/AQ+Pg= github.com/mattn/go-xmlrpc v0.0.3 h1:Y6WEMLEsqs3RviBrAa1/7qmbGB7DVD3brZIbqMbQdGY= github.com/mattn/go-xmlrpc v0.0.3/go.mod h1:mqc2dz7tP5x5BKlCahN/n+hs7OSZKJkS9JsHNBRlrxA= -github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/mdlayher/genetlink v1.0.0 h1:OoHN1OdyEIkScEmRgxLEe2M9U8ClMytqA5niynLtfj0= -github.com/mdlayher/genetlink v1.0.0/go.mod h1:0rJ0h4itni50A86M2kHcgS85ttZazNt7a8H2a2cw0Gc= -github.com/mdlayher/netlink v0.0.0-20190409211403-11939a169225/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA= -github.com/mdlayher/netlink v0.0.0-20190828143259-340058475d09/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M= -github.com/mdlayher/netlink v1.0.0/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M= -github.com/mdlayher/netlink v1.1.0 h1:mpdLgm+brq10nI9zM1BpX1kpDbh3NLl3RSnVq6ZSkfg= -github.com/mdlayher/netlink v1.1.0/go.mod h1:H4WCitaheIsdF9yOYu8CFmCgQthAPIWZmcKp9uZHgmY= -github.com/mdlayher/wifi v0.0.0-20190303161829-b1436901ddee h1:hZDujBrW3ye2xxdKNFYT59D4yCH5Q0zLuNBNtysKtok= -github.com/mdlayher/wifi v0.0.0-20190303161829-b1436901ddee/go.mod h1:Evt/EIne46u9PtQbeTx2NTcqURpr5K4SvKtGmBuDPN8= -github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= -github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= -github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= -github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= -github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= -github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/nats-io/jwt v0.3.0/go.mod h1:fRYCDE99xlTsqUzISS1Bi75UBJ6ljOJQOAAu5VglpSg= -github.com/nats-io/jwt v0.3.2/go.mod h1:/euKqTS1ZD+zzjYrY7pseZrTtWQSjujC7xjPc8wL6eU= -github.com/nats-io/nats-server/v2 v2.1.2/go.mod h1:Afk+wRZqkMQs/p45uXdrVLuab3gwv3Z8C4HTBu8GD/k= -github.com/nats-io/nats.go v1.9.1/go.mod h1:ZjDU1L/7fJ09jvUSRVBR2e7+RnLiiIQyqyzEE/Zbp4w= -github.com/nats-io/nkeys v0.1.0/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nkeys v0.1.3/go.mod h1:xpnFELMwJABBLVhffcfd1MZx6VsNRFpEugbxziKVo7w= -github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c= -github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= -github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= -github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= -github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= -github.com/opentracing/opentracing-go v1.0.2/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= -github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= -github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/openzipkin/zipkin-go v0.2.2/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= -github.com/pact-foundation/pact-go v1.0.4/go.mod h1:uExwJY4kCzNPcHRj+hCR/HBbOOIwwtUjcrb0b5/5kLM= -github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= -github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= -github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= -github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= -github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= +github.com/mdlayher/ethtool v0.1.0 h1:XAWHsmKhyPOo42qq/yTPb0eFBGUKKTR1rE0dVrWVQ0Y= +github.com/mdlayher/ethtool v0.1.0/go.mod h1:fBMLn2UhfRGtcH5ZFjr+6GUiHEjZsItFD7fSn7jbZVQ= +github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw= +github.com/mdlayher/genetlink v1.3.2/go.mod h1:tcC3pkCrPUGIKKsCsp0B3AdaaKuHtaxoJRz3cc+528o= +github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g= +github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= +github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= +github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= +github.com/mdlayher/wifi v0.1.0 h1:y8wYRUXwok5CtUZOXT3egghYesX0O79E3ALl+SIDm9Q= +github.com/mdlayher/wifi v0.1.0/go.mod h1:+gBYnZAMcUKHSFzMJXwlz7tLsEHgwDJ9DJCefhJM+gI= +github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU= +github.com/opencontainers/selinux v1.11.0/go.mod h1:E5dMC3VPuVvVHDYmi78qvhJp8+M586T4DlDRYpFkyec= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= -github.com/prometheus/client_golang v1.6.0/go.mod h1:ZLOG9ck3JLRdB5MgO8f+lLTe83AXG6ro35rLTxvnIl4= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.11.1 h1:+4eQaD7vAZ6DsfsxB15hbE0odUjGI5ARs9yskGu1v4s= -github.com/prometheus/client_golang v1.11.1/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA= -github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.26.0 h1:iMAkS2TDoNWnKM+Kopnx/8tnEStIfpYA0ur0xQzzhMQ= -github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/node_exporter v1.0.1 h1:xTBtauxuNCMhuF4FKiNo2wDCuCAWgS3PoTlVbXLzNO0= -github.com/prometheus/node_exporter v1.0.1/go.mod h1:IC23eAmBHxDOtCRUgP9uqJewluDPwjStnbvWJEYtisQ= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= -github.com/prometheus/procfs v0.0.11/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0 h1:mxy4L2jP6qMonqmq+aTtOx1ifVWUgG/TAmntgbh3xv4= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= -github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= -github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= -github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= -github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= -github.com/siebenmann/go-kstat v0.0.0-20200303194639-4e8294f9e9d5 h1:rRF7gJ7t0E1bfqNLwMqgb59eb273kgi+GgLE/yEiDzs= -github.com/siebenmann/go-kstat v0.0.0-20200303194639-4e8294f9e9d5/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= -github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= -github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY= -github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a h1:os5OBNhwOwybXZMNLqT96XqtjdTtwRFw2w08uluvNeI= -github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a/go.mod h1:LeFCbQYJ3KJlPs/FvPz2dy1tkpxyeNESVyCNNzRXFR0= -github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= -github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= -github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= -github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= -github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI= +github.com/prometheus-community/go-runit v0.1.0 h1:uTWEj/Fn2RoLdfg/etSqwzgYNOYPrARx1BHUN052tGA= +github.com/prometheus-community/go-runit v0.1.0/go.mod h1:AvJ9Jo3gAFu2lbM4+qfjdpq30FfiLDJZKbQ015u08IQ= +github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= +github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+aLCE= +github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U= +github.com/prometheus/node_exporter v1.8.1 h1:qYIN+ghn7kEggHe4pcIRp9oXkljU8ARWyEHBr286RPY= +github.com/prometheus/node_exporter v1.8.1/go.mod h1:rJMoAQMglUjAZ7nggHnRuwfJ0hKUVW6+Gv+IaMxh6js= +github.com/prometheus/procfs v0.14.0 h1:Lw4VdGGoKEZilJsayHf0B+9YgLGREba2C6xr+Fdfq6s= +github.com/prometheus/procfs v0.14.0/go.mod h1:XL+Iwz8k8ZabyZfMFHPiilCniixqQarAy5Mu67pHlNQ= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= +github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= +github.com/safchain/ethtool v0.3.0 h1:gimQJpsI6sc1yIqP/y8GYgiXn/NjgvpM0RNoWLVVmP0= +github.com/safchain/ethtool v0.3.0/go.mod h1:SA9BwrgyAqNo7M+uaL6IYbxpm5wk3L7Mm6ocLW+CJUs= +github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 h1:GfSdC6wKfTGcgCS7BtzF5694Amne1pGCSTY252WhlEY= +github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= -github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= -github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= -github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= -go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= -go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= -go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk= -go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= -go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4= -go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A= -go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4= -go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= -go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= -go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190902133755-9109b7679e13/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191220142924-d4481acd189f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200513201620-d5fe73897c97/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ= -golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/api v0.3.1/go.mod h1:6wY9I6uQWHQ8EM57III9mq/AjF+i8G65rmVagqKMtkk= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190530194941-fb225487d101/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.0/go.mod h1:chYK+tFQF0nDUGJgXMSgLCQk3phJEuONr2DCgLDdAQM= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.22.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= -google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= -google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= -google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= -google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= +github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= +go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.7.0 h1:zaiO/rmgFjbmCXdSYJWQcdvOCsthmdaHfr3Gm2Kx4Ec= +go.uber.org/multierr v1.7.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f h1:99ci1mjWVBWwJiEKYY6jWa4d2nTQVIEhZIptnrVb1XY= +golang.org/x/exp v0.0.0-20240416160154-fe59bbe5cc7f/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= +golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20211031064116-611d5d643895/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o= -gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= -gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3 h1:sXmLre5bzIR6ypkjXCDI3jHPssRhc8KD/Ome589sc3U= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= -sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= +howett.net/plist v1.0.1 h1:37GdZ8tP09Q35o9ych3ehygcsL+HqKSwzctveSlarvM= +howett.net/plist v1.0.1/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= diff --git a/internal/flags/flags.go b/internal/flags/flags.go index 9ebfad28..b7b15729 100644 --- a/internal/flags/flags.go +++ b/internal/flags/flags.go @@ -4,8 +4,8 @@ package flags import ( + "github.com/alecthomas/kingpin/v2" "github.com/prometheus/procfs" - kingpin "gopkg.in/alecthomas/kingpin.v2" ) var ( diff --git a/internal/process/collector.go b/internal/process/collector.go index 070f6506..55bf6875 100644 --- a/internal/process/collector.go +++ b/internal/process/collector.go @@ -35,7 +35,7 @@ func NewProcessCollector() prometheus.Collector { c.collectFn = c.processCollect } else { // nop - c.collectFn = func(ch chan<- prometheus.Metric) {} + c.collectFn = func(_ chan<- prometheus.Metric) {} } return c diff --git a/pkg/aggregate/aggregate.go b/pkg/aggregate/aggregate.go index 4c93ac67..9e914d3f 100644 --- a/pkg/aggregate/aggregate.go +++ b/pkg/aggregate/aggregate.go @@ -1,7 +1,6 @@ package aggregate import ( - "github.com/pkg/errors" dto "github.com/prometheus/client_model/go" "github.com/digitalocean/do-agent/pkg/clients/tsclient" @@ -44,11 +43,11 @@ func Aggregate(metrics []*dto.MetricFamily, aggregateSpec map[string][]string) ( def := tsclient.NewDefinition(*mf.Name, tsclient.WithCommonLabels(labels)) lfm, err := tsclient.GetLFM(def, tslbls) if err != nil { - return nil, errors.WithStack(err) + return nil, err } lfmDelim, err := tsclient.ParseMetricDelimited(lfm) if err != nil { - return nil, errors.WithStack(err) + return nil, err } labelsToRemove, ok := aggregateSpec[mf.GetName()] if ok { diff --git a/pkg/clients/tsclient/client.go b/pkg/clients/tsclient/client.go index 83131dcb..a9655821 100644 --- a/pkg/clients/tsclient/client.go +++ b/pkg/clients/tsclient/client.go @@ -25,7 +25,6 @@ import ( "time" "github.com/golang/snappy" - "github.com/pkg/errors" "github.com/digitalocean/do-agent/internal/log" "github.com/digitalocean/do-agent/pkg/clients/tsclient/structuredstream" @@ -340,13 +339,13 @@ func (c *HTTPClient) addMetricWithMSEpochTime(def *Definition, ms int64, value f } lfm, err := GetLFM(def, labels) if err != nil { - return errors.Wrap(err, "failed to get LFM") + return fmt.Errorf("failed to get LFM: %w", err) } if !isZeroTime { // ensure sufficient time between reported metric values if lastSend, ok := c.lastSend[lfm]; ok && (time.Duration(ms-lastSend)*time.Millisecond) < c.WaitDuration() { - return errors.WithStack(ErrSendTooFrequent) + return ErrSendTooFrequent } c.lastSend[lfm] = ms } @@ -357,7 +356,7 @@ func (c *HTTPClient) addMetricWithMSEpochTime(def *Definition, ms int64, value f writer.Write(value) if err := writer.Error(); err != nil { log.Error("failed to write: %+v", err) - return errors.WithStack(ErrWriteFailure) + return ErrWriteFailure } return nil } diff --git a/pkg/collector/node.go b/pkg/collector/node.go index cd97ed5c..afd86891 100644 --- a/pkg/collector/node.go +++ b/pkg/collector/node.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/digitalocean/do-agent/internal/log" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/prometheus/node_exporter/collector" @@ -49,7 +48,7 @@ var metricWhitelist = []string{ func NewNodeCollector() (*NodeCollector, error) { c, err := collector.NewNodeCollector(log.GetCollectorLogger()) if err != nil { - return nil, errors.Wrap(err, "failed to create NodeCollector") + return nil, fmt.Errorf("failed to create NodeCollector: %w", err) } return &NodeCollector{ diff --git a/pkg/collector/scraper.go b/pkg/collector/scraper.go index 07ae9a5b..4fc864e5 100644 --- a/pkg/collector/scraper.go +++ b/pkg/collector/scraper.go @@ -13,7 +13,6 @@ import ( "github.com/digitalocean/do-agent/internal/log" "github.com/digitalocean/do-agent/pkg/clients" "github.com/digitalocean/do-agent/pkg/clients/roundtrippers" - "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" @@ -82,7 +81,7 @@ func NewScraper(name, metricsEndpoint string, extraMetricLabels []*dto.LabelPair metricsEndpoint = strings.TrimRight(metricsEndpoint, "/") req, err := http.NewRequest("GET", metricsEndpoint, nil) if err != nil { - return nil, errors.Wrap(err, "failed to create http request") + return nil, fmt.Errorf("failed to create http request: %w", err) } req.Header.Add("Accept", `text/plain;version=0.0.4;q=1,*/*;q=0.1`) req.Header.Add("Accept-Encoding", "gzip") @@ -149,17 +148,17 @@ func (s *Scraper) readStream(ctx context.Context) (r io.ReadCloser, outerr error if err := r.Close(); err != nil { // This should not happen, but if it does it'll be nice // to know why we have a bunch of unclosed messages - s.log("failed to close stream on error: %+v", errors.WithStack(err)) + s.log("failed to close stream on error: %s", err) } }() resp, err := s.client.Do(s.req.WithContext(ctx)) if err != nil { - return nil, errors.Wrap(err, "HTTP request failed") + return nil, fmt.Errorf("HTTP request failed: %w", err) } if resp.StatusCode != http.StatusOK { - return nil, errors.Errorf("server returned bad HTTP status %s", resp.Status) + return nil, fmt.Errorf("server returned bad HTTP status %s", resp.Status) } if resp.Header.Get("Content-Encoding") != "gzip" { @@ -167,7 +166,7 @@ func (s *Scraper) readStream(ctx context.Context) (r io.ReadCloser, outerr error } reader, err := gzip.NewReader(bufio.NewReader(resp.Body)) - return reader, errors.Wrap(err, "failed to create gzip reader") + return reader, fmt.Errorf("failed to create gzip reader: %w", err) } // Describe describes this collector @@ -207,7 +206,7 @@ func (s *Scraper) scrape(ctx context.Context, ch chan<- prometheus.Metric) (oute parsed, err := new(expfmt.TextParser).TextToMetricFamilies(stream) if err != nil { - return errors.Wrapf(err, "parsing message failed") + return fmt.Errorf("parsing message failed: %w", err) } for _, mf := range parsed { diff --git a/pkg/collector/scraper_test.go b/pkg/collector/scraper_test.go index 50c0f125..ee6d247b 100644 --- a/pkg/collector/scraper_test.go +++ b/pkg/collector/scraper_test.go @@ -47,7 +47,7 @@ func TestScraper(t *testing.T) { ch := make(chan prometheus.Metric) go s.Collect(ch) for m := range ch { - if m.Desc().String() == `Desc{fqName: "testscraper_scrape_collector_success", help: "testscraper: Whether a collector succeeded.", constLabels: {}, variableLabels: [collector]}` { + if m.Desc().String() == `Desc{fqName: "testscraper_scrape_collector_success", help: "testscraper: Whether a collector succeeded.", constLabels: {}, variableLabels: {collector}}` { metric := &dto.Metric{} require.NoError(t, m.Write(metric)) require.Equal(t, float64(1), *metric.Gauge.Value) @@ -73,8 +73,8 @@ func TestScraperAddsKubernetesClusterUUID(t *testing.T) { ch := make(chan prometheus.Metric) go s.Collect(ch) for m := range ch { - if m.Desc().String() == `Desc{fqName: "testscraper_scrape_collector_success", help: "testscraper: Whether a collector succeeded.", constLabels: {}, variableLabels: [collector]}` || - m.Desc().String() == `Desc{fqName: "testscraper_scrape_collector_duration_seconds", help: "testscraper: Duration of a collector scrape.", constLabels: {}, variableLabels: [collector]}` { + if m.Desc().String() == `Desc{fqName: "testscraper_scrape_collector_success", help: "testscraper: Whether a collector succeeded.", constLabels: {}, variableLabels: {collector}}` || + m.Desc().String() == `Desc{fqName: "testscraper_scrape_collector_duration_seconds", help: "testscraper: Duration of a collector scrape.", constLabels: {}, variableLabels: {collector}}` { continue } metric := &dto.Metric{} @@ -107,15 +107,15 @@ func TestWhitelist(t *testing.T) { var whitelist int for m := range ch { switch m.Desc().String() { - case `Desc{fqName: "kube_configmap_created", help: "Unix creation timestamp", constLabels: {}, variableLabels: [namespace configmap]}`: + case `Desc{fqName: "kube_configmap_created", help: "Unix creation timestamp", constLabels: {}, variableLabels: {namespace,configmap}}`: whitelist++ continue // expected whitelisted metric - case `Desc{fqName: "testscraper_scrape_collector_success", help: "testscraper: Whether a collector succeeded.", constLabels: {}, variableLabels: [collector]}`: + case `Desc{fqName: "testscraper_scrape_collector_success", help: "testscraper: Whether a collector succeeded.", constLabels: {}, variableLabels: {collector}}`: metric := &dto.Metric{} require.NoError(t, m.Write(metric)) require.Equal(t, float64(1), *metric.Gauge.Value) return - case `Desc{fqName: "testscraper_scrape_collector_duration_seconds", help: "testscraper: Duration of a collector scrape.", constLabels: {}, variableLabels: [collector]}`: + case `Desc{fqName: "testscraper_scrape_collector_duration_seconds", help: "testscraper: Duration of a collector scrape.", constLabels: {}, variableLabels: {collector}}`: continue default: t.Errorf("Unexpected metric was scraped: %v", m.Desc()) diff --git a/pkg/writer/sonar.go b/pkg/writer/sonar.go index 280de28e..f07a9598 100644 --- a/pkg/writer/sonar.go +++ b/pkg/writer/sonar.go @@ -7,8 +7,6 @@ import ( "github.com/digitalocean/do-agent/pkg/aggregate" "github.com/digitalocean/do-agent/pkg/clients/tsclient" "github.com/prometheus/client_golang/prometheus" - - "github.com/pkg/errors" ) var ( @@ -45,14 +43,14 @@ func NewSonar(client tsclient.Client, c *prometheus.CounterVec) *Sonar { func (s *Sonar) Write(mets []aggregate.MetricWithValue) error { if len(mets) > s.client.MaxBatchSize() { s.c.WithLabelValues("failure", "too many metrics").Inc() - return errors.Wrap(ErrTooManyMetrics, "cannot write metrics") + return fmt.Errorf("cannot write metrics: %w", ErrTooManyMetrics) } for _, m := range mets { lfmEncoded := tsclient.ConvertLFMMapToPrometheusEncodedName(m.LFM) if len(lfmEncoded) > s.client.MaxMetricLength() { s.c.WithLabelValues("failure", "metric exceeds max length").Inc() - return errors.Wrapf(ErrMetricTooLong, "cannot send metric: %q", lfmEncoded) + return fmt.Errorf("cannot send metric %q: %w", lfmEncoded, ErrMetricTooLong) } err := s.client.AddMetric(tsclient.NewDefinitionFromMap(m.LFM), m.Value) if err != nil { diff --git a/vendor/github.com/alecthomas/kingpin/v2/.travis.yml b/vendor/github.com/alecthomas/kingpin/v2/.travis.yml new file mode 100644 index 00000000..9c45bacc --- /dev/null +++ b/vendor/github.com/alecthomas/kingpin/v2/.travis.yml @@ -0,0 +1,14 @@ +sudo: false +language: go +install: go get -t -v ./... +go: + - 1.2.x + - 1.3.x + - 1.4.x + - 1.5.x + - 1.6.x + - 1.7.x + - 1.8.x + - 1.9.x + - 1.10.x + - 1.11.x diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/COPYING b/vendor/github.com/alecthomas/kingpin/v2/COPYING similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/COPYING rename to vendor/github.com/alecthomas/kingpin/v2/COPYING diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/README.md b/vendor/github.com/alecthomas/kingpin/v2/README.md similarity index 89% rename from vendor/gopkg.in/alecthomas/kingpin.v2/README.md rename to vendor/github.com/alecthomas/kingpin/v2/README.md index 498704c8..5495ca19 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/README.md +++ b/vendor/github.com/alecthomas/kingpin/v2/README.md @@ -1,5 +1,15 @@ +# CONTRIBUTIONS ONLY + +**What does this mean?** I do not have time to fix issues myself. The only way fixes or new features will be added is by people submitting PRs. If you are interested in taking over maintenance and have a history of contributions to Kingpin, please let me know. + +**Current status.** Kingpin is largely feature stable. There hasn't been a need to add new features in a while, but there are some bugs that should be fixed. + +**Why?** I no longer use Kingpin personally (I now use [kong](https://github.com/alecthomas/kong)). Rather than leave the project in a limbo of people filing issues and wondering why they're not being worked on, I believe this notice will more clearly set expectations. + # Kingpin - A Go (golang) command line and flag parser -[![](https://godoc.org/github.com/alecthomas/kingpin?status.svg)](http://godoc.org/github.com/alecthomas/kingpin) [![Build Status](https://travis-ci.org/alecthomas/kingpin.svg?branch=master)](https://travis-ci.org/alecthomas/kingpin) [![Gitter chat](https://badges.gitter.im/alecthomas.png)](https://gitter.im/alecthomas/Lobby) +[![](https://godoc.org/github.com/alecthomas/kingpin?status.svg)](http://godoc.org/github.com/alecthomas/kingpin) [![CI](https://github.com/alecthomas/kingpin/actions/workflows/ci.yml/badge.svg)](https://github.com/alecthomas/kingpin/actions/workflows/ci.yml) + + @@ -41,7 +51,7 @@ positional arguments. Install it with: - $ go get gopkg.in/alecthomas/kingpin.v2 + $ go get github.com/alecthomas/kingpin/v2 It looks like this: @@ -116,16 +126,14 @@ be separated by a space. That is no longer the case. ## Versions -Kingpin uses [gopkg.in](https://gopkg.in/alecthomas/kingpin) for versioning. +The current stable version is [github.com/alecthomas/kingpin/v2](https://github.com/alecthomas/kingpin/v2). The previous version, [gopkg.in/alecthomas/kingpin.v1](https://gopkg.in/alecthomas/kingpin.v1), is deprecated and in maintenance mode. -The current stable version is [gopkg.in/alecthomas/kingpin.v2](https://gopkg.in/alecthomas/kingpin.v2). The previous version, [gopkg.in/alecthomas/kingpin.v1](https://gopkg.in/alecthomas/kingpin.v1), is deprecated and in maintenance mode. - -### [V2](https://gopkg.in/alecthomas/kingpin.v2) is the current stable version +### [V2](https://github.com/alecthomas/kingpin/v2) is the current stable version Installation: ```sh -$ go get gopkg.in/alecthomas/kingpin.v2 +$ go get github.com/alecthomas/kingpin/v2 ``` ### [V1](https://gopkg.in/alecthomas/kingpin.v1) is the OLD stable version @@ -233,12 +241,12 @@ package main import ( "fmt" - "gopkg.in/alecthomas/kingpin.v2" + "github.com/alecthomas/kingpin/v2" ) var ( debug = kingpin.Flag("debug", "Enable debug mode.").Bool() - timeout = kingpin.Flag("timeout", "Timeout waiting for ping.").Default("5s").OverrideDefaultFromEnvar("PING_TIMEOUT").Short('t').Duration() + timeout = kingpin.Flag("timeout", "Timeout waiting for ping.").Default("5s").Envar("PING_TIMEOUT").Short('t').Duration() ip = kingpin.Arg("ip", "IP address to ping.").Required().IP() count = kingpin.Arg("count", "Number of packets to send").Int() ) @@ -250,6 +258,17 @@ func main() { } ``` +#### Reading arguments from a file +Kingpin supports reading arguments from a file. +Create a file with the corresponding arguments: +``` +echo -t=5\n > args +``` +And now supply it: +``` +$ ping @args +``` + ### Complex Example Kingpin can also produce complex command-line applications with global flags, @@ -300,7 +319,7 @@ package main import ( "os" "strings" - "gopkg.in/alecthomas/kingpin.v2" + "github.com/alecthomas/kingpin/v2" ) var ( @@ -377,8 +396,8 @@ var ( func main() { switch kingpin.Parse() { - case "delete user": - case "delete post": + case deleteUserCommand.FullCommand(): + case deletePostCommand.FullCommand(): } } ``` @@ -514,35 +533,35 @@ ips := IPList(kingpin.Arg("ips", "IP addresses to ping.")) ### Bash/ZSH Shell Completion -By default, all flags and commands/subcommands generate completions +By default, all flags and commands/subcommands generate completions internally. -Out of the box, CLI tools using kingpin should be able to take advantage -of completion hinting for flags and commands. By specifying -`--completion-bash` as the first argument, your CLI tool will show -possible subcommands. By ending your argv with `--`, hints for flags +Out of the box, CLI tools using kingpin should be able to take advantage +of completion hinting for flags and commands. By specifying +`--completion-bash` as the first argument, your CLI tool will show +possible subcommands. By ending your argv with `--`, hints for flags will be shown. -To allow your end users to take advantage you must package a -`/etc/bash_completion.d` script with your distribution (or the equivalent -for your target platform/shell). An alternative is to instruct your end +To allow your end users to take advantage you must package a +`/etc/bash_completion.d` script with your distribution (or the equivalent +for your target platform/shell). An alternative is to instruct your end user to source a script from their `bash_profile` (or equivalent). Fortunately Kingpin makes it easy to generate or source a script for use -with end users shells. `./yourtool --completion-script-bash` and +with end users shells. `./yourtool --completion-script-bash` and `./yourtool --completion-script-zsh` will generate these scripts for you. **Installation by Package** -For the best user experience, you should bundle your pre-created -completion script with your CLI tool and install it inside -`/etc/bash_completion.d` (or equivalent). A good suggestion is to add -this as an automated step to your build pipeline, in the implementation +For the best user experience, you should bundle your pre-created +completion script with your CLI tool and install it inside +`/etc/bash_completion.d` (or equivalent). A good suggestion is to add +this as an automated step to your build pipeline, in the implementation is improved for bug fixed. **Installation by `bash_profile`** -Alternatively, instruct your users to add an additional statement to +Alternatively, instruct your users to add an additional statement to their `bash_profile` (or equivalent): ``` @@ -558,13 +577,13 @@ eval "$(your-cli-tool --completion-script-zsh)" #### Additional API To provide more flexibility, a completion option API has been exposed for flags to allow user defined completion options, to extend -completions further than just EnumVar/Enum. +completions further than just EnumVar/Enum. **Provide Static Options** -When using an `Enum` or `EnumVar`, users are limited to only the options -given. Maybe we wish to hint possible options to the user, but also +When using an `Enum` or `EnumVar`, users are limited to only the options +given. Maybe we wish to hint possible options to the user, but also allow them to provide their own custom option. `HintOptions` gives this functionality to flags. @@ -577,7 +596,7 @@ app.Flag("port", "Provide a port to connect to"). ``` **Provide Dynamic Options** -Consider the case that you needed to read a local database or a file to +Consider the case that you needed to read a local database or a file to provide suggestions. You can dynamically generate the options ``` @@ -596,13 +615,13 @@ app.Flag("flag-1", "").HintAction(listHosts).String() **EnumVar/Enum** When using `Enum` or `EnumVar`, any provided options will be automatically -used for bash autocompletion. However, if you wish to provide a subset or +used for bash autocompletion. However, if you wish to provide a subset or different options, you can use `HintOptions` or `HintAction` which will override the default completion options for `Enum`/`EnumVar`. **Examples** -You can see an in depth example of the completion API within +You can see an in depth example of the completion API within `examples/completion/main.go` @@ -610,11 +629,27 @@ You can see an in depth example of the completion API within `kingpin.CommandLine.HelpFlag.Short('h')` +Short help is also available when creating a more complicated app: + +```go +var ( + app = kingpin.New("chat", "A command-line chat application.") + // ... +) + +func main() { + app.HelpFlag.Short('h') + switch kingpin.MustParse(app.Parse(os.Args[1:])) { + // ... + } +} +``` + ### Custom help Kingpin v2 supports templatised help using the text/template library (actually, [a fork](https://github.com/alecthomas/template)). -You can specify the template to use with the [Application.UsageTemplate()](http://godoc.org/gopkg.in/alecthomas/kingpin.v2#Application.UsageTemplate) function. +You can specify the template to use with the [Application.UsageTemplate()](http://godoc.org/github.com/alecthomas/kingpin/v2#Application.UsageTemplate) function. There are four included templates: `kingpin.DefaultUsageTemplate` is the default, `kingpin.CompactUsageTemplate` provides a more compact representation for more complex command-line structures, diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/actions.go b/vendor/github.com/alecthomas/kingpin/v2/actions.go similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/actions.go rename to vendor/github.com/alecthomas/kingpin/v2/actions.go diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/app.go b/vendor/github.com/alecthomas/kingpin/v2/app.go similarity index 97% rename from vendor/gopkg.in/alecthomas/kingpin.v2/app.go rename to vendor/github.com/alecthomas/kingpin/v2/app.go index 1a1a5eff..4f1f31be 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/app.go +++ b/vendor/github.com/alecthomas/kingpin/v2/app.go @@ -6,6 +6,7 @@ import ( "os" "regexp" "strings" + "text/template" ) var ( @@ -32,6 +33,7 @@ type Application struct { errorWriter io.Writer // Destination for errors. usageWriter io.Writer // Destination for usage usageTemplate string + usageFuncs template.FuncMap validator ApplicationValidator terminate func(status int) // See Terminate() noInterspersed bool // can flags be interspersed with args (or must they come first) @@ -153,6 +155,12 @@ func (a *Application) UsageTemplate(template string) *Application { return a } +// UsageFuncs adds extra functions that can be used in the usage template. +func (a *Application) UsageFuncs(funcs template.FuncMap) *Application { + a.usageFuncs = funcs + return a +} + // Validate sets a validation function to run when parsing. func (a *Application) Validate(validator ApplicationValidator) *Application { a.validator = validator @@ -405,6 +413,10 @@ func (a *Application) setDefaults(context *ParseContext) error { if flag.name == "help" { return nil } + + if flag.name == "version" { + return nil + } flagElements[flag.name] = element } } @@ -452,14 +464,18 @@ func (a *Application) validateRequired(context *ParseContext) error { } // Check required flags and set defaults. + var missingFlags []string for _, flag := range context.flags.long { if flagElements[flag.name] == nil { // Check required flags were provided. if flag.needsValue() { - return fmt.Errorf("required flag --%s not provided", flag.name) + missingFlags = append(missingFlags, fmt.Sprintf("'--%s'", flag.name)) } } } + if len(missingFlags) != 0 { + return fmt.Errorf("required flag(s) %s not provided", strings.Join(missingFlags, ", ")) + } for _, arg := range context.arguments.args { if argElements[arg.name] == nil { @@ -496,11 +512,6 @@ func (a *Application) setValues(context *ParseContext) (selected []string, err e } case *CmdClause: - if clause.validator != nil { - if err = clause.validator(clause); err != nil { - return - } - } selected = append(selected, clause.name) lastCmd = clause } @@ -631,6 +642,10 @@ func (a *Application) completionOptions(context *ParseContext) []string { } if (currArg != "" && strings.HasPrefix(currArg, "--")) || strings.HasPrefix(prevArg, "--") { + if context.argsOnly { + return nil + } + // Perform completion for A flag. The last/current argument started with "-" var ( flagName string // The name of a flag if given (could be half complete) diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/args.go b/vendor/github.com/alecthomas/kingpin/v2/args.go similarity index 88% rename from vendor/gopkg.in/alecthomas/kingpin.v2/args.go rename to vendor/github.com/alecthomas/kingpin/v2/args.go index 34006947..54e41071 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/args.go +++ b/vendor/github.com/alecthomas/kingpin/v2/args.go @@ -71,6 +71,8 @@ type ArgClause struct { name string help string defaultValues []string + placeholder string + hidden bool required bool } @@ -120,6 +122,19 @@ func (a *ArgClause) consumesRemainder() bool { return false } +// Hidden hides the argument from usage but still allows it to be used. +func (a *ArgClause) Hidden() *ArgClause { + a.hidden = true + return a +} + +// PlaceHolder sets the place-holder string used for arg values in the help. The +// default behaviour is to use the arg name between < > brackets. +func (a *ArgClause) PlaceHolder(value string) *ArgClause { + a.placeholder = value + return a +} + // Required arguments must be input by the user. They can not have a Default() value provided. func (a *ArgClause) Required() *ArgClause { a.required = true @@ -173,6 +188,12 @@ func (a *ArgClause) HintOptions(options ...string) *ArgClause { return a } +// Help sets the help message. +func (a *ArgClause) Help(help string) *ArgClause { + a.help = help + return a +} + func (a *ArgClause) init() error { if a.required && len(a.defaultValues) > 0 { return fmt.Errorf("required argument '%s' with unusable default value", a.name) diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/cmd.go b/vendor/github.com/alecthomas/kingpin/v2/cmd.go similarity index 80% rename from vendor/gopkg.in/alecthomas/kingpin.v2/cmd.go rename to vendor/github.com/alecthomas/kingpin/v2/cmd.go index 0473b871..cd7e6120 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/cmd.go +++ b/vendor/github.com/alecthomas/kingpin/v2/cmd.go @@ -21,11 +21,47 @@ func (c *cmdMixin) CmdCompletion(context *ParseContext) []string { // default commands' alternatives, since they weren't listed explicitly // and the user may want to explicitly list something else. argsSatisfied := 0 + allSatisfied := false +ElementLoop: for _, el := range context.Elements { switch clause := el.Clause.(type) { case *ArgClause: + // Each new element should reset the previous state + allSatisfied = false + options = nil + if el.Value != nil && *el.Value != "" { - argsSatisfied++ + // Get the list of valid options for the last argument + validOptions := c.argGroup.args[argsSatisfied].resolveCompletions() + if len(validOptions) == 0 { + // If there are no options for this argument, + // mark is as allSatisfied as we can't suggest anything + if !clause.consumesRemainder() { + argsSatisfied++ + allSatisfied = true + } + continue ElementLoop + } + + for _, opt := range validOptions { + if opt == *el.Value { + // We have an exact match + // We don't need to suggest any option + if !clause.consumesRemainder() { + argsSatisfied++ + } + continue ElementLoop + } + if strings.HasPrefix(opt, *el.Value) { + // If the option match the partially entered argument, add it to the list + options = append(options, opt) + } + } + // Avoid further completion as we have done everything we could + if !clause.consumesRemainder() { + argsSatisfied++ + allSatisfied = true + } } case *CmdClause: options = append(options, clause.completionAlts...) @@ -33,7 +69,7 @@ func (c *cmdMixin) CmdCompletion(context *ParseContext) []string { } } - if argsSatisfied < len(c.argGroup.args) { + if argsSatisfied < len(c.argGroup.args) && !allSatisfied { // Since not all args have been satisfied, show options for the current one options = append(options, c.argGroup.args[argsSatisfied].resolveCompletions()...) } else { @@ -191,6 +227,7 @@ type CmdClause struct { name string aliases []string help string + helpLong string isDefault bool validator CmdClauseValidator hidden bool @@ -252,6 +289,12 @@ func (c *CmdClause) PreAction(action Action) *CmdClause { return c } +// Help sets the help message. +func (c *CmdClause) Help(help string) *CmdClause { + c.help = help + return c +} + func (c *CmdClause) init() error { if err := c.flagGroup.init(c.app.defaultEnvarPrefix()); err != nil { return err @@ -272,3 +315,11 @@ func (c *CmdClause) Hidden() *CmdClause { c.hidden = true return c } + +// HelpLong adds a long help text, which can be used in usage templates. +// For example, to use a longer help text in the command-specific help +// than in the apps root help. +func (c *CmdClause) HelpLong(help string) *CmdClause { + c.helpLong = help + return c +} diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/completions.go b/vendor/github.com/alecthomas/kingpin/v2/completions.go similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/completions.go rename to vendor/github.com/alecthomas/kingpin/v2/completions.go diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/doc.go b/vendor/github.com/alecthomas/kingpin/v2/doc.go similarity index 97% rename from vendor/gopkg.in/alecthomas/kingpin.v2/doc.go rename to vendor/github.com/alecthomas/kingpin/v2/doc.go index cb951a80..8a72729d 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/doc.go +++ b/vendor/github.com/alecthomas/kingpin/v2/doc.go @@ -35,7 +35,7 @@ // // package main // -// import "gopkg.in/alecthomas/kingpin.v2" +// import "github.com/alecthomas/kingpin/v2" // // var ( // debug = kingpin.Flag("debug", "enable debug mode").Default("false").Bool() diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/envar.go b/vendor/github.com/alecthomas/kingpin/v2/envar.go similarity index 81% rename from vendor/gopkg.in/alecthomas/kingpin.v2/envar.go rename to vendor/github.com/alecthomas/kingpin/v2/envar.go index c01a27df..44e16de3 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/envar.go +++ b/vendor/github.com/alecthomas/kingpin/v2/envar.go @@ -28,18 +28,13 @@ func (e *envarMixin) GetEnvarValue() string { } func (e *envarMixin) GetSplitEnvarValue() []string { - values := make([]string, 0) - envarValue := e.GetEnvarValue() if envarValue == "" { - return values + return []string{} } // Split by new line to extract multiple values, if any. trimmed := envVarValuesTrimmer.ReplaceAllString(envarValue, "") - for _, value := range envVarValuesSplitter.Split(trimmed, -1) { - values = append(values, value) - } - return values + return envVarValuesSplitter.Split(trimmed, -1) } diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/flags.go b/vendor/github.com/alecthomas/kingpin/v2/flags.go similarity index 94% rename from vendor/gopkg.in/alecthomas/kingpin.v2/flags.go rename to vendor/github.com/alecthomas/kingpin/v2/flags.go index 8f33721f..2b2938b4 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/flags.go +++ b/vendor/github.com/alecthomas/kingpin/v2/flags.go @@ -109,6 +109,8 @@ loop: context.Next() + flag.isSetByUser() + fb, ok := flag.value.(boolFlag) if ok && fb.IsBoolFlag() { if invert { @@ -152,6 +154,7 @@ type FlagClause struct { defaultValues []string placeholder string hidden bool + setByUser *bool } func newFlag(name, help string) *FlagClause { @@ -189,6 +192,12 @@ func (f *FlagClause) setDefault() error { return nil } +func (f *FlagClause) isSetByUser() { + if f.setByUser != nil { + *f.setByUser = true + } +} + func (f *FlagClause) needsValue() bool { haveDefault := len(f.defaultValues) > 0 return f.required && !(haveDefault || f.HasEnvarValue()) @@ -246,6 +255,15 @@ func (a *FlagClause) Enum(options ...string) (target *string) { return a.parserMixin.Enum(options...) } +// IsSetByUser let to know if the flag was set by the user +func (f *FlagClause) IsSetByUser(setByUser *bool) *FlagClause { + if setByUser != nil { + *setByUser = false + } + f.setByUser = setByUser + return f +} + // Default values for this flag. They *must* be parseable by the value of the flag. func (f *FlagClause) Default(values ...string) *FlagClause { f.defaultValues = values @@ -300,6 +318,12 @@ func (f *FlagClause) Short(name rune) *FlagClause { return f } +// Help sets the help message. +func (f *FlagClause) Help(help string) *FlagClause { + f.help = help + return f +} + // Bool makes this flag a boolean flag. func (f *FlagClause) Bool() (target *bool) { target = new(bool) diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/global.go b/vendor/github.com/alecthomas/kingpin/v2/global.go similarity index 97% rename from vendor/gopkg.in/alecthomas/kingpin.v2/global.go rename to vendor/github.com/alecthomas/kingpin/v2/global.go index 10a29137..4d073eab 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/global.go +++ b/vendor/github.com/alecthomas/kingpin/v2/global.go @@ -14,6 +14,8 @@ var ( HelpCommand = CommandLine.HelpCommand // Global version flag. Exposed for user customisation. May be nil. VersionFlag = CommandLine.VersionFlag + // Whether to file expansion with '@' is enabled. + EnableFileExpansion = true ) // Command adds a new command to the default parser. diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/guesswidth.go b/vendor/github.com/alecthomas/kingpin/v2/guesswidth.go similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/guesswidth.go rename to vendor/github.com/alecthomas/kingpin/v2/guesswidth.go diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/guesswidth_unix.go b/vendor/github.com/alecthomas/kingpin/v2/guesswidth_unix.go similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/guesswidth_unix.go rename to vendor/github.com/alecthomas/kingpin/v2/guesswidth_unix.go diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/model.go b/vendor/github.com/alecthomas/kingpin/v2/model.go similarity index 77% rename from vendor/gopkg.in/alecthomas/kingpin.v2/model.go rename to vendor/github.com/alecthomas/kingpin/v2/model.go index a4ee83b4..382616c5 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/model.go +++ b/vendor/github.com/alecthomas/kingpin/v2/model.go @@ -8,6 +8,17 @@ import ( // Data model for Kingpin command-line structure. +var ( + ignoreInCount = map[string]bool{ + "help": true, + "help-long": true, + "help-man": true, + "completion-bash": true, + "completion-script-bash": true, + "completion-script-zsh": true, + } +) + type FlagGroupModel struct { Flags []*FlagModel } @@ -15,10 +26,13 @@ type FlagGroupModel struct { func (f *FlagGroupModel) FlagSummary() string { out := []string{} count := 0 + for _, flag := range f.Flags { - if flag.Name != "help" { + + if !ignoreInCount[flag.Name] { count++ } + if flag.Required { if flag.IsBoolFlag() { out = append(out, fmt.Sprintf("--[no-]%s", flag.Name)) @@ -46,6 +60,9 @@ type FlagModel struct { } func (f *FlagModel) String() string { + if f.Value == nil { + return "" + } return f.Value.String() } @@ -73,6 +90,13 @@ func (f *FlagModel) FormatPlaceHolder() string { return strings.ToUpper(f.Name) } +func (f *FlagModel) HelpWithEnvar() string { + if f.Envar == "" { + return f.Help + } + return fmt.Sprintf("%s ($%s)", f.Help, f.Envar) +} + type ArgGroupModel struct { Args []*ArgModel } @@ -81,7 +105,12 @@ func (a *ArgGroupModel) ArgSummary() string { depth := 0 out := []string{} for _, arg := range a.Args { - h := "<" + arg.Name + ">" + var h string + if arg.PlaceHolder != "" { + h = arg.PlaceHolder + } else { + h = "<" + arg.Name + ">" + } if !arg.Required { h = "[" + h depth++ @@ -92,16 +121,29 @@ func (a *ArgGroupModel) ArgSummary() string { return strings.Join(out, " ") } +func (a *ArgModel) HelpWithEnvar() string { + if a.Envar == "" { + return a.Help + } + return fmt.Sprintf("%s ($%s)", a.Help, a.Envar) +} + type ArgModel struct { - Name string - Help string - Default []string - Envar string - Required bool - Value Value + Name string + Help string + Default []string + Envar string + PlaceHolder string + Required bool + Hidden bool + Value Value } func (a *ArgModel) String() string { + if a.Value == nil { + return "" + } + return a.Value.String() } @@ -123,6 +165,7 @@ type CmdModel struct { Name string Aliases []string Help string + HelpLong string FullCommand string Depth int Hidden bool @@ -168,12 +211,14 @@ func (a *argGroup) Model() *ArgGroupModel { func (a *ArgClause) Model() *ArgModel { return &ArgModel{ - Name: a.name, - Help: a.help, - Default: a.defaultValues, - Envar: a.envar, - Required: a.required, - Value: a.value, + Name: a.name, + Help: a.help, + Default: a.defaultValues, + Envar: a.envar, + PlaceHolder: a.placeholder, + Required: a.required, + Hidden: a.hidden, + Value: a.value, } } @@ -216,6 +261,7 @@ func (c *CmdClause) Model() *CmdModel { Name: c.name, Aliases: c.aliases, Help: c.help, + HelpLong: c.helpLong, Depth: depth, Hidden: c.hidden, Default: c.isDefault, diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/parser.go b/vendor/github.com/alecthomas/kingpin/v2/parser.go similarity index 95% rename from vendor/gopkg.in/alecthomas/kingpin.v2/parser.go rename to vendor/github.com/alecthomas/kingpin/v2/parser.go index 2a183519..5f28c78d 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/parser.go +++ b/vendor/github.com/alecthomas/kingpin/v2/parser.go @@ -144,9 +144,7 @@ func (p *ParseContext) mergeFlags(flags *flagGroup) { } func (p *ParseContext) mergeArgs(args *argGroup) { - for _, arg := range args.args { - p.arguments.args = append(p.arguments.args, arg) - } + p.arguments.args = append(p.arguments.args, args.args...) } func (p *ParseContext) EOL() bool { @@ -168,6 +166,10 @@ func (p *ParseContext) Next() *Token { return &Token{Index: p.argi, Type: TokenEOL} } + if p.argi > 0 && p.argi <= len(p.rawArgs) && p.rawArgs[p.argi-1] == "--" { + // If the previous argument was a --, from now on only arguments are parsed. + p.argsOnly = true + } arg := p.args[0] p.next() @@ -175,9 +177,7 @@ func (p *ParseContext) Next() *Token { return &Token{p.argi, TokenArg, arg} } - // All remaining args are passed directly. if arg == "--" { - p.argsOnly = true return p.Next() } @@ -192,7 +192,7 @@ func (p *ParseContext) Next() *Token { if strings.HasPrefix(arg, "-") { if len(arg) == 1 { - return &Token{Index: p.argi, Type: TokenShort} + return &Token{Index: p.argi, Type: TokenArg} } shortRune, size := utf8.DecodeRuneInString(arg[1:]) short := string(shortRune) @@ -214,7 +214,7 @@ func (p *ParseContext) Next() *Token { p.args = append([]string{"-" + arg[size+1:]}, p.args...) } return &Token{p.argi, TokenShort, short} - } else if strings.HasPrefix(arg, "@") { + } else if EnableFileExpansion && strings.HasPrefix(arg, "@") { expanded, err := ExpandArgsFromFile(arg[1:]) if err != nil { return &Token{p.argi, TokenError, err.Error()} @@ -281,7 +281,7 @@ func ExpandArgsFromFile(filename string) (out []string, err error) { scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Text() - if strings.HasPrefix(line, "#") { + if strings.HasPrefix(line, "#") || strings.TrimSpace(line) == "" { continue } out = append(out, line) diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/parsers.go b/vendor/github.com/alecthomas/kingpin/v2/parsers.go similarity index 98% rename from vendor/gopkg.in/alecthomas/kingpin.v2/parsers.go rename to vendor/github.com/alecthomas/kingpin/v2/parsers.go index d9ad57e5..5a068821 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/parsers.go +++ b/vendor/github.com/alecthomas/kingpin/v2/parsers.go @@ -18,6 +18,10 @@ type parserMixin struct { required bool } +func (p *parserMixin) SetText(text Text) { + p.value = &wrapText{text} +} + func (p *parserMixin) SetValue(value Value) { p.value = value } diff --git a/vendor/github.com/alecthomas/kingpin/v2/templates.go b/vendor/github.com/alecthomas/kingpin/v2/templates.go new file mode 100644 index 00000000..703c2cda --- /dev/null +++ b/vendor/github.com/alecthomas/kingpin/v2/templates.go @@ -0,0 +1,262 @@ +package kingpin + +// Default usage template. +var DefaultUsageTemplate = `{{define "FormatCommand" -}} +{{if .FlagSummary}} {{.FlagSummary}}{{end -}} +{{range .Args}}{{if not .Hidden}} {{if not .Required}}[{{end}}{{if .PlaceHolder}}{{.PlaceHolder}}{{else}}<{{.Name}}>{{end}}{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}{{end -}} +{{end -}} + +{{define "FormatCommands" -}} +{{range .FlattenedCommands -}} +{{if not .Hidden -}} + {{.FullCommand}}{{if .Default}}*{{end}}{{template "FormatCommand" .}} +{{.Help|Wrap 4}} +{{end -}} +{{end -}} +{{end -}} + +{{define "FormatUsage" -}} +{{template "FormatCommand" .}}{{if .Commands}} [ ...]{{end}} +{{if .Help}} +{{.Help|Wrap 0 -}} +{{end -}} + +{{end -}} + +{{if .Context.SelectedCommand -}} +usage: {{.App.Name}} {{.Context.SelectedCommand}}{{template "FormatUsage" .Context.SelectedCommand}} +{{ else -}} +usage: {{.App.Name}}{{template "FormatUsage" .App}} +{{end}} +{{if .Context.Flags -}} +Flags: +{{.Context.Flags|FlagsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.Args -}} +Args: +{{.Context.Args|ArgsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.SelectedCommand -}} +{{if len .Context.SelectedCommand.Commands -}} +Subcommands: +{{template "FormatCommands" .Context.SelectedCommand}} +{{end -}} +{{else if .App.Commands -}} +Commands: +{{template "FormatCommands" .App}} +{{end -}} +` + +// Usage template where command's optional flags are listed separately +var SeparateOptionalFlagsUsageTemplate = `{{define "FormatCommand" -}} +{{if .FlagSummary}} {{.FlagSummary}}{{end -}} +{{range .Args}}{{if not .Hidden}} {{if not .Required}}[{{end}}{{if .PlaceHolder}}{{.PlaceHolder}}{{else}}<{{.Name}}>{{end}}{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}{{end -}} +{{end -}} + +{{define "FormatCommands" -}} +{{range .FlattenedCommands -}} +{{if not .Hidden -}} + {{.FullCommand}}{{if .Default}}*{{end}}{{template "FormatCommand" .}} +{{.Help|Wrap 4}} +{{end -}} +{{end -}} +{{end -}} + +{{define "FormatUsage" -}} +{{template "FormatCommand" .}}{{if .Commands}} [ ...]{{end}} +{{if .Help}} +{{.Help|Wrap 0 -}} +{{end -}} + +{{end -}} +{{if .Context.SelectedCommand -}} +usage: {{.App.Name}} {{.Context.SelectedCommand}}{{template "FormatUsage" .Context.SelectedCommand}} +{{else -}} +usage: {{.App.Name}}{{template "FormatUsage" .App}} +{{end -}} + +{{if .Context.Flags|RequiredFlags -}} +Required flags: +{{.Context.Flags|RequiredFlags|FlagsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.Flags|OptionalFlags -}} +Optional flags: +{{.Context.Flags|OptionalFlags|FlagsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.Args -}} +Args: +{{.Context.Args|ArgsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.SelectedCommand -}} +Subcommands: +{{if .Context.SelectedCommand.Commands -}} +{{template "FormatCommands" .Context.SelectedCommand}} +{{end -}} +{{else if .App.Commands -}} +Commands: +{{template "FormatCommands" .App}} +{{end -}} +` + +// Usage template with compactly formatted commands. +var CompactUsageTemplate = `{{define "FormatCommand" -}} +{{if .FlagSummary}} {{.FlagSummary}}{{end -}} +{{range .Args}}{{if not .Hidden}} {{if not .Required}}[{{end}}{{if .PlaceHolder}}{{.PlaceHolder}}{{else}}<{{.Name}}>{{end}}{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}{{end -}} +{{end -}} + +{{define "FormatCommandList" -}} +{{range . -}} +{{if not .Hidden -}} +{{.Depth|Indent}}{{.Name}}{{if .Default}}*{{end}}{{template "FormatCommand" .}} +{{end -}} +{{template "FormatCommandList" .Commands -}} +{{end -}} +{{end -}} + +{{define "FormatUsage" -}} +{{template "FormatCommand" .}}{{if .Commands}} [ ...]{{end}} +{{if .Help}} +{{.Help|Wrap 0 -}} +{{end -}} + +{{end -}} + +{{if .Context.SelectedCommand -}} +usage: {{.App.Name}} {{.Context.SelectedCommand}}{{template "FormatUsage" .Context.SelectedCommand}} +{{else -}} +usage: {{.App.Name}}{{template "FormatUsage" .App}} +{{end -}} +{{if .Context.Flags -}} +Flags: +{{.Context.Flags|FlagsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.Args -}} +Args: +{{.Context.Args|ArgsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.SelectedCommand -}} +{{if .Context.SelectedCommand.Commands -}} +Commands: + {{.Context.SelectedCommand}} +{{template "FormatCommandList" .Context.SelectedCommand.Commands}} +{{end -}} +{{else if .App.Commands -}} +Commands: +{{template "FormatCommandList" .App.Commands}} +{{end -}} +` + +var ManPageTemplate = `{{define "FormatFlags" -}} +{{range .Flags -}} +{{if not .Hidden -}} +.TP +\fB{{if .Short}}-{{.Short|Char}}, {{end}}--{{.Name}}{{if not .IsBoolFlag}}={{.FormatPlaceHolder}}{{end -}}\fR +{{.Help}} +{{end -}} +{{end -}} +{{end -}} + +{{define "FormatCommand" -}} +{{if .FlagSummary}} {{.FlagSummary}}{{end -}} +{{range .Args}}{{if not .Hidden}} {{if not .Required}}[{{end}}{{if .PlaceHolder}}{{.PlaceHolder}}{{else}}<{{.Name}}>{{end}}{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}{{end -}} +{{end -}} + +{{define "FormatCommands" -}} +{{range .FlattenedCommands -}} +{{if not .Hidden -}} +.SS +\fB{{.FullCommand}}{{template "FormatCommand" . -}}\fR +.PP +{{.Help}} +{{template "FormatFlags" . -}} +{{end -}} +{{end -}} +{{end -}} + +{{define "FormatUsage" -}} +{{template "FormatCommand" .}}{{if .Commands}} [ ...]{{end -}}\fR +{{end -}} + +.TH {{.App.Name}} 1 {{.App.Version}} "{{.App.Author}}" +.SH "NAME" +{{.App.Name}} +.SH "SYNOPSIS" +.TP +\fB{{.App.Name}}{{template "FormatUsage" .App}} +.SH "DESCRIPTION" +{{.App.Help}} +.SH "OPTIONS" +{{template "FormatFlags" .App -}} +{{if .App.Commands -}} +.SH "COMMANDS" +{{template "FormatCommands" .App -}} +{{end -}} +` + +// Default usage template. +var LongHelpTemplate = `{{define "FormatCommand" -}} +{{if .FlagSummary}} {{.FlagSummary}}{{end -}} +{{range .Args}}{{if not .Hidden}} {{if not .Required}}[{{end}}{{if .PlaceHolder}}{{.PlaceHolder}}{{else}}<{{.Name}}>{{end}}{{if .Value|IsCumulative}}...{{end}}{{if not .Required}}]{{end}}{{end}}{{end -}} +{{end -}} + +{{define "FormatCommands" -}} +{{range .FlattenedCommands -}} +{{if not .Hidden -}} + {{.FullCommand}}{{template "FormatCommand" .}} +{{.Help|Wrap 4}} +{{with .Flags|FlagsToTwoColumns}}{{FormatTwoColumnsWithIndent . 4 2}}{{end}} +{{end -}} +{{end -}} +{{end -}} + +{{define "FormatUsage" -}} +{{template "FormatCommand" .}}{{if .Commands}} [ ...]{{end}} +{{if .Help}} +{{.Help|Wrap 0 -}} +{{end -}} + +{{end -}} + +usage: {{.App.Name}}{{template "FormatUsage" .App}} +{{if .Context.Flags -}} +Flags: +{{.Context.Flags|FlagsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .Context.Args -}} +Args: +{{.Context.Args|ArgsToTwoColumns|FormatTwoColumns}} +{{end -}} +{{if .App.Commands -}} +Commands: +{{template "FormatCommands" .App}} +{{end -}} +` + +var BashCompletionTemplate = ` +_{{.App.Name}}_bash_autocomplete() { + local cur prev opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + opts=$( ${COMP_WORDS[0]} --completion-bash "${COMP_WORDS[@]:1:$COMP_CWORD}" ) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 +} +complete -F _{{.App.Name}}_bash_autocomplete -o default {{.App.Name}} + +` + +var ZshCompletionTemplate = `#compdef {{.App.Name}} + +_{{.App.Name}}() { + local matches=($(${words[1]} --completion-bash "${(@)words[2,$CURRENT]}")) + compadd -a matches + + if [[ $compstate[nmatches] -eq 0 && $words[$CURRENT] != -* ]]; then + _files + fi +} + +if [[ "$(basename -- ${(%):-%x})" != "_{{.App.Name}}" ]]; then + compdef _{{.App.Name}} {{.App.Name}} +fi +` diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/usage.go b/vendor/github.com/alecthomas/kingpin/v2/usage.go similarity index 87% rename from vendor/gopkg.in/alecthomas/kingpin.v2/usage.go rename to vendor/github.com/alecthomas/kingpin/v2/usage.go index 44af6f65..9b3dd731 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/usage.go +++ b/vendor/github.com/alecthomas/kingpin/v2/usage.go @@ -6,8 +6,7 @@ import ( "go/doc" "io" "strings" - - "github.com/alecthomas/template" + "text/template" ) var ( @@ -64,24 +63,28 @@ func formatAppUsage(app *ApplicationModel) string { func formatCmdUsage(app *ApplicationModel, cmd *CmdModel) string { s := []string{app.Name, cmd.String()} - if len(app.Flags) > 0 { - s = append(s, app.FlagSummary()) + if len(cmd.Flags) > 0 { + s = append(s, cmd.FlagSummary()) } - if len(app.Args) > 0 { - s = append(s, app.ArgSummary()) + if len(cmd.Args) > 0 { + s = append(s, cmd.ArgSummary()) } return strings.Join(s, " ") } func formatFlag(haveShort bool, flag *FlagModel) string { flagString := "" + flagName := flag.Name + if flag.IsBoolFlag() { + flagName = "[no-]" + flagName + } if flag.Short != 0 { - flagString += fmt.Sprintf("-%c, --%s", flag.Short, flag.Name) + flagString += fmt.Sprintf("-%c, --%s", flag.Short, flagName) } else { if haveShort { - flagString += fmt.Sprintf(" --%s", flag.Name) + flagString += fmt.Sprintf(" --%s", flagName) } else { - flagString += fmt.Sprintf("--%s", flag.Name) + flagString += fmt.Sprintf("--%s", flagName) } } if !flag.IsBoolFlag() { @@ -136,7 +139,7 @@ func (a *Application) UsageForContextWithTemplate(context *ParseContext, indent } for _, flag := range f { if !flag.Hidden { - rows = append(rows, [2]string{formatFlag(haveShort, flag), flag.Help}) + rows = append(rows, [2]string{formatFlag(haveShort, flag), flag.HelpWithEnvar()}) } } return rows @@ -162,11 +165,18 @@ func (a *Application) UsageForContextWithTemplate(context *ParseContext, indent "ArgsToTwoColumns": func(a []*ArgModel) [][2]string { rows := [][2]string{} for _, arg := range a { - s := "<" + arg.Name + ">" - if !arg.Required { - s = "[" + s + "]" + if !arg.Hidden { + var s string + if arg.PlaceHolder != "" { + s = arg.PlaceHolder + } else { + s = "<" + arg.Name + ">" + } + if !arg.Required { + s = "[" + s + "]" + } + rows = append(rows, [2]string{s, arg.HelpWithEnvar()}) } - rows = append(rows, [2]string{s, arg.Help}) } return rows }, @@ -190,6 +200,10 @@ func (a *Application) UsageForContextWithTemplate(context *ParseContext, indent return string(c) }, } + for k, v := range a.usageFuncs { + funcs[k] = v + } + t, err := template.New("usage").Funcs(funcs).Parse(tmpl) if err != nil { return err diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/values.go b/vendor/github.com/alecthomas/kingpin/v2/values.go similarity index 95% rename from vendor/gopkg.in/alecthomas/kingpin.v2/values.go rename to vendor/github.com/alecthomas/kingpin/v2/values.go index 7ee9a3b3..e6e05bc2 100644 --- a/vendor/gopkg.in/alecthomas/kingpin.v2/values.go +++ b/vendor/github.com/alecthomas/kingpin/v2/values.go @@ -3,6 +3,7 @@ package kingpin //go:generate go run ./cmd/genvalues/main.go import ( + "encoding" "fmt" "net" "net/url" @@ -13,6 +14,7 @@ import ( "time" "github.com/alecthomas/units" + "github.com/xhit/go-str2duration/v2" ) // NOTE: Most of the base type values were lifted from: @@ -42,23 +44,40 @@ type Getter interface { // Optional interface to indicate boolean flags that don't accept a value, and // implicitly have a --no- negation counterpart. type boolFlag interface { - Value IsBoolFlag() bool } // Optional interface for arguments that cumulatively consume all remaining // input. type remainderArg interface { - Value IsCumulative() bool } // Optional interface for flags that can be repeated. type repeatableFlag interface { - Value IsCumulative() bool } +// Text is the interface to the dynamic value stored in a flag. +// (The default value is represented as a string.) +type Text interface { + encoding.TextMarshaler + encoding.TextUnmarshaler +} + +type wrapText struct { + text Text +} + +func (w wrapText) String() string { + buf, _ := w.text.MarshalText() + return string(buf) +} + +func (w *wrapText) Set(s string) error { + return w.text.UnmarshalText([]byte(s)) +} + type accumulator struct { element func(value interface{}) Value typ reflect.Type @@ -120,7 +139,7 @@ func newDurationValue(p *time.Duration) *durationValue { } func (d *durationValue) Set(s string) error { - v, err := time.ParseDuration(s) + v, err := str2duration.ParseDuration(s) *d = durationValue(v) return err } diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/values.json b/vendor/github.com/alecthomas/kingpin/v2/values.json similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/values.json rename to vendor/github.com/alecthomas/kingpin/v2/values.json diff --git a/vendor/gopkg.in/alecthomas/kingpin.v2/values_generated.go b/vendor/github.com/alecthomas/kingpin/v2/values_generated.go similarity index 100% rename from vendor/gopkg.in/alecthomas/kingpin.v2/values_generated.go rename to vendor/github.com/alecthomas/kingpin/v2/values_generated.go diff --git a/vendor/github.com/alecthomas/template/README.md b/vendor/github.com/alecthomas/template/README.md deleted file mode 100644 index ef6a8ee3..00000000 --- a/vendor/github.com/alecthomas/template/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Go's `text/template` package with newline elision - -This is a fork of Go 1.4's [text/template](http://golang.org/pkg/text/template/) package with one addition: a backslash immediately after a closing delimiter will delete all subsequent newlines until a non-newline. - -eg. - -``` -{{if true}}\ -hello -{{end}}\ -``` - -Will result in: - -``` -hello\n -``` - -Rather than: - -``` -\n -hello\n -\n -``` diff --git a/vendor/github.com/alecthomas/template/doc.go b/vendor/github.com/alecthomas/template/doc.go deleted file mode 100644 index 223c595c..00000000 --- a/vendor/github.com/alecthomas/template/doc.go +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -/* -Package template implements data-driven templates for generating textual output. - -To generate HTML output, see package html/template, which has the same interface -as this package but automatically secures HTML output against certain attacks. - -Templates are executed by applying them to a data structure. Annotations in the -template refer to elements of the data structure (typically a field of a struct -or a key in a map) to control execution and derive values to be displayed. -Execution of the template walks the structure and sets the cursor, represented -by a period '.' and called "dot", to the value at the current location in the -structure as execution proceeds. - -The input text for a template is UTF-8-encoded text in any format. -"Actions"--data evaluations or control structures--are delimited by -"{{" and "}}"; all text outside actions is copied to the output unchanged. -Actions may not span newlines, although comments can. - -Once parsed, a template may be executed safely in parallel. - -Here is a trivial example that prints "17 items are made of wool". - - type Inventory struct { - Material string - Count uint - } - sweaters := Inventory{"wool", 17} - tmpl, err := template.New("test").Parse("{{.Count}} items are made of {{.Material}}") - if err != nil { panic(err) } - err = tmpl.Execute(os.Stdout, sweaters) - if err != nil { panic(err) } - -More intricate examples appear below. - -Actions - -Here is the list of actions. "Arguments" and "pipelines" are evaluations of -data, defined in detail below. - -*/ -// {{/* a comment */}} -// A comment; discarded. May contain newlines. -// Comments do not nest and must start and end at the -// delimiters, as shown here. -/* - - {{pipeline}} - The default textual representation of the value of the pipeline - is copied to the output. - - {{if pipeline}} T1 {{end}} - If the value of the pipeline is empty, no output is generated; - otherwise, T1 is executed. The empty values are false, 0, any - nil pointer or interface value, and any array, slice, map, or - string of length zero. - Dot is unaffected. - - {{if pipeline}} T1 {{else}} T0 {{end}} - If the value of the pipeline is empty, T0 is executed; - otherwise, T1 is executed. Dot is unaffected. - - {{if pipeline}} T1 {{else if pipeline}} T0 {{end}} - To simplify the appearance of if-else chains, the else action - of an if may include another if directly; the effect is exactly - the same as writing - {{if pipeline}} T1 {{else}}{{if pipeline}} T0 {{end}}{{end}} - - {{range pipeline}} T1 {{end}} - The value of the pipeline must be an array, slice, map, or channel. - If the value of the pipeline has length zero, nothing is output; - otherwise, dot is set to the successive elements of the array, - slice, or map and T1 is executed. If the value is a map and the - keys are of basic type with a defined order ("comparable"), the - elements will be visited in sorted key order. - - {{range pipeline}} T1 {{else}} T0 {{end}} - The value of the pipeline must be an array, slice, map, or channel. - If the value of the pipeline has length zero, dot is unaffected and - T0 is executed; otherwise, dot is set to the successive elements - of the array, slice, or map and T1 is executed. - - {{template "name"}} - The template with the specified name is executed with nil data. - - {{template "name" pipeline}} - The template with the specified name is executed with dot set - to the value of the pipeline. - - {{with pipeline}} T1 {{end}} - If the value of the pipeline is empty, no output is generated; - otherwise, dot is set to the value of the pipeline and T1 is - executed. - - {{with pipeline}} T1 {{else}} T0 {{end}} - If the value of the pipeline is empty, dot is unaffected and T0 - is executed; otherwise, dot is set to the value of the pipeline - and T1 is executed. - -Arguments - -An argument is a simple value, denoted by one of the following. - - - A boolean, string, character, integer, floating-point, imaginary - or complex constant in Go syntax. These behave like Go's untyped - constants, although raw strings may not span newlines. - - The keyword nil, representing an untyped Go nil. - - The character '.' (period): - . - The result is the value of dot. - - A variable name, which is a (possibly empty) alphanumeric string - preceded by a dollar sign, such as - $piOver2 - or - $ - The result is the value of the variable. - Variables are described below. - - The name of a field of the data, which must be a struct, preceded - by a period, such as - .Field - The result is the value of the field. Field invocations may be - chained: - .Field1.Field2 - Fields can also be evaluated on variables, including chaining: - $x.Field1.Field2 - - The name of a key of the data, which must be a map, preceded - by a period, such as - .Key - The result is the map element value indexed by the key. - Key invocations may be chained and combined with fields to any - depth: - .Field1.Key1.Field2.Key2 - Although the key must be an alphanumeric identifier, unlike with - field names they do not need to start with an upper case letter. - Keys can also be evaluated on variables, including chaining: - $x.key1.key2 - - The name of a niladic method of the data, preceded by a period, - such as - .Method - The result is the value of invoking the method with dot as the - receiver, dot.Method(). Such a method must have one return value (of - any type) or two return values, the second of which is an error. - If it has two and the returned error is non-nil, execution terminates - and an error is returned to the caller as the value of Execute. - Method invocations may be chained and combined with fields and keys - to any depth: - .Field1.Key1.Method1.Field2.Key2.Method2 - Methods can also be evaluated on variables, including chaining: - $x.Method1.Field - - The name of a niladic function, such as - fun - The result is the value of invoking the function, fun(). The return - types and values behave as in methods. Functions and function - names are described below. - - A parenthesized instance of one the above, for grouping. The result - may be accessed by a field or map key invocation. - print (.F1 arg1) (.F2 arg2) - (.StructValuedMethod "arg").Field - -Arguments may evaluate to any type; if they are pointers the implementation -automatically indirects to the base type when required. -If an evaluation yields a function value, such as a function-valued -field of a struct, the function is not invoked automatically, but it -can be used as a truth value for an if action and the like. To invoke -it, use the call function, defined below. - -A pipeline is a possibly chained sequence of "commands". A command is a simple -value (argument) or a function or method call, possibly with multiple arguments: - - Argument - The result is the value of evaluating the argument. - .Method [Argument...] - The method can be alone or the last element of a chain but, - unlike methods in the middle of a chain, it can take arguments. - The result is the value of calling the method with the - arguments: - dot.Method(Argument1, etc.) - functionName [Argument...] - The result is the value of calling the function associated - with the name: - function(Argument1, etc.) - Functions and function names are described below. - -Pipelines - -A pipeline may be "chained" by separating a sequence of commands with pipeline -characters '|'. In a chained pipeline, the result of the each command is -passed as the last argument of the following command. The output of the final -command in the pipeline is the value of the pipeline. - -The output of a command will be either one value or two values, the second of -which has type error. If that second value is present and evaluates to -non-nil, execution terminates and the error is returned to the caller of -Execute. - -Variables - -A pipeline inside an action may initialize a variable to capture the result. -The initialization has syntax - - $variable := pipeline - -where $variable is the name of the variable. An action that declares a -variable produces no output. - -If a "range" action initializes a variable, the variable is set to the -successive elements of the iteration. Also, a "range" may declare two -variables, separated by a comma: - - range $index, $element := pipeline - -in which case $index and $element are set to the successive values of the -array/slice index or map key and element, respectively. Note that if there is -only one variable, it is assigned the element; this is opposite to the -convention in Go range clauses. - -A variable's scope extends to the "end" action of the control structure ("if", -"with", or "range") in which it is declared, or to the end of the template if -there is no such control structure. A template invocation does not inherit -variables from the point of its invocation. - -When execution begins, $ is set to the data argument passed to Execute, that is, -to the starting value of dot. - -Examples - -Here are some example one-line templates demonstrating pipelines and variables. -All produce the quoted word "output": - - {{"\"output\""}} - A string constant. - {{`"output"`}} - A raw string constant. - {{printf "%q" "output"}} - A function call. - {{"output" | printf "%q"}} - A function call whose final argument comes from the previous - command. - {{printf "%q" (print "out" "put")}} - A parenthesized argument. - {{"put" | printf "%s%s" "out" | printf "%q"}} - A more elaborate call. - {{"output" | printf "%s" | printf "%q"}} - A longer chain. - {{with "output"}}{{printf "%q" .}}{{end}} - A with action using dot. - {{with $x := "output" | printf "%q"}}{{$x}}{{end}} - A with action that creates and uses a variable. - {{with $x := "output"}}{{printf "%q" $x}}{{end}} - A with action that uses the variable in another action. - {{with $x := "output"}}{{$x | printf "%q"}}{{end}} - The same, but pipelined. - -Functions - -During execution functions are found in two function maps: first in the -template, then in the global function map. By default, no functions are defined -in the template but the Funcs method can be used to add them. - -Predefined global functions are named as follows. - - and - Returns the boolean AND of its arguments by returning the - first empty argument or the last argument, that is, - "and x y" behaves as "if x then y else x". All the - arguments are evaluated. - call - Returns the result of calling the first argument, which - must be a function, with the remaining arguments as parameters. - Thus "call .X.Y 1 2" is, in Go notation, dot.X.Y(1, 2) where - Y is a func-valued field, map entry, or the like. - The first argument must be the result of an evaluation - that yields a value of function type (as distinct from - a predefined function such as print). The function must - return either one or two result values, the second of which - is of type error. If the arguments don't match the function - or the returned error value is non-nil, execution stops. - html - Returns the escaped HTML equivalent of the textual - representation of its arguments. - index - Returns the result of indexing its first argument by the - following arguments. Thus "index x 1 2 3" is, in Go syntax, - x[1][2][3]. Each indexed item must be a map, slice, or array. - js - Returns the escaped JavaScript equivalent of the textual - representation of its arguments. - len - Returns the integer length of its argument. - not - Returns the boolean negation of its single argument. - or - Returns the boolean OR of its arguments by returning the - first non-empty argument or the last argument, that is, - "or x y" behaves as "if x then x else y". All the - arguments are evaluated. - print - An alias for fmt.Sprint - printf - An alias for fmt.Sprintf - println - An alias for fmt.Sprintln - urlquery - Returns the escaped value of the textual representation of - its arguments in a form suitable for embedding in a URL query. - -The boolean functions take any zero value to be false and a non-zero -value to be true. - -There is also a set of binary comparison operators defined as -functions: - - eq - Returns the boolean truth of arg1 == arg2 - ne - Returns the boolean truth of arg1 != arg2 - lt - Returns the boolean truth of arg1 < arg2 - le - Returns the boolean truth of arg1 <= arg2 - gt - Returns the boolean truth of arg1 > arg2 - ge - Returns the boolean truth of arg1 >= arg2 - -For simpler multi-way equality tests, eq (only) accepts two or more -arguments and compares the second and subsequent to the first, -returning in effect - - arg1==arg2 || arg1==arg3 || arg1==arg4 ... - -(Unlike with || in Go, however, eq is a function call and all the -arguments will be evaluated.) - -The comparison functions work on basic types only (or named basic -types, such as "type Celsius float32"). They implement the Go rules -for comparison of values, except that size and exact type are -ignored, so any integer value, signed or unsigned, may be compared -with any other integer value. (The arithmetic value is compared, -not the bit pattern, so all negative integers are less than all -unsigned integers.) However, as usual, one may not compare an int -with a float32 and so on. - -Associated templates - -Each template is named by a string specified when it is created. Also, each -template is associated with zero or more other templates that it may invoke by -name; such associations are transitive and form a name space of templates. - -A template may use a template invocation to instantiate another associated -template; see the explanation of the "template" action above. The name must be -that of a template associated with the template that contains the invocation. - -Nested template definitions - -When parsing a template, another template may be defined and associated with the -template being parsed. Template definitions must appear at the top level of the -template, much like global variables in a Go program. - -The syntax of such definitions is to surround each template declaration with a -"define" and "end" action. - -The define action names the template being created by providing a string -constant. Here is a simple example: - - `{{define "T1"}}ONE{{end}} - {{define "T2"}}TWO{{end}} - {{define "T3"}}{{template "T1"}} {{template "T2"}}{{end}} - {{template "T3"}}` - -This defines two templates, T1 and T2, and a third T3 that invokes the other two -when it is executed. Finally it invokes T3. If executed this template will -produce the text - - ONE TWO - -By construction, a template may reside in only one association. If it's -necessary to have a template addressable from multiple associations, the -template definition must be parsed multiple times to create distinct *Template -values, or must be copied with the Clone or AddParseTree method. - -Parse may be called multiple times to assemble the various associated templates; -see the ParseFiles and ParseGlob functions and methods for simple ways to parse -related templates stored in files. - -A template may be executed directly or through ExecuteTemplate, which executes -an associated template identified by name. To invoke our example above, we -might write, - - err := tmpl.Execute(os.Stdout, "no data needed") - if err != nil { - log.Fatalf("execution failed: %s", err) - } - -or to invoke a particular template explicitly by name, - - err := tmpl.ExecuteTemplate(os.Stdout, "T2", "no data needed") - if err != nil { - log.Fatalf("execution failed: %s", err) - } - -*/ -package template diff --git a/vendor/github.com/alecthomas/template/exec.go b/vendor/github.com/alecthomas/template/exec.go deleted file mode 100644 index c3078e5d..00000000 --- a/vendor/github.com/alecthomas/template/exec.go +++ /dev/null @@ -1,845 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package template - -import ( - "bytes" - "fmt" - "io" - "reflect" - "runtime" - "sort" - "strings" - - "github.com/alecthomas/template/parse" -) - -// state represents the state of an execution. It's not part of the -// template so that multiple executions of the same template -// can execute in parallel. -type state struct { - tmpl *Template - wr io.Writer - node parse.Node // current node, for errors - vars []variable // push-down stack of variable values. -} - -// variable holds the dynamic value of a variable such as $, $x etc. -type variable struct { - name string - value reflect.Value -} - -// push pushes a new variable on the stack. -func (s *state) push(name string, value reflect.Value) { - s.vars = append(s.vars, variable{name, value}) -} - -// mark returns the length of the variable stack. -func (s *state) mark() int { - return len(s.vars) -} - -// pop pops the variable stack up to the mark. -func (s *state) pop(mark int) { - s.vars = s.vars[0:mark] -} - -// setVar overwrites the top-nth variable on the stack. Used by range iterations. -func (s *state) setVar(n int, value reflect.Value) { - s.vars[len(s.vars)-n].value = value -} - -// varValue returns the value of the named variable. -func (s *state) varValue(name string) reflect.Value { - for i := s.mark() - 1; i >= 0; i-- { - if s.vars[i].name == name { - return s.vars[i].value - } - } - s.errorf("undefined variable: %s", name) - return zero -} - -var zero reflect.Value - -// at marks the state to be on node n, for error reporting. -func (s *state) at(node parse.Node) { - s.node = node -} - -// doublePercent returns the string with %'s replaced by %%, if necessary, -// so it can be used safely inside a Printf format string. -func doublePercent(str string) string { - if strings.Contains(str, "%") { - str = strings.Replace(str, "%", "%%", -1) - } - return str -} - -// errorf formats the error and terminates processing. -func (s *state) errorf(format string, args ...interface{}) { - name := doublePercent(s.tmpl.Name()) - if s.node == nil { - format = fmt.Sprintf("template: %s: %s", name, format) - } else { - location, context := s.tmpl.ErrorContext(s.node) - format = fmt.Sprintf("template: %s: executing %q at <%s>: %s", location, name, doublePercent(context), format) - } - panic(fmt.Errorf(format, args...)) -} - -// errRecover is the handler that turns panics into returns from the top -// level of Parse. -func errRecover(errp *error) { - e := recover() - if e != nil { - switch err := e.(type) { - case runtime.Error: - panic(e) - case error: - *errp = err - default: - panic(e) - } - } -} - -// ExecuteTemplate applies the template associated with t that has the given name -// to the specified data object and writes the output to wr. -// If an error occurs executing the template or writing its output, -// execution stops, but partial results may already have been written to -// the output writer. -// A template may be executed safely in parallel. -func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error { - tmpl := t.tmpl[name] - if tmpl == nil { - return fmt.Errorf("template: no template %q associated with template %q", name, t.name) - } - return tmpl.Execute(wr, data) -} - -// Execute applies a parsed template to the specified data object, -// and writes the output to wr. -// If an error occurs executing the template or writing its output, -// execution stops, but partial results may already have been written to -// the output writer. -// A template may be executed safely in parallel. -func (t *Template) Execute(wr io.Writer, data interface{}) (err error) { - defer errRecover(&err) - value := reflect.ValueOf(data) - state := &state{ - tmpl: t, - wr: wr, - vars: []variable{{"$", value}}, - } - t.init() - if t.Tree == nil || t.Root == nil { - var b bytes.Buffer - for name, tmpl := range t.tmpl { - if tmpl.Tree == nil || tmpl.Root == nil { - continue - } - if b.Len() > 0 { - b.WriteString(", ") - } - fmt.Fprintf(&b, "%q", name) - } - var s string - if b.Len() > 0 { - s = "; defined templates are: " + b.String() - } - state.errorf("%q is an incomplete or empty template%s", t.Name(), s) - } - state.walk(value, t.Root) - return -} - -// Walk functions step through the major pieces of the template structure, -// generating output as they go. -func (s *state) walk(dot reflect.Value, node parse.Node) { - s.at(node) - switch node := node.(type) { - case *parse.ActionNode: - // Do not pop variables so they persist until next end. - // Also, if the action declares variables, don't print the result. - val := s.evalPipeline(dot, node.Pipe) - if len(node.Pipe.Decl) == 0 { - s.printValue(node, val) - } - case *parse.IfNode: - s.walkIfOrWith(parse.NodeIf, dot, node.Pipe, node.List, node.ElseList) - case *parse.ListNode: - for _, node := range node.Nodes { - s.walk(dot, node) - } - case *parse.RangeNode: - s.walkRange(dot, node) - case *parse.TemplateNode: - s.walkTemplate(dot, node) - case *parse.TextNode: - if _, err := s.wr.Write(node.Text); err != nil { - s.errorf("%s", err) - } - case *parse.WithNode: - s.walkIfOrWith(parse.NodeWith, dot, node.Pipe, node.List, node.ElseList) - default: - s.errorf("unknown node: %s", node) - } -} - -// walkIfOrWith walks an 'if' or 'with' node. The two control structures -// are identical in behavior except that 'with' sets dot. -func (s *state) walkIfOrWith(typ parse.NodeType, dot reflect.Value, pipe *parse.PipeNode, list, elseList *parse.ListNode) { - defer s.pop(s.mark()) - val := s.evalPipeline(dot, pipe) - truth, ok := isTrue(val) - if !ok { - s.errorf("if/with can't use %v", val) - } - if truth { - if typ == parse.NodeWith { - s.walk(val, list) - } else { - s.walk(dot, list) - } - } else if elseList != nil { - s.walk(dot, elseList) - } -} - -// isTrue reports whether the value is 'true', in the sense of not the zero of its type, -// and whether the value has a meaningful truth value. -func isTrue(val reflect.Value) (truth, ok bool) { - if !val.IsValid() { - // Something like var x interface{}, never set. It's a form of nil. - return false, true - } - switch val.Kind() { - case reflect.Array, reflect.Map, reflect.Slice, reflect.String: - truth = val.Len() > 0 - case reflect.Bool: - truth = val.Bool() - case reflect.Complex64, reflect.Complex128: - truth = val.Complex() != 0 - case reflect.Chan, reflect.Func, reflect.Ptr, reflect.Interface: - truth = !val.IsNil() - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - truth = val.Int() != 0 - case reflect.Float32, reflect.Float64: - truth = val.Float() != 0 - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - truth = val.Uint() != 0 - case reflect.Struct: - truth = true // Struct values are always true. - default: - return - } - return truth, true -} - -func (s *state) walkRange(dot reflect.Value, r *parse.RangeNode) { - s.at(r) - defer s.pop(s.mark()) - val, _ := indirect(s.evalPipeline(dot, r.Pipe)) - // mark top of stack before any variables in the body are pushed. - mark := s.mark() - oneIteration := func(index, elem reflect.Value) { - // Set top var (lexically the second if there are two) to the element. - if len(r.Pipe.Decl) > 0 { - s.setVar(1, elem) - } - // Set next var (lexically the first if there are two) to the index. - if len(r.Pipe.Decl) > 1 { - s.setVar(2, index) - } - s.walk(elem, r.List) - s.pop(mark) - } - switch val.Kind() { - case reflect.Array, reflect.Slice: - if val.Len() == 0 { - break - } - for i := 0; i < val.Len(); i++ { - oneIteration(reflect.ValueOf(i), val.Index(i)) - } - return - case reflect.Map: - if val.Len() == 0 { - break - } - for _, key := range sortKeys(val.MapKeys()) { - oneIteration(key, val.MapIndex(key)) - } - return - case reflect.Chan: - if val.IsNil() { - break - } - i := 0 - for ; ; i++ { - elem, ok := val.Recv() - if !ok { - break - } - oneIteration(reflect.ValueOf(i), elem) - } - if i == 0 { - break - } - return - case reflect.Invalid: - break // An invalid value is likely a nil map, etc. and acts like an empty map. - default: - s.errorf("range can't iterate over %v", val) - } - if r.ElseList != nil { - s.walk(dot, r.ElseList) - } -} - -func (s *state) walkTemplate(dot reflect.Value, t *parse.TemplateNode) { - s.at(t) - tmpl := s.tmpl.tmpl[t.Name] - if tmpl == nil { - s.errorf("template %q not defined", t.Name) - } - // Variables declared by the pipeline persist. - dot = s.evalPipeline(dot, t.Pipe) - newState := *s - newState.tmpl = tmpl - // No dynamic scoping: template invocations inherit no variables. - newState.vars = []variable{{"$", dot}} - newState.walk(dot, tmpl.Root) -} - -// Eval functions evaluate pipelines, commands, and their elements and extract -// values from the data structure by examining fields, calling methods, and so on. -// The printing of those values happens only through walk functions. - -// evalPipeline returns the value acquired by evaluating a pipeline. If the -// pipeline has a variable declaration, the variable will be pushed on the -// stack. Callers should therefore pop the stack after they are finished -// executing commands depending on the pipeline value. -func (s *state) evalPipeline(dot reflect.Value, pipe *parse.PipeNode) (value reflect.Value) { - if pipe == nil { - return - } - s.at(pipe) - for _, cmd := range pipe.Cmds { - value = s.evalCommand(dot, cmd, value) // previous value is this one's final arg. - // If the object has type interface{}, dig down one level to the thing inside. - if value.Kind() == reflect.Interface && value.Type().NumMethod() == 0 { - value = reflect.ValueOf(value.Interface()) // lovely! - } - } - for _, variable := range pipe.Decl { - s.push(variable.Ident[0], value) - } - return value -} - -func (s *state) notAFunction(args []parse.Node, final reflect.Value) { - if len(args) > 1 || final.IsValid() { - s.errorf("can't give argument to non-function %s", args[0]) - } -} - -func (s *state) evalCommand(dot reflect.Value, cmd *parse.CommandNode, final reflect.Value) reflect.Value { - firstWord := cmd.Args[0] - switch n := firstWord.(type) { - case *parse.FieldNode: - return s.evalFieldNode(dot, n, cmd.Args, final) - case *parse.ChainNode: - return s.evalChainNode(dot, n, cmd.Args, final) - case *parse.IdentifierNode: - // Must be a function. - return s.evalFunction(dot, n, cmd, cmd.Args, final) - case *parse.PipeNode: - // Parenthesized pipeline. The arguments are all inside the pipeline; final is ignored. - return s.evalPipeline(dot, n) - case *parse.VariableNode: - return s.evalVariableNode(dot, n, cmd.Args, final) - } - s.at(firstWord) - s.notAFunction(cmd.Args, final) - switch word := firstWord.(type) { - case *parse.BoolNode: - return reflect.ValueOf(word.True) - case *parse.DotNode: - return dot - case *parse.NilNode: - s.errorf("nil is not a command") - case *parse.NumberNode: - return s.idealConstant(word) - case *parse.StringNode: - return reflect.ValueOf(word.Text) - } - s.errorf("can't evaluate command %q", firstWord) - panic("not reached") -} - -// idealConstant is called to return the value of a number in a context where -// we don't know the type. In that case, the syntax of the number tells us -// its type, and we use Go rules to resolve. Note there is no such thing as -// a uint ideal constant in this situation - the value must be of int type. -func (s *state) idealConstant(constant *parse.NumberNode) reflect.Value { - // These are ideal constants but we don't know the type - // and we have no context. (If it was a method argument, - // we'd know what we need.) The syntax guides us to some extent. - s.at(constant) - switch { - case constant.IsComplex: - return reflect.ValueOf(constant.Complex128) // incontrovertible. - case constant.IsFloat && !isHexConstant(constant.Text) && strings.IndexAny(constant.Text, ".eE") >= 0: - return reflect.ValueOf(constant.Float64) - case constant.IsInt: - n := int(constant.Int64) - if int64(n) != constant.Int64 { - s.errorf("%s overflows int", constant.Text) - } - return reflect.ValueOf(n) - case constant.IsUint: - s.errorf("%s overflows int", constant.Text) - } - return zero -} - -func isHexConstant(s string) bool { - return len(s) > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X') -} - -func (s *state) evalFieldNode(dot reflect.Value, field *parse.FieldNode, args []parse.Node, final reflect.Value) reflect.Value { - s.at(field) - return s.evalFieldChain(dot, dot, field, field.Ident, args, final) -} - -func (s *state) evalChainNode(dot reflect.Value, chain *parse.ChainNode, args []parse.Node, final reflect.Value) reflect.Value { - s.at(chain) - // (pipe).Field1.Field2 has pipe as .Node, fields as .Field. Eval the pipeline, then the fields. - pipe := s.evalArg(dot, nil, chain.Node) - if len(chain.Field) == 0 { - s.errorf("internal error: no fields in evalChainNode") - } - return s.evalFieldChain(dot, pipe, chain, chain.Field, args, final) -} - -func (s *state) evalVariableNode(dot reflect.Value, variable *parse.VariableNode, args []parse.Node, final reflect.Value) reflect.Value { - // $x.Field has $x as the first ident, Field as the second. Eval the var, then the fields. - s.at(variable) - value := s.varValue(variable.Ident[0]) - if len(variable.Ident) == 1 { - s.notAFunction(args, final) - return value - } - return s.evalFieldChain(dot, value, variable, variable.Ident[1:], args, final) -} - -// evalFieldChain evaluates .X.Y.Z possibly followed by arguments. -// dot is the environment in which to evaluate arguments, while -// receiver is the value being walked along the chain. -func (s *state) evalFieldChain(dot, receiver reflect.Value, node parse.Node, ident []string, args []parse.Node, final reflect.Value) reflect.Value { - n := len(ident) - for i := 0; i < n-1; i++ { - receiver = s.evalField(dot, ident[i], node, nil, zero, receiver) - } - // Now if it's a method, it gets the arguments. - return s.evalField(dot, ident[n-1], node, args, final, receiver) -} - -func (s *state) evalFunction(dot reflect.Value, node *parse.IdentifierNode, cmd parse.Node, args []parse.Node, final reflect.Value) reflect.Value { - s.at(node) - name := node.Ident - function, ok := findFunction(name, s.tmpl) - if !ok { - s.errorf("%q is not a defined function", name) - } - return s.evalCall(dot, function, cmd, name, args, final) -} - -// evalField evaluates an expression like (.Field) or (.Field arg1 arg2). -// The 'final' argument represents the return value from the preceding -// value of the pipeline, if any. -func (s *state) evalField(dot reflect.Value, fieldName string, node parse.Node, args []parse.Node, final, receiver reflect.Value) reflect.Value { - if !receiver.IsValid() { - return zero - } - typ := receiver.Type() - receiver, _ = indirect(receiver) - // Unless it's an interface, need to get to a value of type *T to guarantee - // we see all methods of T and *T. - ptr := receiver - if ptr.Kind() != reflect.Interface && ptr.CanAddr() { - ptr = ptr.Addr() - } - if method := ptr.MethodByName(fieldName); method.IsValid() { - return s.evalCall(dot, method, node, fieldName, args, final) - } - hasArgs := len(args) > 1 || final.IsValid() - // It's not a method; must be a field of a struct or an element of a map. The receiver must not be nil. - receiver, isNil := indirect(receiver) - if isNil { - s.errorf("nil pointer evaluating %s.%s", typ, fieldName) - } - switch receiver.Kind() { - case reflect.Struct: - tField, ok := receiver.Type().FieldByName(fieldName) - if ok { - field := receiver.FieldByIndex(tField.Index) - if tField.PkgPath != "" { // field is unexported - s.errorf("%s is an unexported field of struct type %s", fieldName, typ) - } - // If it's a function, we must call it. - if hasArgs { - s.errorf("%s has arguments but cannot be invoked as function", fieldName) - } - return field - } - s.errorf("%s is not a field of struct type %s", fieldName, typ) - case reflect.Map: - // If it's a map, attempt to use the field name as a key. - nameVal := reflect.ValueOf(fieldName) - if nameVal.Type().AssignableTo(receiver.Type().Key()) { - if hasArgs { - s.errorf("%s is not a method but has arguments", fieldName) - } - return receiver.MapIndex(nameVal) - } - } - s.errorf("can't evaluate field %s in type %s", fieldName, typ) - panic("not reached") -} - -var ( - errorType = reflect.TypeOf((*error)(nil)).Elem() - fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() -) - -// evalCall executes a function or method call. If it's a method, fun already has the receiver bound, so -// it looks just like a function call. The arg list, if non-nil, includes (in the manner of the shell), arg[0] -// as the function itself. -func (s *state) evalCall(dot, fun reflect.Value, node parse.Node, name string, args []parse.Node, final reflect.Value) reflect.Value { - if args != nil { - args = args[1:] // Zeroth arg is function name/node; not passed to function. - } - typ := fun.Type() - numIn := len(args) - if final.IsValid() { - numIn++ - } - numFixed := len(args) - if typ.IsVariadic() { - numFixed = typ.NumIn() - 1 // last arg is the variadic one. - if numIn < numFixed { - s.errorf("wrong number of args for %s: want at least %d got %d", name, typ.NumIn()-1, len(args)) - } - } else if numIn < typ.NumIn()-1 || !typ.IsVariadic() && numIn != typ.NumIn() { - s.errorf("wrong number of args for %s: want %d got %d", name, typ.NumIn(), len(args)) - } - if !goodFunc(typ) { - // TODO: This could still be a confusing error; maybe goodFunc should provide info. - s.errorf("can't call method/function %q with %d results", name, typ.NumOut()) - } - // Build the arg list. - argv := make([]reflect.Value, numIn) - // Args must be evaluated. Fixed args first. - i := 0 - for ; i < numFixed && i < len(args); i++ { - argv[i] = s.evalArg(dot, typ.In(i), args[i]) - } - // Now the ... args. - if typ.IsVariadic() { - argType := typ.In(typ.NumIn() - 1).Elem() // Argument is a slice. - for ; i < len(args); i++ { - argv[i] = s.evalArg(dot, argType, args[i]) - } - } - // Add final value if necessary. - if final.IsValid() { - t := typ.In(typ.NumIn() - 1) - if typ.IsVariadic() { - t = t.Elem() - } - argv[i] = s.validateType(final, t) - } - result := fun.Call(argv) - // If we have an error that is not nil, stop execution and return that error to the caller. - if len(result) == 2 && !result[1].IsNil() { - s.at(node) - s.errorf("error calling %s: %s", name, result[1].Interface().(error)) - } - return result[0] -} - -// canBeNil reports whether an untyped nil can be assigned to the type. See reflect.Zero. -func canBeNil(typ reflect.Type) bool { - switch typ.Kind() { - case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: - return true - } - return false -} - -// validateType guarantees that the value is valid and assignable to the type. -func (s *state) validateType(value reflect.Value, typ reflect.Type) reflect.Value { - if !value.IsValid() { - if typ == nil || canBeNil(typ) { - // An untyped nil interface{}. Accept as a proper nil value. - return reflect.Zero(typ) - } - s.errorf("invalid value; expected %s", typ) - } - if typ != nil && !value.Type().AssignableTo(typ) { - if value.Kind() == reflect.Interface && !value.IsNil() { - value = value.Elem() - if value.Type().AssignableTo(typ) { - return value - } - // fallthrough - } - // Does one dereference or indirection work? We could do more, as we - // do with method receivers, but that gets messy and method receivers - // are much more constrained, so it makes more sense there than here. - // Besides, one is almost always all you need. - switch { - case value.Kind() == reflect.Ptr && value.Type().Elem().AssignableTo(typ): - value = value.Elem() - if !value.IsValid() { - s.errorf("dereference of nil pointer of type %s", typ) - } - case reflect.PtrTo(value.Type()).AssignableTo(typ) && value.CanAddr(): - value = value.Addr() - default: - s.errorf("wrong type for value; expected %s; got %s", typ, value.Type()) - } - } - return value -} - -func (s *state) evalArg(dot reflect.Value, typ reflect.Type, n parse.Node) reflect.Value { - s.at(n) - switch arg := n.(type) { - case *parse.DotNode: - return s.validateType(dot, typ) - case *parse.NilNode: - if canBeNil(typ) { - return reflect.Zero(typ) - } - s.errorf("cannot assign nil to %s", typ) - case *parse.FieldNode: - return s.validateType(s.evalFieldNode(dot, arg, []parse.Node{n}, zero), typ) - case *parse.VariableNode: - return s.validateType(s.evalVariableNode(dot, arg, nil, zero), typ) - case *parse.PipeNode: - return s.validateType(s.evalPipeline(dot, arg), typ) - case *parse.IdentifierNode: - return s.evalFunction(dot, arg, arg, nil, zero) - case *parse.ChainNode: - return s.validateType(s.evalChainNode(dot, arg, nil, zero), typ) - } - switch typ.Kind() { - case reflect.Bool: - return s.evalBool(typ, n) - case reflect.Complex64, reflect.Complex128: - return s.evalComplex(typ, n) - case reflect.Float32, reflect.Float64: - return s.evalFloat(typ, n) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return s.evalInteger(typ, n) - case reflect.Interface: - if typ.NumMethod() == 0 { - return s.evalEmptyInterface(dot, n) - } - case reflect.String: - return s.evalString(typ, n) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return s.evalUnsignedInteger(typ, n) - } - s.errorf("can't handle %s for arg of type %s", n, typ) - panic("not reached") -} - -func (s *state) evalBool(typ reflect.Type, n parse.Node) reflect.Value { - s.at(n) - if n, ok := n.(*parse.BoolNode); ok { - value := reflect.New(typ).Elem() - value.SetBool(n.True) - return value - } - s.errorf("expected bool; found %s", n) - panic("not reached") -} - -func (s *state) evalString(typ reflect.Type, n parse.Node) reflect.Value { - s.at(n) - if n, ok := n.(*parse.StringNode); ok { - value := reflect.New(typ).Elem() - value.SetString(n.Text) - return value - } - s.errorf("expected string; found %s", n) - panic("not reached") -} - -func (s *state) evalInteger(typ reflect.Type, n parse.Node) reflect.Value { - s.at(n) - if n, ok := n.(*parse.NumberNode); ok && n.IsInt { - value := reflect.New(typ).Elem() - value.SetInt(n.Int64) - return value - } - s.errorf("expected integer; found %s", n) - panic("not reached") -} - -func (s *state) evalUnsignedInteger(typ reflect.Type, n parse.Node) reflect.Value { - s.at(n) - if n, ok := n.(*parse.NumberNode); ok && n.IsUint { - value := reflect.New(typ).Elem() - value.SetUint(n.Uint64) - return value - } - s.errorf("expected unsigned integer; found %s", n) - panic("not reached") -} - -func (s *state) evalFloat(typ reflect.Type, n parse.Node) reflect.Value { - s.at(n) - if n, ok := n.(*parse.NumberNode); ok && n.IsFloat { - value := reflect.New(typ).Elem() - value.SetFloat(n.Float64) - return value - } - s.errorf("expected float; found %s", n) - panic("not reached") -} - -func (s *state) evalComplex(typ reflect.Type, n parse.Node) reflect.Value { - if n, ok := n.(*parse.NumberNode); ok && n.IsComplex { - value := reflect.New(typ).Elem() - value.SetComplex(n.Complex128) - return value - } - s.errorf("expected complex; found %s", n) - panic("not reached") -} - -func (s *state) evalEmptyInterface(dot reflect.Value, n parse.Node) reflect.Value { - s.at(n) - switch n := n.(type) { - case *parse.BoolNode: - return reflect.ValueOf(n.True) - case *parse.DotNode: - return dot - case *parse.FieldNode: - return s.evalFieldNode(dot, n, nil, zero) - case *parse.IdentifierNode: - return s.evalFunction(dot, n, n, nil, zero) - case *parse.NilNode: - // NilNode is handled in evalArg, the only place that calls here. - s.errorf("evalEmptyInterface: nil (can't happen)") - case *parse.NumberNode: - return s.idealConstant(n) - case *parse.StringNode: - return reflect.ValueOf(n.Text) - case *parse.VariableNode: - return s.evalVariableNode(dot, n, nil, zero) - case *parse.PipeNode: - return s.evalPipeline(dot, n) - } - s.errorf("can't handle assignment of %s to empty interface argument", n) - panic("not reached") -} - -// indirect returns the item at the end of indirection, and a bool to indicate if it's nil. -// We indirect through pointers and empty interfaces (only) because -// non-empty interfaces have methods we might need. -func indirect(v reflect.Value) (rv reflect.Value, isNil bool) { - for ; v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface; v = v.Elem() { - if v.IsNil() { - return v, true - } - if v.Kind() == reflect.Interface && v.NumMethod() > 0 { - break - } - } - return v, false -} - -// printValue writes the textual representation of the value to the output of -// the template. -func (s *state) printValue(n parse.Node, v reflect.Value) { - s.at(n) - iface, ok := printableValue(v) - if !ok { - s.errorf("can't print %s of type %s", n, v.Type()) - } - fmt.Fprint(s.wr, iface) -} - -// printableValue returns the, possibly indirected, interface value inside v that -// is best for a call to formatted printer. -func printableValue(v reflect.Value) (interface{}, bool) { - if v.Kind() == reflect.Ptr { - v, _ = indirect(v) // fmt.Fprint handles nil. - } - if !v.IsValid() { - return "", true - } - - if !v.Type().Implements(errorType) && !v.Type().Implements(fmtStringerType) { - if v.CanAddr() && (reflect.PtrTo(v.Type()).Implements(errorType) || reflect.PtrTo(v.Type()).Implements(fmtStringerType)) { - v = v.Addr() - } else { - switch v.Kind() { - case reflect.Chan, reflect.Func: - return nil, false - } - } - } - return v.Interface(), true -} - -// Types to help sort the keys in a map for reproducible output. - -type rvs []reflect.Value - -func (x rvs) Len() int { return len(x) } -func (x rvs) Swap(i, j int) { x[i], x[j] = x[j], x[i] } - -type rvInts struct{ rvs } - -func (x rvInts) Less(i, j int) bool { return x.rvs[i].Int() < x.rvs[j].Int() } - -type rvUints struct{ rvs } - -func (x rvUints) Less(i, j int) bool { return x.rvs[i].Uint() < x.rvs[j].Uint() } - -type rvFloats struct{ rvs } - -func (x rvFloats) Less(i, j int) bool { return x.rvs[i].Float() < x.rvs[j].Float() } - -type rvStrings struct{ rvs } - -func (x rvStrings) Less(i, j int) bool { return x.rvs[i].String() < x.rvs[j].String() } - -// sortKeys sorts (if it can) the slice of reflect.Values, which is a slice of map keys. -func sortKeys(v []reflect.Value) []reflect.Value { - if len(v) <= 1 { - return v - } - switch v[0].Kind() { - case reflect.Float32, reflect.Float64: - sort.Sort(rvFloats{v}) - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - sort.Sort(rvInts{v}) - case reflect.String: - sort.Sort(rvStrings{v}) - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - sort.Sort(rvUints{v}) - } - return v -} diff --git a/vendor/github.com/alecthomas/template/funcs.go b/vendor/github.com/alecthomas/template/funcs.go deleted file mode 100644 index 39ee5ed6..00000000 --- a/vendor/github.com/alecthomas/template/funcs.go +++ /dev/null @@ -1,598 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package template - -import ( - "bytes" - "errors" - "fmt" - "io" - "net/url" - "reflect" - "strings" - "unicode" - "unicode/utf8" -) - -// FuncMap is the type of the map defining the mapping from names to functions. -// Each function must have either a single return value, or two return values of -// which the second has type error. In that case, if the second (error) -// return value evaluates to non-nil during execution, execution terminates and -// Execute returns that error. -type FuncMap map[string]interface{} - -var builtins = FuncMap{ - "and": and, - "call": call, - "html": HTMLEscaper, - "index": index, - "js": JSEscaper, - "len": length, - "not": not, - "or": or, - "print": fmt.Sprint, - "printf": fmt.Sprintf, - "println": fmt.Sprintln, - "urlquery": URLQueryEscaper, - - // Comparisons - "eq": eq, // == - "ge": ge, // >= - "gt": gt, // > - "le": le, // <= - "lt": lt, // < - "ne": ne, // != -} - -var builtinFuncs = createValueFuncs(builtins) - -// createValueFuncs turns a FuncMap into a map[string]reflect.Value -func createValueFuncs(funcMap FuncMap) map[string]reflect.Value { - m := make(map[string]reflect.Value) - addValueFuncs(m, funcMap) - return m -} - -// addValueFuncs adds to values the functions in funcs, converting them to reflect.Values. -func addValueFuncs(out map[string]reflect.Value, in FuncMap) { - for name, fn := range in { - v := reflect.ValueOf(fn) - if v.Kind() != reflect.Func { - panic("value for " + name + " not a function") - } - if !goodFunc(v.Type()) { - panic(fmt.Errorf("can't install method/function %q with %d results", name, v.Type().NumOut())) - } - out[name] = v - } -} - -// addFuncs adds to values the functions in funcs. It does no checking of the input - -// call addValueFuncs first. -func addFuncs(out, in FuncMap) { - for name, fn := range in { - out[name] = fn - } -} - -// goodFunc checks that the function or method has the right result signature. -func goodFunc(typ reflect.Type) bool { - // We allow functions with 1 result or 2 results where the second is an error. - switch { - case typ.NumOut() == 1: - return true - case typ.NumOut() == 2 && typ.Out(1) == errorType: - return true - } - return false -} - -// findFunction looks for a function in the template, and global map. -func findFunction(name string, tmpl *Template) (reflect.Value, bool) { - if tmpl != nil && tmpl.common != nil { - if fn := tmpl.execFuncs[name]; fn.IsValid() { - return fn, true - } - } - if fn := builtinFuncs[name]; fn.IsValid() { - return fn, true - } - return reflect.Value{}, false -} - -// Indexing. - -// index returns the result of indexing its first argument by the following -// arguments. Thus "index x 1 2 3" is, in Go syntax, x[1][2][3]. Each -// indexed item must be a map, slice, or array. -func index(item interface{}, indices ...interface{}) (interface{}, error) { - v := reflect.ValueOf(item) - for _, i := range indices { - index := reflect.ValueOf(i) - var isNil bool - if v, isNil = indirect(v); isNil { - return nil, fmt.Errorf("index of nil pointer") - } - switch v.Kind() { - case reflect.Array, reflect.Slice, reflect.String: - var x int64 - switch index.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - x = index.Int() - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - x = int64(index.Uint()) - default: - return nil, fmt.Errorf("cannot index slice/array with type %s", index.Type()) - } - if x < 0 || x >= int64(v.Len()) { - return nil, fmt.Errorf("index out of range: %d", x) - } - v = v.Index(int(x)) - case reflect.Map: - if !index.IsValid() { - index = reflect.Zero(v.Type().Key()) - } - if !index.Type().AssignableTo(v.Type().Key()) { - return nil, fmt.Errorf("%s is not index type for %s", index.Type(), v.Type()) - } - if x := v.MapIndex(index); x.IsValid() { - v = x - } else { - v = reflect.Zero(v.Type().Elem()) - } - default: - return nil, fmt.Errorf("can't index item of type %s", v.Type()) - } - } - return v.Interface(), nil -} - -// Length - -// length returns the length of the item, with an error if it has no defined length. -func length(item interface{}) (int, error) { - v, isNil := indirect(reflect.ValueOf(item)) - if isNil { - return 0, fmt.Errorf("len of nil pointer") - } - switch v.Kind() { - case reflect.Array, reflect.Chan, reflect.Map, reflect.Slice, reflect.String: - return v.Len(), nil - } - return 0, fmt.Errorf("len of type %s", v.Type()) -} - -// Function invocation - -// call returns the result of evaluating the first argument as a function. -// The function must return 1 result, or 2 results, the second of which is an error. -func call(fn interface{}, args ...interface{}) (interface{}, error) { - v := reflect.ValueOf(fn) - typ := v.Type() - if typ.Kind() != reflect.Func { - return nil, fmt.Errorf("non-function of type %s", typ) - } - if !goodFunc(typ) { - return nil, fmt.Errorf("function called with %d args; should be 1 or 2", typ.NumOut()) - } - numIn := typ.NumIn() - var dddType reflect.Type - if typ.IsVariadic() { - if len(args) < numIn-1 { - return nil, fmt.Errorf("wrong number of args: got %d want at least %d", len(args), numIn-1) - } - dddType = typ.In(numIn - 1).Elem() - } else { - if len(args) != numIn { - return nil, fmt.Errorf("wrong number of args: got %d want %d", len(args), numIn) - } - } - argv := make([]reflect.Value, len(args)) - for i, arg := range args { - value := reflect.ValueOf(arg) - // Compute the expected type. Clumsy because of variadics. - var argType reflect.Type - if !typ.IsVariadic() || i < numIn-1 { - argType = typ.In(i) - } else { - argType = dddType - } - if !value.IsValid() && canBeNil(argType) { - value = reflect.Zero(argType) - } - if !value.Type().AssignableTo(argType) { - return nil, fmt.Errorf("arg %d has type %s; should be %s", i, value.Type(), argType) - } - argv[i] = value - } - result := v.Call(argv) - if len(result) == 2 && !result[1].IsNil() { - return result[0].Interface(), result[1].Interface().(error) - } - return result[0].Interface(), nil -} - -// Boolean logic. - -func truth(a interface{}) bool { - t, _ := isTrue(reflect.ValueOf(a)) - return t -} - -// and computes the Boolean AND of its arguments, returning -// the first false argument it encounters, or the last argument. -func and(arg0 interface{}, args ...interface{}) interface{} { - if !truth(arg0) { - return arg0 - } - for i := range args { - arg0 = args[i] - if !truth(arg0) { - break - } - } - return arg0 -} - -// or computes the Boolean OR of its arguments, returning -// the first true argument it encounters, or the last argument. -func or(arg0 interface{}, args ...interface{}) interface{} { - if truth(arg0) { - return arg0 - } - for i := range args { - arg0 = args[i] - if truth(arg0) { - break - } - } - return arg0 -} - -// not returns the Boolean negation of its argument. -func not(arg interface{}) (truth bool) { - truth, _ = isTrue(reflect.ValueOf(arg)) - return !truth -} - -// Comparison. - -// TODO: Perhaps allow comparison between signed and unsigned integers. - -var ( - errBadComparisonType = errors.New("invalid type for comparison") - errBadComparison = errors.New("incompatible types for comparison") - errNoComparison = errors.New("missing argument for comparison") -) - -type kind int - -const ( - invalidKind kind = iota - boolKind - complexKind - intKind - floatKind - integerKind - stringKind - uintKind -) - -func basicKind(v reflect.Value) (kind, error) { - switch v.Kind() { - case reflect.Bool: - return boolKind, nil - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return intKind, nil - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return uintKind, nil - case reflect.Float32, reflect.Float64: - return floatKind, nil - case reflect.Complex64, reflect.Complex128: - return complexKind, nil - case reflect.String: - return stringKind, nil - } - return invalidKind, errBadComparisonType -} - -// eq evaluates the comparison a == b || a == c || ... -func eq(arg1 interface{}, arg2 ...interface{}) (bool, error) { - v1 := reflect.ValueOf(arg1) - k1, err := basicKind(v1) - if err != nil { - return false, err - } - if len(arg2) == 0 { - return false, errNoComparison - } - for _, arg := range arg2 { - v2 := reflect.ValueOf(arg) - k2, err := basicKind(v2) - if err != nil { - return false, err - } - truth := false - if k1 != k2 { - // Special case: Can compare integer values regardless of type's sign. - switch { - case k1 == intKind && k2 == uintKind: - truth = v1.Int() >= 0 && uint64(v1.Int()) == v2.Uint() - case k1 == uintKind && k2 == intKind: - truth = v2.Int() >= 0 && v1.Uint() == uint64(v2.Int()) - default: - return false, errBadComparison - } - } else { - switch k1 { - case boolKind: - truth = v1.Bool() == v2.Bool() - case complexKind: - truth = v1.Complex() == v2.Complex() - case floatKind: - truth = v1.Float() == v2.Float() - case intKind: - truth = v1.Int() == v2.Int() - case stringKind: - truth = v1.String() == v2.String() - case uintKind: - truth = v1.Uint() == v2.Uint() - default: - panic("invalid kind") - } - } - if truth { - return true, nil - } - } - return false, nil -} - -// ne evaluates the comparison a != b. -func ne(arg1, arg2 interface{}) (bool, error) { - // != is the inverse of ==. - equal, err := eq(arg1, arg2) - return !equal, err -} - -// lt evaluates the comparison a < b. -func lt(arg1, arg2 interface{}) (bool, error) { - v1 := reflect.ValueOf(arg1) - k1, err := basicKind(v1) - if err != nil { - return false, err - } - v2 := reflect.ValueOf(arg2) - k2, err := basicKind(v2) - if err != nil { - return false, err - } - truth := false - if k1 != k2 { - // Special case: Can compare integer values regardless of type's sign. - switch { - case k1 == intKind && k2 == uintKind: - truth = v1.Int() < 0 || uint64(v1.Int()) < v2.Uint() - case k1 == uintKind && k2 == intKind: - truth = v2.Int() >= 0 && v1.Uint() < uint64(v2.Int()) - default: - return false, errBadComparison - } - } else { - switch k1 { - case boolKind, complexKind: - return false, errBadComparisonType - case floatKind: - truth = v1.Float() < v2.Float() - case intKind: - truth = v1.Int() < v2.Int() - case stringKind: - truth = v1.String() < v2.String() - case uintKind: - truth = v1.Uint() < v2.Uint() - default: - panic("invalid kind") - } - } - return truth, nil -} - -// le evaluates the comparison <= b. -func le(arg1, arg2 interface{}) (bool, error) { - // <= is < or ==. - lessThan, err := lt(arg1, arg2) - if lessThan || err != nil { - return lessThan, err - } - return eq(arg1, arg2) -} - -// gt evaluates the comparison a > b. -func gt(arg1, arg2 interface{}) (bool, error) { - // > is the inverse of <=. - lessOrEqual, err := le(arg1, arg2) - if err != nil { - return false, err - } - return !lessOrEqual, nil -} - -// ge evaluates the comparison a >= b. -func ge(arg1, arg2 interface{}) (bool, error) { - // >= is the inverse of <. - lessThan, err := lt(arg1, arg2) - if err != nil { - return false, err - } - return !lessThan, nil -} - -// HTML escaping. - -var ( - htmlQuot = []byte(""") // shorter than """ - htmlApos = []byte("'") // shorter than "'" and apos was not in HTML until HTML5 - htmlAmp = []byte("&") - htmlLt = []byte("<") - htmlGt = []byte(">") -) - -// HTMLEscape writes to w the escaped HTML equivalent of the plain text data b. -func HTMLEscape(w io.Writer, b []byte) { - last := 0 - for i, c := range b { - var html []byte - switch c { - case '"': - html = htmlQuot - case '\'': - html = htmlApos - case '&': - html = htmlAmp - case '<': - html = htmlLt - case '>': - html = htmlGt - default: - continue - } - w.Write(b[last:i]) - w.Write(html) - last = i + 1 - } - w.Write(b[last:]) -} - -// HTMLEscapeString returns the escaped HTML equivalent of the plain text data s. -func HTMLEscapeString(s string) string { - // Avoid allocation if we can. - if strings.IndexAny(s, `'"&<>`) < 0 { - return s - } - var b bytes.Buffer - HTMLEscape(&b, []byte(s)) - return b.String() -} - -// HTMLEscaper returns the escaped HTML equivalent of the textual -// representation of its arguments. -func HTMLEscaper(args ...interface{}) string { - return HTMLEscapeString(evalArgs(args)) -} - -// JavaScript escaping. - -var ( - jsLowUni = []byte(`\u00`) - hex = []byte("0123456789ABCDEF") - - jsBackslash = []byte(`\\`) - jsApos = []byte(`\'`) - jsQuot = []byte(`\"`) - jsLt = []byte(`\x3C`) - jsGt = []byte(`\x3E`) -) - -// JSEscape writes to w the escaped JavaScript equivalent of the plain text data b. -func JSEscape(w io.Writer, b []byte) { - last := 0 - for i := 0; i < len(b); i++ { - c := b[i] - - if !jsIsSpecial(rune(c)) { - // fast path: nothing to do - continue - } - w.Write(b[last:i]) - - if c < utf8.RuneSelf { - // Quotes, slashes and angle brackets get quoted. - // Control characters get written as \u00XX. - switch c { - case '\\': - w.Write(jsBackslash) - case '\'': - w.Write(jsApos) - case '"': - w.Write(jsQuot) - case '<': - w.Write(jsLt) - case '>': - w.Write(jsGt) - default: - w.Write(jsLowUni) - t, b := c>>4, c&0x0f - w.Write(hex[t : t+1]) - w.Write(hex[b : b+1]) - } - } else { - // Unicode rune. - r, size := utf8.DecodeRune(b[i:]) - if unicode.IsPrint(r) { - w.Write(b[i : i+size]) - } else { - fmt.Fprintf(w, "\\u%04X", r) - } - i += size - 1 - } - last = i + 1 - } - w.Write(b[last:]) -} - -// JSEscapeString returns the escaped JavaScript equivalent of the plain text data s. -func JSEscapeString(s string) string { - // Avoid allocation if we can. - if strings.IndexFunc(s, jsIsSpecial) < 0 { - return s - } - var b bytes.Buffer - JSEscape(&b, []byte(s)) - return b.String() -} - -func jsIsSpecial(r rune) bool { - switch r { - case '\\', '\'', '"', '<', '>': - return true - } - return r < ' ' || utf8.RuneSelf <= r -} - -// JSEscaper returns the escaped JavaScript equivalent of the textual -// representation of its arguments. -func JSEscaper(args ...interface{}) string { - return JSEscapeString(evalArgs(args)) -} - -// URLQueryEscaper returns the escaped value of the textual representation of -// its arguments in a form suitable for embedding in a URL query. -func URLQueryEscaper(args ...interface{}) string { - return url.QueryEscape(evalArgs(args)) -} - -// evalArgs formats the list of arguments into a string. It is therefore equivalent to -// fmt.Sprint(args...) -// except that each argument is indirected (if a pointer), as required, -// using the same rules as the default string evaluation during template -// execution. -func evalArgs(args []interface{}) string { - ok := false - var s string - // Fast path for simple common case. - if len(args) == 1 { - s, ok = args[0].(string) - } - if !ok { - for i, arg := range args { - a, ok := printableValue(reflect.ValueOf(arg)) - if ok { - args[i] = a - } // else left fmt do its thing - } - s = fmt.Sprint(args...) - } - return s -} diff --git a/vendor/github.com/alecthomas/template/helper.go b/vendor/github.com/alecthomas/template/helper.go deleted file mode 100644 index 3636fb54..00000000 --- a/vendor/github.com/alecthomas/template/helper.go +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Helper functions to make constructing templates easier. - -package template - -import ( - "fmt" - "io/ioutil" - "path/filepath" -) - -// Functions and methods to parse templates. - -// Must is a helper that wraps a call to a function returning (*Template, error) -// and panics if the error is non-nil. It is intended for use in variable -// initializations such as -// var t = template.Must(template.New("name").Parse("text")) -func Must(t *Template, err error) *Template { - if err != nil { - panic(err) - } - return t -} - -// ParseFiles creates a new Template and parses the template definitions from -// the named files. The returned template's name will have the (base) name and -// (parsed) contents of the first file. There must be at least one file. -// If an error occurs, parsing stops and the returned *Template is nil. -func ParseFiles(filenames ...string) (*Template, error) { - return parseFiles(nil, filenames...) -} - -// ParseFiles parses the named files and associates the resulting templates with -// t. If an error occurs, parsing stops and the returned template is nil; -// otherwise it is t. There must be at least one file. -func (t *Template) ParseFiles(filenames ...string) (*Template, error) { - return parseFiles(t, filenames...) -} - -// parseFiles is the helper for the method and function. If the argument -// template is nil, it is created from the first file. -func parseFiles(t *Template, filenames ...string) (*Template, error) { - if len(filenames) == 0 { - // Not really a problem, but be consistent. - return nil, fmt.Errorf("template: no files named in call to ParseFiles") - } - for _, filename := range filenames { - b, err := ioutil.ReadFile(filename) - if err != nil { - return nil, err - } - s := string(b) - name := filepath.Base(filename) - // First template becomes return value if not already defined, - // and we use that one for subsequent New calls to associate - // all the templates together. Also, if this file has the same name - // as t, this file becomes the contents of t, so - // t, err := New(name).Funcs(xxx).ParseFiles(name) - // works. Otherwise we create a new template associated with t. - var tmpl *Template - if t == nil { - t = New(name) - } - if name == t.Name() { - tmpl = t - } else { - tmpl = t.New(name) - } - _, err = tmpl.Parse(s) - if err != nil { - return nil, err - } - } - return t, nil -} - -// ParseGlob creates a new Template and parses the template definitions from the -// files identified by the pattern, which must match at least one file. The -// returned template will have the (base) name and (parsed) contents of the -// first file matched by the pattern. ParseGlob is equivalent to calling -// ParseFiles with the list of files matched by the pattern. -func ParseGlob(pattern string) (*Template, error) { - return parseGlob(nil, pattern) -} - -// ParseGlob parses the template definitions in the files identified by the -// pattern and associates the resulting templates with t. The pattern is -// processed by filepath.Glob and must match at least one file. ParseGlob is -// equivalent to calling t.ParseFiles with the list of files matched by the -// pattern. -func (t *Template) ParseGlob(pattern string) (*Template, error) { - return parseGlob(t, pattern) -} - -// parseGlob is the implementation of the function and method ParseGlob. -func parseGlob(t *Template, pattern string) (*Template, error) { - filenames, err := filepath.Glob(pattern) - if err != nil { - return nil, err - } - if len(filenames) == 0 { - return nil, fmt.Errorf("template: pattern matches no files: %#q", pattern) - } - return parseFiles(t, filenames...) -} diff --git a/vendor/github.com/alecthomas/template/parse/lex.go b/vendor/github.com/alecthomas/template/parse/lex.go deleted file mode 100644 index 55f1c051..00000000 --- a/vendor/github.com/alecthomas/template/parse/lex.go +++ /dev/null @@ -1,556 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package parse - -import ( - "fmt" - "strings" - "unicode" - "unicode/utf8" -) - -// item represents a token or text string returned from the scanner. -type item struct { - typ itemType // The type of this item. - pos Pos // The starting position, in bytes, of this item in the input string. - val string // The value of this item. -} - -func (i item) String() string { - switch { - case i.typ == itemEOF: - return "EOF" - case i.typ == itemError: - return i.val - case i.typ > itemKeyword: - return fmt.Sprintf("<%s>", i.val) - case len(i.val) > 10: - return fmt.Sprintf("%.10q...", i.val) - } - return fmt.Sprintf("%q", i.val) -} - -// itemType identifies the type of lex items. -type itemType int - -const ( - itemError itemType = iota // error occurred; value is text of error - itemBool // boolean constant - itemChar // printable ASCII character; grab bag for comma etc. - itemCharConstant // character constant - itemComplex // complex constant (1+2i); imaginary is just a number - itemColonEquals // colon-equals (':=') introducing a declaration - itemEOF - itemField // alphanumeric identifier starting with '.' - itemIdentifier // alphanumeric identifier not starting with '.' - itemLeftDelim // left action delimiter - itemLeftParen // '(' inside action - itemNumber // simple number, including imaginary - itemPipe // pipe symbol - itemRawString // raw quoted string (includes quotes) - itemRightDelim // right action delimiter - itemElideNewline // elide newline after right delim - itemRightParen // ')' inside action - itemSpace // run of spaces separating arguments - itemString // quoted string (includes quotes) - itemText // plain text - itemVariable // variable starting with '$', such as '$' or '$1' or '$hello' - // Keywords appear after all the rest. - itemKeyword // used only to delimit the keywords - itemDot // the cursor, spelled '.' - itemDefine // define keyword - itemElse // else keyword - itemEnd // end keyword - itemIf // if keyword - itemNil // the untyped nil constant, easiest to treat as a keyword - itemRange // range keyword - itemTemplate // template keyword - itemWith // with keyword -) - -var key = map[string]itemType{ - ".": itemDot, - "define": itemDefine, - "else": itemElse, - "end": itemEnd, - "if": itemIf, - "range": itemRange, - "nil": itemNil, - "template": itemTemplate, - "with": itemWith, -} - -const eof = -1 - -// stateFn represents the state of the scanner as a function that returns the next state. -type stateFn func(*lexer) stateFn - -// lexer holds the state of the scanner. -type lexer struct { - name string // the name of the input; used only for error reports - input string // the string being scanned - leftDelim string // start of action - rightDelim string // end of action - state stateFn // the next lexing function to enter - pos Pos // current position in the input - start Pos // start position of this item - width Pos // width of last rune read from input - lastPos Pos // position of most recent item returned by nextItem - items chan item // channel of scanned items - parenDepth int // nesting depth of ( ) exprs -} - -// next returns the next rune in the input. -func (l *lexer) next() rune { - if int(l.pos) >= len(l.input) { - l.width = 0 - return eof - } - r, w := utf8.DecodeRuneInString(l.input[l.pos:]) - l.width = Pos(w) - l.pos += l.width - return r -} - -// peek returns but does not consume the next rune in the input. -func (l *lexer) peek() rune { - r := l.next() - l.backup() - return r -} - -// backup steps back one rune. Can only be called once per call of next. -func (l *lexer) backup() { - l.pos -= l.width -} - -// emit passes an item back to the client. -func (l *lexer) emit(t itemType) { - l.items <- item{t, l.start, l.input[l.start:l.pos]} - l.start = l.pos -} - -// ignore skips over the pending input before this point. -func (l *lexer) ignore() { - l.start = l.pos -} - -// accept consumes the next rune if it's from the valid set. -func (l *lexer) accept(valid string) bool { - if strings.IndexRune(valid, l.next()) >= 0 { - return true - } - l.backup() - return false -} - -// acceptRun consumes a run of runes from the valid set. -func (l *lexer) acceptRun(valid string) { - for strings.IndexRune(valid, l.next()) >= 0 { - } - l.backup() -} - -// lineNumber reports which line we're on, based on the position of -// the previous item returned by nextItem. Doing it this way -// means we don't have to worry about peek double counting. -func (l *lexer) lineNumber() int { - return 1 + strings.Count(l.input[:l.lastPos], "\n") -} - -// errorf returns an error token and terminates the scan by passing -// back a nil pointer that will be the next state, terminating l.nextItem. -func (l *lexer) errorf(format string, args ...interface{}) stateFn { - l.items <- item{itemError, l.start, fmt.Sprintf(format, args...)} - return nil -} - -// nextItem returns the next item from the input. -func (l *lexer) nextItem() item { - item := <-l.items - l.lastPos = item.pos - return item -} - -// lex creates a new scanner for the input string. -func lex(name, input, left, right string) *lexer { - if left == "" { - left = leftDelim - } - if right == "" { - right = rightDelim - } - l := &lexer{ - name: name, - input: input, - leftDelim: left, - rightDelim: right, - items: make(chan item), - } - go l.run() - return l -} - -// run runs the state machine for the lexer. -func (l *lexer) run() { - for l.state = lexText; l.state != nil; { - l.state = l.state(l) - } -} - -// state functions - -const ( - leftDelim = "{{" - rightDelim = "}}" - leftComment = "/*" - rightComment = "*/" -) - -// lexText scans until an opening action delimiter, "{{". -func lexText(l *lexer) stateFn { - for { - if strings.HasPrefix(l.input[l.pos:], l.leftDelim) { - if l.pos > l.start { - l.emit(itemText) - } - return lexLeftDelim - } - if l.next() == eof { - break - } - } - // Correctly reached EOF. - if l.pos > l.start { - l.emit(itemText) - } - l.emit(itemEOF) - return nil -} - -// lexLeftDelim scans the left delimiter, which is known to be present. -func lexLeftDelim(l *lexer) stateFn { - l.pos += Pos(len(l.leftDelim)) - if strings.HasPrefix(l.input[l.pos:], leftComment) { - return lexComment - } - l.emit(itemLeftDelim) - l.parenDepth = 0 - return lexInsideAction -} - -// lexComment scans a comment. The left comment marker is known to be present. -func lexComment(l *lexer) stateFn { - l.pos += Pos(len(leftComment)) - i := strings.Index(l.input[l.pos:], rightComment) - if i < 0 { - return l.errorf("unclosed comment") - } - l.pos += Pos(i + len(rightComment)) - if !strings.HasPrefix(l.input[l.pos:], l.rightDelim) { - return l.errorf("comment ends before closing delimiter") - - } - l.pos += Pos(len(l.rightDelim)) - l.ignore() - return lexText -} - -// lexRightDelim scans the right delimiter, which is known to be present. -func lexRightDelim(l *lexer) stateFn { - l.pos += Pos(len(l.rightDelim)) - l.emit(itemRightDelim) - if l.peek() == '\\' { - l.pos++ - l.emit(itemElideNewline) - } - return lexText -} - -// lexInsideAction scans the elements inside action delimiters. -func lexInsideAction(l *lexer) stateFn { - // Either number, quoted string, or identifier. - // Spaces separate arguments; runs of spaces turn into itemSpace. - // Pipe symbols separate and are emitted. - if strings.HasPrefix(l.input[l.pos:], l.rightDelim+"\\") || strings.HasPrefix(l.input[l.pos:], l.rightDelim) { - if l.parenDepth == 0 { - return lexRightDelim - } - return l.errorf("unclosed left paren") - } - switch r := l.next(); { - case r == eof || isEndOfLine(r): - return l.errorf("unclosed action") - case isSpace(r): - return lexSpace - case r == ':': - if l.next() != '=' { - return l.errorf("expected :=") - } - l.emit(itemColonEquals) - case r == '|': - l.emit(itemPipe) - case r == '"': - return lexQuote - case r == '`': - return lexRawQuote - case r == '$': - return lexVariable - case r == '\'': - return lexChar - case r == '.': - // special look-ahead for ".field" so we don't break l.backup(). - if l.pos < Pos(len(l.input)) { - r := l.input[l.pos] - if r < '0' || '9' < r { - return lexField - } - } - fallthrough // '.' can start a number. - case r == '+' || r == '-' || ('0' <= r && r <= '9'): - l.backup() - return lexNumber - case isAlphaNumeric(r): - l.backup() - return lexIdentifier - case r == '(': - l.emit(itemLeftParen) - l.parenDepth++ - return lexInsideAction - case r == ')': - l.emit(itemRightParen) - l.parenDepth-- - if l.parenDepth < 0 { - return l.errorf("unexpected right paren %#U", r) - } - return lexInsideAction - case r <= unicode.MaxASCII && unicode.IsPrint(r): - l.emit(itemChar) - return lexInsideAction - default: - return l.errorf("unrecognized character in action: %#U", r) - } - return lexInsideAction -} - -// lexSpace scans a run of space characters. -// One space has already been seen. -func lexSpace(l *lexer) stateFn { - for isSpace(l.peek()) { - l.next() - } - l.emit(itemSpace) - return lexInsideAction -} - -// lexIdentifier scans an alphanumeric. -func lexIdentifier(l *lexer) stateFn { -Loop: - for { - switch r := l.next(); { - case isAlphaNumeric(r): - // absorb. - default: - l.backup() - word := l.input[l.start:l.pos] - if !l.atTerminator() { - return l.errorf("bad character %#U", r) - } - switch { - case key[word] > itemKeyword: - l.emit(key[word]) - case word[0] == '.': - l.emit(itemField) - case word == "true", word == "false": - l.emit(itemBool) - default: - l.emit(itemIdentifier) - } - break Loop - } - } - return lexInsideAction -} - -// lexField scans a field: .Alphanumeric. -// The . has been scanned. -func lexField(l *lexer) stateFn { - return lexFieldOrVariable(l, itemField) -} - -// lexVariable scans a Variable: $Alphanumeric. -// The $ has been scanned. -func lexVariable(l *lexer) stateFn { - if l.atTerminator() { // Nothing interesting follows -> "$". - l.emit(itemVariable) - return lexInsideAction - } - return lexFieldOrVariable(l, itemVariable) -} - -// lexVariable scans a field or variable: [.$]Alphanumeric. -// The . or $ has been scanned. -func lexFieldOrVariable(l *lexer, typ itemType) stateFn { - if l.atTerminator() { // Nothing interesting follows -> "." or "$". - if typ == itemVariable { - l.emit(itemVariable) - } else { - l.emit(itemDot) - } - return lexInsideAction - } - var r rune - for { - r = l.next() - if !isAlphaNumeric(r) { - l.backup() - break - } - } - if !l.atTerminator() { - return l.errorf("bad character %#U", r) - } - l.emit(typ) - return lexInsideAction -} - -// atTerminator reports whether the input is at valid termination character to -// appear after an identifier. Breaks .X.Y into two pieces. Also catches cases -// like "$x+2" not being acceptable without a space, in case we decide one -// day to implement arithmetic. -func (l *lexer) atTerminator() bool { - r := l.peek() - if isSpace(r) || isEndOfLine(r) { - return true - } - switch r { - case eof, '.', ',', '|', ':', ')', '(': - return true - } - // Does r start the delimiter? This can be ambiguous (with delim=="//", $x/2 will - // succeed but should fail) but only in extremely rare cases caused by willfully - // bad choice of delimiter. - if rd, _ := utf8.DecodeRuneInString(l.rightDelim); rd == r { - return true - } - return false -} - -// lexChar scans a character constant. The initial quote is already -// scanned. Syntax checking is done by the parser. -func lexChar(l *lexer) stateFn { -Loop: - for { - switch l.next() { - case '\\': - if r := l.next(); r != eof && r != '\n' { - break - } - fallthrough - case eof, '\n': - return l.errorf("unterminated character constant") - case '\'': - break Loop - } - } - l.emit(itemCharConstant) - return lexInsideAction -} - -// lexNumber scans a number: decimal, octal, hex, float, or imaginary. This -// isn't a perfect number scanner - for instance it accepts "." and "0x0.2" -// and "089" - but when it's wrong the input is invalid and the parser (via -// strconv) will notice. -func lexNumber(l *lexer) stateFn { - if !l.scanNumber() { - return l.errorf("bad number syntax: %q", l.input[l.start:l.pos]) - } - if sign := l.peek(); sign == '+' || sign == '-' { - // Complex: 1+2i. No spaces, must end in 'i'. - if !l.scanNumber() || l.input[l.pos-1] != 'i' { - return l.errorf("bad number syntax: %q", l.input[l.start:l.pos]) - } - l.emit(itemComplex) - } else { - l.emit(itemNumber) - } - return lexInsideAction -} - -func (l *lexer) scanNumber() bool { - // Optional leading sign. - l.accept("+-") - // Is it hex? - digits := "0123456789" - if l.accept("0") && l.accept("xX") { - digits = "0123456789abcdefABCDEF" - } - l.acceptRun(digits) - if l.accept(".") { - l.acceptRun(digits) - } - if l.accept("eE") { - l.accept("+-") - l.acceptRun("0123456789") - } - // Is it imaginary? - l.accept("i") - // Next thing mustn't be alphanumeric. - if isAlphaNumeric(l.peek()) { - l.next() - return false - } - return true -} - -// lexQuote scans a quoted string. -func lexQuote(l *lexer) stateFn { -Loop: - for { - switch l.next() { - case '\\': - if r := l.next(); r != eof && r != '\n' { - break - } - fallthrough - case eof, '\n': - return l.errorf("unterminated quoted string") - case '"': - break Loop - } - } - l.emit(itemString) - return lexInsideAction -} - -// lexRawQuote scans a raw quoted string. -func lexRawQuote(l *lexer) stateFn { -Loop: - for { - switch l.next() { - case eof, '\n': - return l.errorf("unterminated raw quoted string") - case '`': - break Loop - } - } - l.emit(itemRawString) - return lexInsideAction -} - -// isSpace reports whether r is a space character. -func isSpace(r rune) bool { - return r == ' ' || r == '\t' -} - -// isEndOfLine reports whether r is an end-of-line character. -func isEndOfLine(r rune) bool { - return r == '\r' || r == '\n' -} - -// isAlphaNumeric reports whether r is an alphabetic, digit, or underscore. -func isAlphaNumeric(r rune) bool { - return r == '_' || unicode.IsLetter(r) || unicode.IsDigit(r) -} diff --git a/vendor/github.com/alecthomas/template/parse/node.go b/vendor/github.com/alecthomas/template/parse/node.go deleted file mode 100644 index 55c37f6d..00000000 --- a/vendor/github.com/alecthomas/template/parse/node.go +++ /dev/null @@ -1,834 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Parse nodes. - -package parse - -import ( - "bytes" - "fmt" - "strconv" - "strings" -) - -var textFormat = "%s" // Changed to "%q" in tests for better error messages. - -// A Node is an element in the parse tree. The interface is trivial. -// The interface contains an unexported method so that only -// types local to this package can satisfy it. -type Node interface { - Type() NodeType - String() string - // Copy does a deep copy of the Node and all its components. - // To avoid type assertions, some XxxNodes also have specialized - // CopyXxx methods that return *XxxNode. - Copy() Node - Position() Pos // byte position of start of node in full original input string - // tree returns the containing *Tree. - // It is unexported so all implementations of Node are in this package. - tree() *Tree -} - -// NodeType identifies the type of a parse tree node. -type NodeType int - -// Pos represents a byte position in the original input text from which -// this template was parsed. -type Pos int - -func (p Pos) Position() Pos { - return p -} - -// Type returns itself and provides an easy default implementation -// for embedding in a Node. Embedded in all non-trivial Nodes. -func (t NodeType) Type() NodeType { - return t -} - -const ( - NodeText NodeType = iota // Plain text. - NodeAction // A non-control action such as a field evaluation. - NodeBool // A boolean constant. - NodeChain // A sequence of field accesses. - NodeCommand // An element of a pipeline. - NodeDot // The cursor, dot. - nodeElse // An else action. Not added to tree. - nodeEnd // An end action. Not added to tree. - NodeField // A field or method name. - NodeIdentifier // An identifier; always a function name. - NodeIf // An if action. - NodeList // A list of Nodes. - NodeNil // An untyped nil constant. - NodeNumber // A numerical constant. - NodePipe // A pipeline of commands. - NodeRange // A range action. - NodeString // A string constant. - NodeTemplate // A template invocation action. - NodeVariable // A $ variable. - NodeWith // A with action. -) - -// Nodes. - -// ListNode holds a sequence of nodes. -type ListNode struct { - NodeType - Pos - tr *Tree - Nodes []Node // The element nodes in lexical order. -} - -func (t *Tree) newList(pos Pos) *ListNode { - return &ListNode{tr: t, NodeType: NodeList, Pos: pos} -} - -func (l *ListNode) append(n Node) { - l.Nodes = append(l.Nodes, n) -} - -func (l *ListNode) tree() *Tree { - return l.tr -} - -func (l *ListNode) String() string { - b := new(bytes.Buffer) - for _, n := range l.Nodes { - fmt.Fprint(b, n) - } - return b.String() -} - -func (l *ListNode) CopyList() *ListNode { - if l == nil { - return l - } - n := l.tr.newList(l.Pos) - for _, elem := range l.Nodes { - n.append(elem.Copy()) - } - return n -} - -func (l *ListNode) Copy() Node { - return l.CopyList() -} - -// TextNode holds plain text. -type TextNode struct { - NodeType - Pos - tr *Tree - Text []byte // The text; may span newlines. -} - -func (t *Tree) newText(pos Pos, text string) *TextNode { - return &TextNode{tr: t, NodeType: NodeText, Pos: pos, Text: []byte(text)} -} - -func (t *TextNode) String() string { - return fmt.Sprintf(textFormat, t.Text) -} - -func (t *TextNode) tree() *Tree { - return t.tr -} - -func (t *TextNode) Copy() Node { - return &TextNode{tr: t.tr, NodeType: NodeText, Pos: t.Pos, Text: append([]byte{}, t.Text...)} -} - -// PipeNode holds a pipeline with optional declaration -type PipeNode struct { - NodeType - Pos - tr *Tree - Line int // The line number in the input (deprecated; kept for compatibility) - Decl []*VariableNode // Variable declarations in lexical order. - Cmds []*CommandNode // The commands in lexical order. -} - -func (t *Tree) newPipeline(pos Pos, line int, decl []*VariableNode) *PipeNode { - return &PipeNode{tr: t, NodeType: NodePipe, Pos: pos, Line: line, Decl: decl} -} - -func (p *PipeNode) append(command *CommandNode) { - p.Cmds = append(p.Cmds, command) -} - -func (p *PipeNode) String() string { - s := "" - if len(p.Decl) > 0 { - for i, v := range p.Decl { - if i > 0 { - s += ", " - } - s += v.String() - } - s += " := " - } - for i, c := range p.Cmds { - if i > 0 { - s += " | " - } - s += c.String() - } - return s -} - -func (p *PipeNode) tree() *Tree { - return p.tr -} - -func (p *PipeNode) CopyPipe() *PipeNode { - if p == nil { - return p - } - var decl []*VariableNode - for _, d := range p.Decl { - decl = append(decl, d.Copy().(*VariableNode)) - } - n := p.tr.newPipeline(p.Pos, p.Line, decl) - for _, c := range p.Cmds { - n.append(c.Copy().(*CommandNode)) - } - return n -} - -func (p *PipeNode) Copy() Node { - return p.CopyPipe() -} - -// ActionNode holds an action (something bounded by delimiters). -// Control actions have their own nodes; ActionNode represents simple -// ones such as field evaluations and parenthesized pipelines. -type ActionNode struct { - NodeType - Pos - tr *Tree - Line int // The line number in the input (deprecated; kept for compatibility) - Pipe *PipeNode // The pipeline in the action. -} - -func (t *Tree) newAction(pos Pos, line int, pipe *PipeNode) *ActionNode { - return &ActionNode{tr: t, NodeType: NodeAction, Pos: pos, Line: line, Pipe: pipe} -} - -func (a *ActionNode) String() string { - return fmt.Sprintf("{{%s}}", a.Pipe) - -} - -func (a *ActionNode) tree() *Tree { - return a.tr -} - -func (a *ActionNode) Copy() Node { - return a.tr.newAction(a.Pos, a.Line, a.Pipe.CopyPipe()) - -} - -// CommandNode holds a command (a pipeline inside an evaluating action). -type CommandNode struct { - NodeType - Pos - tr *Tree - Args []Node // Arguments in lexical order: Identifier, field, or constant. -} - -func (t *Tree) newCommand(pos Pos) *CommandNode { - return &CommandNode{tr: t, NodeType: NodeCommand, Pos: pos} -} - -func (c *CommandNode) append(arg Node) { - c.Args = append(c.Args, arg) -} - -func (c *CommandNode) String() string { - s := "" - for i, arg := range c.Args { - if i > 0 { - s += " " - } - if arg, ok := arg.(*PipeNode); ok { - s += "(" + arg.String() + ")" - continue - } - s += arg.String() - } - return s -} - -func (c *CommandNode) tree() *Tree { - return c.tr -} - -func (c *CommandNode) Copy() Node { - if c == nil { - return c - } - n := c.tr.newCommand(c.Pos) - for _, c := range c.Args { - n.append(c.Copy()) - } - return n -} - -// IdentifierNode holds an identifier. -type IdentifierNode struct { - NodeType - Pos - tr *Tree - Ident string // The identifier's name. -} - -// NewIdentifier returns a new IdentifierNode with the given identifier name. -func NewIdentifier(ident string) *IdentifierNode { - return &IdentifierNode{NodeType: NodeIdentifier, Ident: ident} -} - -// SetPos sets the position. NewIdentifier is a public method so we can't modify its signature. -// Chained for convenience. -// TODO: fix one day? -func (i *IdentifierNode) SetPos(pos Pos) *IdentifierNode { - i.Pos = pos - return i -} - -// SetTree sets the parent tree for the node. NewIdentifier is a public method so we can't modify its signature. -// Chained for convenience. -// TODO: fix one day? -func (i *IdentifierNode) SetTree(t *Tree) *IdentifierNode { - i.tr = t - return i -} - -func (i *IdentifierNode) String() string { - return i.Ident -} - -func (i *IdentifierNode) tree() *Tree { - return i.tr -} - -func (i *IdentifierNode) Copy() Node { - return NewIdentifier(i.Ident).SetTree(i.tr).SetPos(i.Pos) -} - -// VariableNode holds a list of variable names, possibly with chained field -// accesses. The dollar sign is part of the (first) name. -type VariableNode struct { - NodeType - Pos - tr *Tree - Ident []string // Variable name and fields in lexical order. -} - -func (t *Tree) newVariable(pos Pos, ident string) *VariableNode { - return &VariableNode{tr: t, NodeType: NodeVariable, Pos: pos, Ident: strings.Split(ident, ".")} -} - -func (v *VariableNode) String() string { - s := "" - for i, id := range v.Ident { - if i > 0 { - s += "." - } - s += id - } - return s -} - -func (v *VariableNode) tree() *Tree { - return v.tr -} - -func (v *VariableNode) Copy() Node { - return &VariableNode{tr: v.tr, NodeType: NodeVariable, Pos: v.Pos, Ident: append([]string{}, v.Ident...)} -} - -// DotNode holds the special identifier '.'. -type DotNode struct { - NodeType - Pos - tr *Tree -} - -func (t *Tree) newDot(pos Pos) *DotNode { - return &DotNode{tr: t, NodeType: NodeDot, Pos: pos} -} - -func (d *DotNode) Type() NodeType { - // Override method on embedded NodeType for API compatibility. - // TODO: Not really a problem; could change API without effect but - // api tool complains. - return NodeDot -} - -func (d *DotNode) String() string { - return "." -} - -func (d *DotNode) tree() *Tree { - return d.tr -} - -func (d *DotNode) Copy() Node { - return d.tr.newDot(d.Pos) -} - -// NilNode holds the special identifier 'nil' representing an untyped nil constant. -type NilNode struct { - NodeType - Pos - tr *Tree -} - -func (t *Tree) newNil(pos Pos) *NilNode { - return &NilNode{tr: t, NodeType: NodeNil, Pos: pos} -} - -func (n *NilNode) Type() NodeType { - // Override method on embedded NodeType for API compatibility. - // TODO: Not really a problem; could change API without effect but - // api tool complains. - return NodeNil -} - -func (n *NilNode) String() string { - return "nil" -} - -func (n *NilNode) tree() *Tree { - return n.tr -} - -func (n *NilNode) Copy() Node { - return n.tr.newNil(n.Pos) -} - -// FieldNode holds a field (identifier starting with '.'). -// The names may be chained ('.x.y'). -// The period is dropped from each ident. -type FieldNode struct { - NodeType - Pos - tr *Tree - Ident []string // The identifiers in lexical order. -} - -func (t *Tree) newField(pos Pos, ident string) *FieldNode { - return &FieldNode{tr: t, NodeType: NodeField, Pos: pos, Ident: strings.Split(ident[1:], ".")} // [1:] to drop leading period -} - -func (f *FieldNode) String() string { - s := "" - for _, id := range f.Ident { - s += "." + id - } - return s -} - -func (f *FieldNode) tree() *Tree { - return f.tr -} - -func (f *FieldNode) Copy() Node { - return &FieldNode{tr: f.tr, NodeType: NodeField, Pos: f.Pos, Ident: append([]string{}, f.Ident...)} -} - -// ChainNode holds a term followed by a chain of field accesses (identifier starting with '.'). -// The names may be chained ('.x.y'). -// The periods are dropped from each ident. -type ChainNode struct { - NodeType - Pos - tr *Tree - Node Node - Field []string // The identifiers in lexical order. -} - -func (t *Tree) newChain(pos Pos, node Node) *ChainNode { - return &ChainNode{tr: t, NodeType: NodeChain, Pos: pos, Node: node} -} - -// Add adds the named field (which should start with a period) to the end of the chain. -func (c *ChainNode) Add(field string) { - if len(field) == 0 || field[0] != '.' { - panic("no dot in field") - } - field = field[1:] // Remove leading dot. - if field == "" { - panic("empty field") - } - c.Field = append(c.Field, field) -} - -func (c *ChainNode) String() string { - s := c.Node.String() - if _, ok := c.Node.(*PipeNode); ok { - s = "(" + s + ")" - } - for _, field := range c.Field { - s += "." + field - } - return s -} - -func (c *ChainNode) tree() *Tree { - return c.tr -} - -func (c *ChainNode) Copy() Node { - return &ChainNode{tr: c.tr, NodeType: NodeChain, Pos: c.Pos, Node: c.Node, Field: append([]string{}, c.Field...)} -} - -// BoolNode holds a boolean constant. -type BoolNode struct { - NodeType - Pos - tr *Tree - True bool // The value of the boolean constant. -} - -func (t *Tree) newBool(pos Pos, true bool) *BoolNode { - return &BoolNode{tr: t, NodeType: NodeBool, Pos: pos, True: true} -} - -func (b *BoolNode) String() string { - if b.True { - return "true" - } - return "false" -} - -func (b *BoolNode) tree() *Tree { - return b.tr -} - -func (b *BoolNode) Copy() Node { - return b.tr.newBool(b.Pos, b.True) -} - -// NumberNode holds a number: signed or unsigned integer, float, or complex. -// The value is parsed and stored under all the types that can represent the value. -// This simulates in a small amount of code the behavior of Go's ideal constants. -type NumberNode struct { - NodeType - Pos - tr *Tree - IsInt bool // Number has an integral value. - IsUint bool // Number has an unsigned integral value. - IsFloat bool // Number has a floating-point value. - IsComplex bool // Number is complex. - Int64 int64 // The signed integer value. - Uint64 uint64 // The unsigned integer value. - Float64 float64 // The floating-point value. - Complex128 complex128 // The complex value. - Text string // The original textual representation from the input. -} - -func (t *Tree) newNumber(pos Pos, text string, typ itemType) (*NumberNode, error) { - n := &NumberNode{tr: t, NodeType: NodeNumber, Pos: pos, Text: text} - switch typ { - case itemCharConstant: - rune, _, tail, err := strconv.UnquoteChar(text[1:], text[0]) - if err != nil { - return nil, err - } - if tail != "'" { - return nil, fmt.Errorf("malformed character constant: %s", text) - } - n.Int64 = int64(rune) - n.IsInt = true - n.Uint64 = uint64(rune) - n.IsUint = true - n.Float64 = float64(rune) // odd but those are the rules. - n.IsFloat = true - return n, nil - case itemComplex: - // fmt.Sscan can parse the pair, so let it do the work. - if _, err := fmt.Sscan(text, &n.Complex128); err != nil { - return nil, err - } - n.IsComplex = true - n.simplifyComplex() - return n, nil - } - // Imaginary constants can only be complex unless they are zero. - if len(text) > 0 && text[len(text)-1] == 'i' { - f, err := strconv.ParseFloat(text[:len(text)-1], 64) - if err == nil { - n.IsComplex = true - n.Complex128 = complex(0, f) - n.simplifyComplex() - return n, nil - } - } - // Do integer test first so we get 0x123 etc. - u, err := strconv.ParseUint(text, 0, 64) // will fail for -0; fixed below. - if err == nil { - n.IsUint = true - n.Uint64 = u - } - i, err := strconv.ParseInt(text, 0, 64) - if err == nil { - n.IsInt = true - n.Int64 = i - if i == 0 { - n.IsUint = true // in case of -0. - n.Uint64 = u - } - } - // If an integer extraction succeeded, promote the float. - if n.IsInt { - n.IsFloat = true - n.Float64 = float64(n.Int64) - } else if n.IsUint { - n.IsFloat = true - n.Float64 = float64(n.Uint64) - } else { - f, err := strconv.ParseFloat(text, 64) - if err == nil { - n.IsFloat = true - n.Float64 = f - // If a floating-point extraction succeeded, extract the int if needed. - if !n.IsInt && float64(int64(f)) == f { - n.IsInt = true - n.Int64 = int64(f) - } - if !n.IsUint && float64(uint64(f)) == f { - n.IsUint = true - n.Uint64 = uint64(f) - } - } - } - if !n.IsInt && !n.IsUint && !n.IsFloat { - return nil, fmt.Errorf("illegal number syntax: %q", text) - } - return n, nil -} - -// simplifyComplex pulls out any other types that are represented by the complex number. -// These all require that the imaginary part be zero. -func (n *NumberNode) simplifyComplex() { - n.IsFloat = imag(n.Complex128) == 0 - if n.IsFloat { - n.Float64 = real(n.Complex128) - n.IsInt = float64(int64(n.Float64)) == n.Float64 - if n.IsInt { - n.Int64 = int64(n.Float64) - } - n.IsUint = float64(uint64(n.Float64)) == n.Float64 - if n.IsUint { - n.Uint64 = uint64(n.Float64) - } - } -} - -func (n *NumberNode) String() string { - return n.Text -} - -func (n *NumberNode) tree() *Tree { - return n.tr -} - -func (n *NumberNode) Copy() Node { - nn := new(NumberNode) - *nn = *n // Easy, fast, correct. - return nn -} - -// StringNode holds a string constant. The value has been "unquoted". -type StringNode struct { - NodeType - Pos - tr *Tree - Quoted string // The original text of the string, with quotes. - Text string // The string, after quote processing. -} - -func (t *Tree) newString(pos Pos, orig, text string) *StringNode { - return &StringNode{tr: t, NodeType: NodeString, Pos: pos, Quoted: orig, Text: text} -} - -func (s *StringNode) String() string { - return s.Quoted -} - -func (s *StringNode) tree() *Tree { - return s.tr -} - -func (s *StringNode) Copy() Node { - return s.tr.newString(s.Pos, s.Quoted, s.Text) -} - -// endNode represents an {{end}} action. -// It does not appear in the final parse tree. -type endNode struct { - NodeType - Pos - tr *Tree -} - -func (t *Tree) newEnd(pos Pos) *endNode { - return &endNode{tr: t, NodeType: nodeEnd, Pos: pos} -} - -func (e *endNode) String() string { - return "{{end}}" -} - -func (e *endNode) tree() *Tree { - return e.tr -} - -func (e *endNode) Copy() Node { - return e.tr.newEnd(e.Pos) -} - -// elseNode represents an {{else}} action. Does not appear in the final tree. -type elseNode struct { - NodeType - Pos - tr *Tree - Line int // The line number in the input (deprecated; kept for compatibility) -} - -func (t *Tree) newElse(pos Pos, line int) *elseNode { - return &elseNode{tr: t, NodeType: nodeElse, Pos: pos, Line: line} -} - -func (e *elseNode) Type() NodeType { - return nodeElse -} - -func (e *elseNode) String() string { - return "{{else}}" -} - -func (e *elseNode) tree() *Tree { - return e.tr -} - -func (e *elseNode) Copy() Node { - return e.tr.newElse(e.Pos, e.Line) -} - -// BranchNode is the common representation of if, range, and with. -type BranchNode struct { - NodeType - Pos - tr *Tree - Line int // The line number in the input (deprecated; kept for compatibility) - Pipe *PipeNode // The pipeline to be evaluated. - List *ListNode // What to execute if the value is non-empty. - ElseList *ListNode // What to execute if the value is empty (nil if absent). -} - -func (b *BranchNode) String() string { - name := "" - switch b.NodeType { - case NodeIf: - name = "if" - case NodeRange: - name = "range" - case NodeWith: - name = "with" - default: - panic("unknown branch type") - } - if b.ElseList != nil { - return fmt.Sprintf("{{%s %s}}%s{{else}}%s{{end}}", name, b.Pipe, b.List, b.ElseList) - } - return fmt.Sprintf("{{%s %s}}%s{{end}}", name, b.Pipe, b.List) -} - -func (b *BranchNode) tree() *Tree { - return b.tr -} - -func (b *BranchNode) Copy() Node { - switch b.NodeType { - case NodeIf: - return b.tr.newIf(b.Pos, b.Line, b.Pipe, b.List, b.ElseList) - case NodeRange: - return b.tr.newRange(b.Pos, b.Line, b.Pipe, b.List, b.ElseList) - case NodeWith: - return b.tr.newWith(b.Pos, b.Line, b.Pipe, b.List, b.ElseList) - default: - panic("unknown branch type") - } -} - -// IfNode represents an {{if}} action and its commands. -type IfNode struct { - BranchNode -} - -func (t *Tree) newIf(pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) *IfNode { - return &IfNode{BranchNode{tr: t, NodeType: NodeIf, Pos: pos, Line: line, Pipe: pipe, List: list, ElseList: elseList}} -} - -func (i *IfNode) Copy() Node { - return i.tr.newIf(i.Pos, i.Line, i.Pipe.CopyPipe(), i.List.CopyList(), i.ElseList.CopyList()) -} - -// RangeNode represents a {{range}} action and its commands. -type RangeNode struct { - BranchNode -} - -func (t *Tree) newRange(pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) *RangeNode { - return &RangeNode{BranchNode{tr: t, NodeType: NodeRange, Pos: pos, Line: line, Pipe: pipe, List: list, ElseList: elseList}} -} - -func (r *RangeNode) Copy() Node { - return r.tr.newRange(r.Pos, r.Line, r.Pipe.CopyPipe(), r.List.CopyList(), r.ElseList.CopyList()) -} - -// WithNode represents a {{with}} action and its commands. -type WithNode struct { - BranchNode -} - -func (t *Tree) newWith(pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) *WithNode { - return &WithNode{BranchNode{tr: t, NodeType: NodeWith, Pos: pos, Line: line, Pipe: pipe, List: list, ElseList: elseList}} -} - -func (w *WithNode) Copy() Node { - return w.tr.newWith(w.Pos, w.Line, w.Pipe.CopyPipe(), w.List.CopyList(), w.ElseList.CopyList()) -} - -// TemplateNode represents a {{template}} action. -type TemplateNode struct { - NodeType - Pos - tr *Tree - Line int // The line number in the input (deprecated; kept for compatibility) - Name string // The name of the template (unquoted). - Pipe *PipeNode // The command to evaluate as dot for the template. -} - -func (t *Tree) newTemplate(pos Pos, line int, name string, pipe *PipeNode) *TemplateNode { - return &TemplateNode{tr: t, NodeType: NodeTemplate, Pos: pos, Line: line, Name: name, Pipe: pipe} -} - -func (t *TemplateNode) String() string { - if t.Pipe == nil { - return fmt.Sprintf("{{template %q}}", t.Name) - } - return fmt.Sprintf("{{template %q %s}}", t.Name, t.Pipe) -} - -func (t *TemplateNode) tree() *Tree { - return t.tr -} - -func (t *TemplateNode) Copy() Node { - return t.tr.newTemplate(t.Pos, t.Line, t.Name, t.Pipe.CopyPipe()) -} diff --git a/vendor/github.com/alecthomas/template/parse/parse.go b/vendor/github.com/alecthomas/template/parse/parse.go deleted file mode 100644 index 0d77ade8..00000000 --- a/vendor/github.com/alecthomas/template/parse/parse.go +++ /dev/null @@ -1,700 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package parse builds parse trees for templates as defined by text/template -// and html/template. Clients should use those packages to construct templates -// rather than this one, which provides shared internal data structures not -// intended for general use. -package parse - -import ( - "bytes" - "fmt" - "runtime" - "strconv" - "strings" -) - -// Tree is the representation of a single parsed template. -type Tree struct { - Name string // name of the template represented by the tree. - ParseName string // name of the top-level template during parsing, for error messages. - Root *ListNode // top-level root of the tree. - text string // text parsed to create the template (or its parent) - // Parsing only; cleared after parse. - funcs []map[string]interface{} - lex *lexer - token [3]item // three-token lookahead for parser. - peekCount int - vars []string // variables defined at the moment. -} - -// Copy returns a copy of the Tree. Any parsing state is discarded. -func (t *Tree) Copy() *Tree { - if t == nil { - return nil - } - return &Tree{ - Name: t.Name, - ParseName: t.ParseName, - Root: t.Root.CopyList(), - text: t.text, - } -} - -// Parse returns a map from template name to parse.Tree, created by parsing the -// templates described in the argument string. The top-level template will be -// given the specified name. If an error is encountered, parsing stops and an -// empty map is returned with the error. -func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (treeSet map[string]*Tree, err error) { - treeSet = make(map[string]*Tree) - t := New(name) - t.text = text - _, err = t.Parse(text, leftDelim, rightDelim, treeSet, funcs...) - return -} - -// next returns the next token. -func (t *Tree) next() item { - if t.peekCount > 0 { - t.peekCount-- - } else { - t.token[0] = t.lex.nextItem() - } - return t.token[t.peekCount] -} - -// backup backs the input stream up one token. -func (t *Tree) backup() { - t.peekCount++ -} - -// backup2 backs the input stream up two tokens. -// The zeroth token is already there. -func (t *Tree) backup2(t1 item) { - t.token[1] = t1 - t.peekCount = 2 -} - -// backup3 backs the input stream up three tokens -// The zeroth token is already there. -func (t *Tree) backup3(t2, t1 item) { // Reverse order: we're pushing back. - t.token[1] = t1 - t.token[2] = t2 - t.peekCount = 3 -} - -// peek returns but does not consume the next token. -func (t *Tree) peek() item { - if t.peekCount > 0 { - return t.token[t.peekCount-1] - } - t.peekCount = 1 - t.token[0] = t.lex.nextItem() - return t.token[0] -} - -// nextNonSpace returns the next non-space token. -func (t *Tree) nextNonSpace() (token item) { - for { - token = t.next() - if token.typ != itemSpace { - break - } - } - return token -} - -// peekNonSpace returns but does not consume the next non-space token. -func (t *Tree) peekNonSpace() (token item) { - for { - token = t.next() - if token.typ != itemSpace { - break - } - } - t.backup() - return token -} - -// Parsing. - -// New allocates a new parse tree with the given name. -func New(name string, funcs ...map[string]interface{}) *Tree { - return &Tree{ - Name: name, - funcs: funcs, - } -} - -// ErrorContext returns a textual representation of the location of the node in the input text. -// The receiver is only used when the node does not have a pointer to the tree inside, -// which can occur in old code. -func (t *Tree) ErrorContext(n Node) (location, context string) { - pos := int(n.Position()) - tree := n.tree() - if tree == nil { - tree = t - } - text := tree.text[:pos] - byteNum := strings.LastIndex(text, "\n") - if byteNum == -1 { - byteNum = pos // On first line. - } else { - byteNum++ // After the newline. - byteNum = pos - byteNum - } - lineNum := 1 + strings.Count(text, "\n") - context = n.String() - if len(context) > 20 { - context = fmt.Sprintf("%.20s...", context) - } - return fmt.Sprintf("%s:%d:%d", tree.ParseName, lineNum, byteNum), context -} - -// errorf formats the error and terminates processing. -func (t *Tree) errorf(format string, args ...interface{}) { - t.Root = nil - format = fmt.Sprintf("template: %s:%d: %s", t.ParseName, t.lex.lineNumber(), format) - panic(fmt.Errorf(format, args...)) -} - -// error terminates processing. -func (t *Tree) error(err error) { - t.errorf("%s", err) -} - -// expect consumes the next token and guarantees it has the required type. -func (t *Tree) expect(expected itemType, context string) item { - token := t.nextNonSpace() - if token.typ != expected { - t.unexpected(token, context) - } - return token -} - -// expectOneOf consumes the next token and guarantees it has one of the required types. -func (t *Tree) expectOneOf(expected1, expected2 itemType, context string) item { - token := t.nextNonSpace() - if token.typ != expected1 && token.typ != expected2 { - t.unexpected(token, context) - } - return token -} - -// unexpected complains about the token and terminates processing. -func (t *Tree) unexpected(token item, context string) { - t.errorf("unexpected %s in %s", token, context) -} - -// recover is the handler that turns panics into returns from the top level of Parse. -func (t *Tree) recover(errp *error) { - e := recover() - if e != nil { - if _, ok := e.(runtime.Error); ok { - panic(e) - } - if t != nil { - t.stopParse() - } - *errp = e.(error) - } - return -} - -// startParse initializes the parser, using the lexer. -func (t *Tree) startParse(funcs []map[string]interface{}, lex *lexer) { - t.Root = nil - t.lex = lex - t.vars = []string{"$"} - t.funcs = funcs -} - -// stopParse terminates parsing. -func (t *Tree) stopParse() { - t.lex = nil - t.vars = nil - t.funcs = nil -} - -// Parse parses the template definition string to construct a representation of -// the template for execution. If either action delimiter string is empty, the -// default ("{{" or "}}") is used. Embedded template definitions are added to -// the treeSet map. -func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error) { - defer t.recover(&err) - t.ParseName = t.Name - t.startParse(funcs, lex(t.Name, text, leftDelim, rightDelim)) - t.text = text - t.parse(treeSet) - t.add(treeSet) - t.stopParse() - return t, nil -} - -// add adds tree to the treeSet. -func (t *Tree) add(treeSet map[string]*Tree) { - tree := treeSet[t.Name] - if tree == nil || IsEmptyTree(tree.Root) { - treeSet[t.Name] = t - return - } - if !IsEmptyTree(t.Root) { - t.errorf("template: multiple definition of template %q", t.Name) - } -} - -// IsEmptyTree reports whether this tree (node) is empty of everything but space. -func IsEmptyTree(n Node) bool { - switch n := n.(type) { - case nil: - return true - case *ActionNode: - case *IfNode: - case *ListNode: - for _, node := range n.Nodes { - if !IsEmptyTree(node) { - return false - } - } - return true - case *RangeNode: - case *TemplateNode: - case *TextNode: - return len(bytes.TrimSpace(n.Text)) == 0 - case *WithNode: - default: - panic("unknown node: " + n.String()) - } - return false -} - -// parse is the top-level parser for a template, essentially the same -// as itemList except it also parses {{define}} actions. -// It runs to EOF. -func (t *Tree) parse(treeSet map[string]*Tree) (next Node) { - t.Root = t.newList(t.peek().pos) - for t.peek().typ != itemEOF { - if t.peek().typ == itemLeftDelim { - delim := t.next() - if t.nextNonSpace().typ == itemDefine { - newT := New("definition") // name will be updated once we know it. - newT.text = t.text - newT.ParseName = t.ParseName - newT.startParse(t.funcs, t.lex) - newT.parseDefinition(treeSet) - continue - } - t.backup2(delim) - } - n := t.textOrAction() - if n.Type() == nodeEnd { - t.errorf("unexpected %s", n) - } - t.Root.append(n) - } - return nil -} - -// parseDefinition parses a {{define}} ... {{end}} template definition and -// installs the definition in the treeSet map. The "define" keyword has already -// been scanned. -func (t *Tree) parseDefinition(treeSet map[string]*Tree) { - const context = "define clause" - name := t.expectOneOf(itemString, itemRawString, context) - var err error - t.Name, err = strconv.Unquote(name.val) - if err != nil { - t.error(err) - } - t.expect(itemRightDelim, context) - var end Node - t.Root, end = t.itemList() - if end.Type() != nodeEnd { - t.errorf("unexpected %s in %s", end, context) - } - t.add(treeSet) - t.stopParse() -} - -// itemList: -// textOrAction* -// Terminates at {{end}} or {{else}}, returned separately. -func (t *Tree) itemList() (list *ListNode, next Node) { - list = t.newList(t.peekNonSpace().pos) - for t.peekNonSpace().typ != itemEOF { - n := t.textOrAction() - switch n.Type() { - case nodeEnd, nodeElse: - return list, n - } - list.append(n) - } - t.errorf("unexpected EOF") - return -} - -// textOrAction: -// text | action -func (t *Tree) textOrAction() Node { - switch token := t.nextNonSpace(); token.typ { - case itemElideNewline: - return t.elideNewline() - case itemText: - return t.newText(token.pos, token.val) - case itemLeftDelim: - return t.action() - default: - t.unexpected(token, "input") - } - return nil -} - -// elideNewline: -// Remove newlines trailing rightDelim if \\ is present. -func (t *Tree) elideNewline() Node { - token := t.peek() - if token.typ != itemText { - t.unexpected(token, "input") - return nil - } - - t.next() - stripped := strings.TrimLeft(token.val, "\n\r") - diff := len(token.val) - len(stripped) - if diff > 0 { - // This is a bit nasty. We mutate the token in-place to remove - // preceding newlines. - token.pos += Pos(diff) - token.val = stripped - } - return t.newText(token.pos, token.val) -} - -// Action: -// control -// command ("|" command)* -// Left delim is past. Now get actions. -// First word could be a keyword such as range. -func (t *Tree) action() (n Node) { - switch token := t.nextNonSpace(); token.typ { - case itemElse: - return t.elseControl() - case itemEnd: - return t.endControl() - case itemIf: - return t.ifControl() - case itemRange: - return t.rangeControl() - case itemTemplate: - return t.templateControl() - case itemWith: - return t.withControl() - } - t.backup() - // Do not pop variables; they persist until "end". - return t.newAction(t.peek().pos, t.lex.lineNumber(), t.pipeline("command")) -} - -// Pipeline: -// declarations? command ('|' command)* -func (t *Tree) pipeline(context string) (pipe *PipeNode) { - var decl []*VariableNode - pos := t.peekNonSpace().pos - // Are there declarations? - for { - if v := t.peekNonSpace(); v.typ == itemVariable { - t.next() - // Since space is a token, we need 3-token look-ahead here in the worst case: - // in "$x foo" we need to read "foo" (as opposed to ":=") to know that $x is an - // argument variable rather than a declaration. So remember the token - // adjacent to the variable so we can push it back if necessary. - tokenAfterVariable := t.peek() - if next := t.peekNonSpace(); next.typ == itemColonEquals || (next.typ == itemChar && next.val == ",") { - t.nextNonSpace() - variable := t.newVariable(v.pos, v.val) - decl = append(decl, variable) - t.vars = append(t.vars, v.val) - if next.typ == itemChar && next.val == "," { - if context == "range" && len(decl) < 2 { - continue - } - t.errorf("too many declarations in %s", context) - } - } else if tokenAfterVariable.typ == itemSpace { - t.backup3(v, tokenAfterVariable) - } else { - t.backup2(v) - } - } - break - } - pipe = t.newPipeline(pos, t.lex.lineNumber(), decl) - for { - switch token := t.nextNonSpace(); token.typ { - case itemRightDelim, itemRightParen: - if len(pipe.Cmds) == 0 { - t.errorf("missing value for %s", context) - } - if token.typ == itemRightParen { - t.backup() - } - return - case itemBool, itemCharConstant, itemComplex, itemDot, itemField, itemIdentifier, - itemNumber, itemNil, itemRawString, itemString, itemVariable, itemLeftParen: - t.backup() - pipe.append(t.command()) - default: - t.unexpected(token, context) - } - } -} - -func (t *Tree) parseControl(allowElseIf bool, context string) (pos Pos, line int, pipe *PipeNode, list, elseList *ListNode) { - defer t.popVars(len(t.vars)) - line = t.lex.lineNumber() - pipe = t.pipeline(context) - var next Node - list, next = t.itemList() - switch next.Type() { - case nodeEnd: //done - case nodeElse: - if allowElseIf { - // Special case for "else if". If the "else" is followed immediately by an "if", - // the elseControl will have left the "if" token pending. Treat - // {{if a}}_{{else if b}}_{{end}} - // as - // {{if a}}_{{else}}{{if b}}_{{end}}{{end}}. - // To do this, parse the if as usual and stop at it {{end}}; the subsequent{{end}} - // is assumed. This technique works even for long if-else-if chains. - // TODO: Should we allow else-if in with and range? - if t.peek().typ == itemIf { - t.next() // Consume the "if" token. - elseList = t.newList(next.Position()) - elseList.append(t.ifControl()) - // Do not consume the next item - only one {{end}} required. - break - } - } - elseList, next = t.itemList() - if next.Type() != nodeEnd { - t.errorf("expected end; found %s", next) - } - } - return pipe.Position(), line, pipe, list, elseList -} - -// If: -// {{if pipeline}} itemList {{end}} -// {{if pipeline}} itemList {{else}} itemList {{end}} -// If keyword is past. -func (t *Tree) ifControl() Node { - return t.newIf(t.parseControl(true, "if")) -} - -// Range: -// {{range pipeline}} itemList {{end}} -// {{range pipeline}} itemList {{else}} itemList {{end}} -// Range keyword is past. -func (t *Tree) rangeControl() Node { - return t.newRange(t.parseControl(false, "range")) -} - -// With: -// {{with pipeline}} itemList {{end}} -// {{with pipeline}} itemList {{else}} itemList {{end}} -// If keyword is past. -func (t *Tree) withControl() Node { - return t.newWith(t.parseControl(false, "with")) -} - -// End: -// {{end}} -// End keyword is past. -func (t *Tree) endControl() Node { - return t.newEnd(t.expect(itemRightDelim, "end").pos) -} - -// Else: -// {{else}} -// Else keyword is past. -func (t *Tree) elseControl() Node { - // Special case for "else if". - peek := t.peekNonSpace() - if peek.typ == itemIf { - // We see "{{else if ... " but in effect rewrite it to {{else}}{{if ... ". - return t.newElse(peek.pos, t.lex.lineNumber()) - } - return t.newElse(t.expect(itemRightDelim, "else").pos, t.lex.lineNumber()) -} - -// Template: -// {{template stringValue pipeline}} -// Template keyword is past. The name must be something that can evaluate -// to a string. -func (t *Tree) templateControl() Node { - var name string - token := t.nextNonSpace() - switch token.typ { - case itemString, itemRawString: - s, err := strconv.Unquote(token.val) - if err != nil { - t.error(err) - } - name = s - default: - t.unexpected(token, "template invocation") - } - var pipe *PipeNode - if t.nextNonSpace().typ != itemRightDelim { - t.backup() - // Do not pop variables; they persist until "end". - pipe = t.pipeline("template") - } - return t.newTemplate(token.pos, t.lex.lineNumber(), name, pipe) -} - -// command: -// operand (space operand)* -// space-separated arguments up to a pipeline character or right delimiter. -// we consume the pipe character but leave the right delim to terminate the action. -func (t *Tree) command() *CommandNode { - cmd := t.newCommand(t.peekNonSpace().pos) - for { - t.peekNonSpace() // skip leading spaces. - operand := t.operand() - if operand != nil { - cmd.append(operand) - } - switch token := t.next(); token.typ { - case itemSpace: - continue - case itemError: - t.errorf("%s", token.val) - case itemRightDelim, itemRightParen: - t.backup() - case itemPipe: - default: - t.errorf("unexpected %s in operand; missing space?", token) - } - break - } - if len(cmd.Args) == 0 { - t.errorf("empty command") - } - return cmd -} - -// operand: -// term .Field* -// An operand is a space-separated component of a command, -// a term possibly followed by field accesses. -// A nil return means the next item is not an operand. -func (t *Tree) operand() Node { - node := t.term() - if node == nil { - return nil - } - if t.peek().typ == itemField { - chain := t.newChain(t.peek().pos, node) - for t.peek().typ == itemField { - chain.Add(t.next().val) - } - // Compatibility with original API: If the term is of type NodeField - // or NodeVariable, just put more fields on the original. - // Otherwise, keep the Chain node. - // TODO: Switch to Chains always when we can. - switch node.Type() { - case NodeField: - node = t.newField(chain.Position(), chain.String()) - case NodeVariable: - node = t.newVariable(chain.Position(), chain.String()) - default: - node = chain - } - } - return node -} - -// term: -// literal (number, string, nil, boolean) -// function (identifier) -// . -// .Field -// $ -// '(' pipeline ')' -// A term is a simple "expression". -// A nil return means the next item is not a term. -func (t *Tree) term() Node { - switch token := t.nextNonSpace(); token.typ { - case itemError: - t.errorf("%s", token.val) - case itemIdentifier: - if !t.hasFunction(token.val) { - t.errorf("function %q not defined", token.val) - } - return NewIdentifier(token.val).SetTree(t).SetPos(token.pos) - case itemDot: - return t.newDot(token.pos) - case itemNil: - return t.newNil(token.pos) - case itemVariable: - return t.useVar(token.pos, token.val) - case itemField: - return t.newField(token.pos, token.val) - case itemBool: - return t.newBool(token.pos, token.val == "true") - case itemCharConstant, itemComplex, itemNumber: - number, err := t.newNumber(token.pos, token.val, token.typ) - if err != nil { - t.error(err) - } - return number - case itemLeftParen: - pipe := t.pipeline("parenthesized pipeline") - if token := t.next(); token.typ != itemRightParen { - t.errorf("unclosed right paren: unexpected %s", token) - } - return pipe - case itemString, itemRawString: - s, err := strconv.Unquote(token.val) - if err != nil { - t.error(err) - } - return t.newString(token.pos, token.val, s) - } - t.backup() - return nil -} - -// hasFunction reports if a function name exists in the Tree's maps. -func (t *Tree) hasFunction(name string) bool { - for _, funcMap := range t.funcs { - if funcMap == nil { - continue - } - if funcMap[name] != nil { - return true - } - } - return false -} - -// popVars trims the variable list to the specified length -func (t *Tree) popVars(n int) { - t.vars = t.vars[:n] -} - -// useVar returns a node for a variable reference. It errors if the -// variable is not defined. -func (t *Tree) useVar(pos Pos, name string) Node { - v := t.newVariable(pos, name) - for _, varName := range t.vars { - if varName == v.Ident[0] { - return v - } - } - t.errorf("undefined variable %q", v.Ident[0]) - return nil -} diff --git a/vendor/github.com/alecthomas/template/template.go b/vendor/github.com/alecthomas/template/template.go deleted file mode 100644 index 447ed2ab..00000000 --- a/vendor/github.com/alecthomas/template/template.go +++ /dev/null @@ -1,218 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package template - -import ( - "fmt" - "reflect" - - "github.com/alecthomas/template/parse" -) - -// common holds the information shared by related templates. -type common struct { - tmpl map[string]*Template - // We use two maps, one for parsing and one for execution. - // This separation makes the API cleaner since it doesn't - // expose reflection to the client. - parseFuncs FuncMap - execFuncs map[string]reflect.Value -} - -// Template is the representation of a parsed template. The *parse.Tree -// field is exported only for use by html/template and should be treated -// as unexported by all other clients. -type Template struct { - name string - *parse.Tree - *common - leftDelim string - rightDelim string -} - -// New allocates a new template with the given name. -func New(name string) *Template { - return &Template{ - name: name, - } -} - -// Name returns the name of the template. -func (t *Template) Name() string { - return t.name -} - -// New allocates a new template associated with the given one and with the same -// delimiters. The association, which is transitive, allows one template to -// invoke another with a {{template}} action. -func (t *Template) New(name string) *Template { - t.init() - return &Template{ - name: name, - common: t.common, - leftDelim: t.leftDelim, - rightDelim: t.rightDelim, - } -} - -func (t *Template) init() { - if t.common == nil { - t.common = new(common) - t.tmpl = make(map[string]*Template) - t.parseFuncs = make(FuncMap) - t.execFuncs = make(map[string]reflect.Value) - } -} - -// Clone returns a duplicate of the template, including all associated -// templates. The actual representation is not copied, but the name space of -// associated templates is, so further calls to Parse in the copy will add -// templates to the copy but not to the original. Clone can be used to prepare -// common templates and use them with variant definitions for other templates -// by adding the variants after the clone is made. -func (t *Template) Clone() (*Template, error) { - nt := t.copy(nil) - nt.init() - nt.tmpl[t.name] = nt - for k, v := range t.tmpl { - if k == t.name { // Already installed. - continue - } - // The associated templates share nt's common structure. - tmpl := v.copy(nt.common) - nt.tmpl[k] = tmpl - } - for k, v := range t.parseFuncs { - nt.parseFuncs[k] = v - } - for k, v := range t.execFuncs { - nt.execFuncs[k] = v - } - return nt, nil -} - -// copy returns a shallow copy of t, with common set to the argument. -func (t *Template) copy(c *common) *Template { - nt := New(t.name) - nt.Tree = t.Tree - nt.common = c - nt.leftDelim = t.leftDelim - nt.rightDelim = t.rightDelim - return nt -} - -// AddParseTree creates a new template with the name and parse tree -// and associates it with t. -func (t *Template) AddParseTree(name string, tree *parse.Tree) (*Template, error) { - if t.common != nil && t.tmpl[name] != nil { - return nil, fmt.Errorf("template: redefinition of template %q", name) - } - nt := t.New(name) - nt.Tree = tree - t.tmpl[name] = nt - return nt, nil -} - -// Templates returns a slice of the templates associated with t, including t -// itself. -func (t *Template) Templates() []*Template { - if t.common == nil { - return nil - } - // Return a slice so we don't expose the map. - m := make([]*Template, 0, len(t.tmpl)) - for _, v := range t.tmpl { - m = append(m, v) - } - return m -} - -// Delims sets the action delimiters to the specified strings, to be used in -// subsequent calls to Parse, ParseFiles, or ParseGlob. Nested template -// definitions will inherit the settings. An empty delimiter stands for the -// corresponding default: {{ or }}. -// The return value is the template, so calls can be chained. -func (t *Template) Delims(left, right string) *Template { - t.leftDelim = left - t.rightDelim = right - return t -} - -// Funcs adds the elements of the argument map to the template's function map. -// It panics if a value in the map is not a function with appropriate return -// type. However, it is legal to overwrite elements of the map. The return -// value is the template, so calls can be chained. -func (t *Template) Funcs(funcMap FuncMap) *Template { - t.init() - addValueFuncs(t.execFuncs, funcMap) - addFuncs(t.parseFuncs, funcMap) - return t -} - -// Lookup returns the template with the given name that is associated with t, -// or nil if there is no such template. -func (t *Template) Lookup(name string) *Template { - if t.common == nil { - return nil - } - return t.tmpl[name] -} - -// Parse parses a string into a template. Nested template definitions will be -// associated with the top-level template t. Parse may be called multiple times -// to parse definitions of templates to associate with t. It is an error if a -// resulting template is non-empty (contains content other than template -// definitions) and would replace a non-empty template with the same name. -// (In multiple calls to Parse with the same receiver template, only one call -// can contain text other than space, comments, and template definitions.) -func (t *Template) Parse(text string) (*Template, error) { - t.init() - trees, err := parse.Parse(t.name, text, t.leftDelim, t.rightDelim, t.parseFuncs, builtins) - if err != nil { - return nil, err - } - // Add the newly parsed trees, including the one for t, into our common structure. - for name, tree := range trees { - // If the name we parsed is the name of this template, overwrite this template. - // The associate method checks it's not a redefinition. - tmpl := t - if name != t.name { - tmpl = t.New(name) - } - // Even if t == tmpl, we need to install it in the common.tmpl map. - if replace, err := t.associate(tmpl, tree); err != nil { - return nil, err - } else if replace { - tmpl.Tree = tree - } - tmpl.leftDelim = t.leftDelim - tmpl.rightDelim = t.rightDelim - } - return t, nil -} - -// associate installs the new template into the group of templates associated -// with t. It is an error to reuse a name except to overwrite an empty -// template. The two are already known to share the common structure. -// The boolean return value reports wither to store this tree as t.Tree. -func (t *Template) associate(new *Template, tree *parse.Tree) (bool, error) { - if new.common != t.common { - panic("internal error: associate not common") - } - name := new.name - if old := t.tmpl[name]; old != nil { - oldIsEmpty := parse.IsEmptyTree(old.Root) - newIsEmpty := parse.IsEmptyTree(tree.Root) - if newIsEmpty { - // Whether old is empty or not, new is empty; no reason to replace old. - return false, nil - } - if !oldIsEmpty { - return false, fmt.Errorf("template: redefinition of template %q", name) - } - } - t.tmpl[name] = new - return true, nil -} diff --git a/vendor/github.com/alecthomas/units/README.md b/vendor/github.com/alecthomas/units/README.md index bee884e3..57b458ae 100644 --- a/vendor/github.com/alecthomas/units/README.md +++ b/vendor/github.com/alecthomas/units/README.md @@ -1,3 +1,5 @@ +[![Go Reference](https://pkg.go.dev/badge/github.com/alecthomas/units.svg)](https://pkg.go.dev/github.com/alecthomas/units) + # Units - Helpful unit multipliers and functions for Go The goal of this package is to have functionality similar to the [time](http://golang.org/pkg/time/) package. diff --git a/vendor/github.com/alecthomas/units/bytes.go b/vendor/github.com/alecthomas/units/bytes.go index 61d0ca47..f13a842e 100644 --- a/vendor/github.com/alecthomas/units/bytes.go +++ b/vendor/github.com/alecthomas/units/bytes.go @@ -40,9 +40,76 @@ func (b Base2Bytes) String() string { return ToString(int64(b), 1024, "iB", "B") } -var ( - metricBytesUnitMap = MakeUnitMap("B", "B", 1000) -) +// MarshalText implement encoding.TextMarshaler to process json/yaml. +func (b Base2Bytes) MarshalText() ([]byte, error) { + return []byte(b.String()), nil +} + +// UnmarshalText implement encoding.TextUnmarshaler to process json/yaml. +func (b *Base2Bytes) UnmarshalText(text []byte) error { + n, err := ParseBase2Bytes(string(text)) + *b = n + return err +} + +// Floor returns Base2Bytes with all but the largest unit zeroed out. So that e.g. 1GiB1MiB1KiB → 1GiB. +func (b Base2Bytes) Floor() Base2Bytes { + switch { + case b > Exbibyte: + return (b / Exbibyte) * Exbibyte + case b > Pebibyte: + return (b / Pebibyte) * Pebibyte + case b > Tebibyte: + return (b / Tebibyte) * Tebibyte + case b > Gibibyte: + return (b / Gibibyte) * Gibibyte + case b > Mebibyte: + return (b / Mebibyte) * Mebibyte + case b > Kibibyte: + return (b / Kibibyte) * Kibibyte + default: + return b + } +} + +// Round returns Base2Bytes with all but the first n units zeroed out. So that e.g. 1GiB1MiB1KiB → 1GiB1MiB, if n is 2. +func (b Base2Bytes) Round(n int) Base2Bytes { + idx := 0 + + switch { + case b > Exbibyte: + idx = n + case b > Pebibyte: + idx = n + 1 + case b > Tebibyte: + idx = n + 2 + case b > Gibibyte: + idx = n + 3 + case b > Mebibyte: + idx = n + 4 + case b > Kibibyte: + idx = n + 5 + } + + switch idx { + case 1: + return b - b%Exbibyte + case 2: + return b - b%Pebibyte + case 3: + return b - b%Tebibyte + case 4: + return b - b%Gibibyte + case 5: + return b - b%Mebibyte + case 6: + return b - b%Kibibyte + default: + return b + } +} + +var metricBytesUnitMap = MakeUnitMap("B", "B", 1000) // MetricBytes are SI byte units (1000 bytes in a kilobyte). type MetricBytes SI @@ -74,6 +141,63 @@ func (m MetricBytes) String() string { return ToString(int64(m), 1000, "B", "B") } +// Floor returns MetricBytes with all but the largest unit zeroed out. So that e.g. 1GB1MB1KB → 1GB. +func (b MetricBytes) Floor() MetricBytes { + switch { + case b > Exabyte: + return (b / Exabyte) * Exabyte + case b > Petabyte: + return (b / Petabyte) * Petabyte + case b > Terabyte: + return (b / Terabyte) * Terabyte + case b > Gigabyte: + return (b / Gigabyte) * Gigabyte + case b > Megabyte: + return (b / Megabyte) * Megabyte + case b > Kilobyte: + return (b / Kilobyte) * Kilobyte + default: + return b + } +} + +// Round returns MetricBytes with all but the first n units zeroed out. So that e.g. 1GB1MB1KB → 1GB1MB, if n is 2. +func (b MetricBytes) Round(n int) MetricBytes { + idx := 0 + + switch { + case b > Exabyte: + idx = n + case b > Petabyte: + idx = n + 1 + case b > Terabyte: + idx = n + 2 + case b > Gigabyte: + idx = n + 3 + case b > Megabyte: + idx = n + 4 + case b > Kilobyte: + idx = n + 5 + } + + switch idx { + case 1: + return b - b%Exabyte + case 2: + return b - b%Petabyte + case 3: + return b - b%Terabyte + case 4: + return b - b%Gigabyte + case 5: + return b - b%Megabyte + case 6: + return b - b%Kilobyte + default: + return b + } +} + // ParseStrictBytes supports both iB and B suffixes for base 2 and metric, // respectively. That is, KiB represents 1024 and kB, KB represent 1000. func ParseStrictBytes(s string) (int64, error) { diff --git a/vendor/github.com/beevik/ntp/.travis.yml b/vendor/github.com/beevik/ntp/.travis.yml deleted file mode 100644 index e996c276..00000000 --- a/vendor/github.com/beevik/ntp/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: go -sudo: false - -go: - - 1.9.x - - 1.12.x - - tip - -matrix: - allow_failures: - - go: tip - -script: - - go test -v ./... diff --git a/vendor/github.com/beevik/ntp/CONTRIBUTORS b/vendor/github.com/beevik/ntp/CONTRIBUTORS index 626c12eb..714817a5 100644 --- a/vendor/github.com/beevik/ntp/CONTRIBUTORS +++ b/vendor/github.com/beevik/ntp/CONTRIBUTORS @@ -4,4 +4,6 @@ Anton Tolchanov (knyar) Christopher Batey (chbatey) Meng Zhuo (mengzhuo) Leonid Evdokimov (darkk) -Ask Bjørn Hansen (abh) \ No newline at end of file +Ask Bjørn Hansen (abh) +Al Cutter (AlCutter) +Silves-Xiang (silves-xiang) diff --git a/vendor/github.com/beevik/ntp/LICENSE b/vendor/github.com/beevik/ntp/LICENSE index 45d3d495..a404327e 100644 --- a/vendor/github.com/beevik/ntp/LICENSE +++ b/vendor/github.com/beevik/ntp/LICENSE @@ -1,4 +1,4 @@ -Copyright 2015-2017 Brett Vickers. All rights reserved. +Copyright © 2015-2023 Brett Vickers. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions diff --git a/vendor/github.com/beevik/ntp/README.md b/vendor/github.com/beevik/ntp/README.md index f77bb7f0..44e70eab 100644 --- a/vendor/github.com/beevik/ntp/README.md +++ b/vendor/github.com/beevik/ntp/README.md @@ -1,11 +1,11 @@ -[![Build Status](https://travis-ci.org/beevik/ntp.svg?branch=master)](https://travis-ci.org/beevik/ntp) [![GoDoc](https://godoc.org/github.com/beevik/ntp?status.svg)](https://godoc.org/github.com/beevik/ntp) +[![Go](https://github.com/beevik/ntp/actions/workflows/go.yml/badge.svg)](https://github.com/beevik/ntp/actions/workflows/go.yml) ntp === The ntp package is an implementation of a Simple NTP (SNTP) client based on -[RFC5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to +[RFC 5905](https://tools.ietf.org/html/rfc5905). It allows you to connect to a remote NTP server and request information about the current time. @@ -18,44 +18,48 @@ time, err := ntp.Time("0.beevik-ntp.pool.ntp.org") ``` -## Querying time metadata +## Querying time synchronization data -To obtain the current time as well as some additional metadata about the time, +To obtain the current time as well as some additional synchronization data, use the [`Query`](https://godoc.org/github.com/beevik/ntp#Query) function: ```go response, err := ntp.Query("0.beevik-ntp.pool.ntp.org") time := time.Now().Add(response.ClockOffset) ``` -Alternatively, use the [`QueryWithOptions`](https://godoc.org/github.com/beevik/ntp#QueryWithOptions) -function if you want to change the default behavior used by the `Query` -function: -```go -options := ntp.QueryOptions{ Timeout: 30*time.Second, TTL: 5 } -response, err := ntp.QueryWithOptions("0.beevik-ntp.pool.ntp.org", options) -time := time.Now().Add(response.ClockOffset) -``` - The [`Response`](https://godoc.org/github.com/beevik/ntp#Response) structure returned by `Query` includes the following information: -* `Time`: The time the server transmitted its response, according to its own clock. -* `ClockOffset`: The estimated offset of the local system clock relative to the server's clock. For a more accurate time reading, you may add this offset to any subsequent system clock reading. -* `RTT`: An estimate of the round-trip-time delay between the client and the server. +* `ClockOffset`: The estimated offset of the local system clock relative to + the server's clock. For a more accurate time reading, you may add this + offset to any subsequent system clock reading. +* `Time`: The time the server transmitted its response, according to its own + clock. +* `RTT`: An estimate of the round-trip-time delay between the client and the + server. * `Precision`: The precision of the server's clock reading. -* `Stratum`: The server's stratum, which indicates the number of hops from the server to the reference clock. A stratum 1 server is directly attached to the reference clock. If the stratum is zero, the server has responded with the "kiss of death". +* `Stratum`: The server's stratum, which indicates the number of hops from the + server to the reference clock. A stratum 1 server is directly attached to + the reference clock. If the stratum is zero, the server has responded with + the "kiss of death" and you should examine the `KissCode`. * `ReferenceID`: A unique identifier for the consulted reference clock. * `ReferenceTime`: The time at which the server last updated its local clock setting. * `RootDelay`: The server's aggregate round-trip-time delay to the stratum 1 server. -* `RootDispersion`: The server's estimated maximum measurement error relative to the reference clock. -* `RootDistance`: An estimate of the root synchronization distance between the client and the stratum 1 server. -* `Leap`: The leap second indicator, indicating whether a second should be added to or removed from the current month's last minute. -* `MinError`: A lower bound on the clock error between the client and the server. -* `KissCode`: A 4-character string describing the reason for a "kiss of death" response (stratum=0). -* `Poll`: The maximum polling interval between successive messages to the server. +* `RootDispersion`: The server's estimated maximum measurement error relative + to the reference clock. +* `RootDistance`: An estimate of the root synchronization distance between the + client and the stratum 1 server. +* `Leap`: The leap second indicator, indicating whether a second should be + added to or removed from the current month's last minute. +* `MinError`: A lower bound on the clock error between the client and the + server. +* `KissCode`: A 4-character string describing the reason for a "kiss of death" + response (stratum=0). +* `Poll`: The maximum polling interval between successive messages to the + server. The `Response` structure's [`Validate`](https://godoc.org/github.com/beevik/ntp#Response.Validate) -method performs additional sanity checks to determine whether the response is -suitable for time synchronization purposes. +function performs additional sanity checks to determine whether the response +is suitable for time synchronization purposes. ```go err := response.Validate() if err == nil { @@ -63,10 +67,44 @@ if err == nil { } ``` +If you wish to customize the behavior of the NTP query, use the +[`QueryWithOptions`](https://godoc.org/github.com/beevik/ntp#QueryWithOptions) +function: +```go +options := ntp.QueryOptions{ Timeout: 30*time.Second, TTL: 5 } +response, err := ntp.QueryWithOptions("0.beevik-ntp.pool.ntp.org", options) +time := time.Now().Add(response.ClockOffset) +``` + +Configurable [`QueryOptions`](https://godoc.org/github.com/beevik/ntp#QueryOptions) +include: +* `Timeout`: How long to wait before giving up on a response from the NTP + server. +* `Version`: Which version of the NTP protocol to use (2, 3 or 4). +* `TTL`: The maximum number of IP hops before the request packet is discarded. +* `Auth`: The symmetric authentication key and algorithm used by the server to + authenticate the query. The same information is used by the client to + authenticate the server's response. +* `Extensions`: Extensions may be added to modify NTP queries before they are + transmitted and to process NTP responses after they arrive. +* `Dialer`: A custom network connection "dialer" function used to override the + default UDP dialer function. + + ## Using the NTP pool -The NTP pool is a shared resource used by people all over the world. -To prevent it from becoming overloaded, please avoid querying the standard -`pool.ntp.org` zone names in your applications. Instead, consider requesting -your own [vendor zone](http://www.pool.ntp.org/en/vendors.html) or [joining -the pool](http://www.pool.ntp.org/join.html). +The NTP pool is a shared resource provided by the [NTP Pool +Project](https://www.pool.ntp.org/en/) and used by people and services all +over the world. To prevent it from becoming overloaded, please avoid querying +the standard `pool.ntp.org` zone names in your applications. Instead, consider +requesting your own [vendor zone](http://www.pool.ntp.org/en/vendors.html) or +[joining the pool](http://www.pool.ntp.org/join.html). + + +## Network Time Security (NTS) + +Network Time Security (NTS) is a recent enhancement of NTP, designed to add +better authentication and message integrity to the protocol. It is defined by +[RFC 8915](https://tools.ietf.org/html/rfc8915). If you wish to use NTS, see +the [nts package](https://github.com/beevik/nts). (The nts package is +implemented as an extension to this package.) diff --git a/vendor/github.com/beevik/ntp/RELEASE_NOTES.md b/vendor/github.com/beevik/ntp/RELEASE_NOTES.md index 932f1019..860298cc 100644 --- a/vendor/github.com/beevik/ntp/RELEASE_NOTES.md +++ b/vendor/github.com/beevik/ntp/RELEASE_NOTES.md @@ -1,3 +1,91 @@ +Release v1.3.1 +============== + +**Changes** + +* Added AES-256-CMAC support for symmetric authentication. +* Symmetric auth keys may now be specified as ASCII or HEX using the "ASCII:" + or "HEX:" prefixes. +* Updated dependencies to address security issues. + +**Fixes** + +* Added proper handling of the empty string when used as a server address. + +Release v1.3.0 +============== + +**Changes** + +* Added the `ReferenceString` function to `Response`. This generates a + stratum-specific string for the `ReferenceID` value. +* Optimized the AES CMAC calculation for 64-bit architectures. + +**Fixes** + +* Fixed a bug introduced in release v1.2.0 that was causing IPv6 addresses + to be interpreted incorrectly. + +Release v1.2.0 +============== + +**Changes** + +* Added support for NTP extensions by exposing an extension interface. + Extensions are able to (1) modify NTP messages before being sent to + the server, and (2) process NTP messages after they arrive from the + server. This feature has been added in preparation for NTS support. +* Added support for RFC 5905 symmetric key authentication. +* Allowed server address to be specified as a "host:port" pair. +* Brought package into further compliance with IETF draft on client data + minimization. +* Declared error variables as part of the public API. +* Added a `Dialer` field to `QueryOptions`. This replaces the deprecated + `Dial` field. +* Added an `IsKissOfDeath` function to the `Response` type. + +**Deprecated** + +* Deprecated the `Port` field in QueryOptions. +* Deprecated the `Dial` field in QueryOptions. + +Release v1.1.1 +============== + +**Fixes** + +* Fixed a missing indirect go module dependency. + +Release v1.1.0 +============== + +**Changes** + +* Added the `Dial` property to the `QueryOptions` struct. This allows the user + to override the default UDP dialer when setting up a connection to a remote + NTP server. + +Release v1.0.0 +============== + +This package has been stable for several years with no bug reports in that +time. It is also pretty much feature complete. I am therefore updating the +version to 1.0.0. + +Because this is a major release, all previously deprecated code has been +removed from the package. + +**Breaking changes** + +* Removed the `TimeV` function. Use `Time` or `QueryWithOptions` instead. + +Release v0.3.2 +============== + +**Changes** + +* Rename unit tests to enable easier test filtering. + Release v0.3.0 ============== @@ -41,24 +129,38 @@ Release v0.1.1 Release v0.1.0 ============== -This is the initial release of the `ntp` package. Currently it supports the following features: +This is the initial release of the `ntp` package. Currently it supports the +following features: * `Time()` to query the current time according to a remote NTP server. -* `Query()` to query multiple pieces of time-related information from a remote NTP server. -* `QueryWithOptions()`, which is like `Query()` but with the ability to override default query options. +* `Query()` to query multiple pieces of time-related information from a remote + NTP server. +* `QueryWithOptions()`, which is like `Query()` but with the ability to + override default query options. Time-related information returned by the `Query` functions includes: -* `Time`: the time the server transmitted its response, according to the server's clock. -* `ClockOffset`: the estimated offset of the client's clock relative to the server's clock. You may apply this offset to any local system clock reading once the query is complete. -* `RTT`: an estimate of the round-trip-time delay between the client and the server. +* `Time`: the time the server transmitted its response, according to the + server's clock. +* `ClockOffset`: the estimated offset of the client's clock relative to the + server's clock. You may apply this offset to any local system clock reading + once the query is complete. +* `RTT`: an estimate of the round-trip-time delay between the client and the + server. * `Precision`: the precision of the server's clock reading. -* `Stratum`: the "stratum" level of the server, where 1 indicates a server directly connected to a reference clock, and values greater than 1 indicating the number of hops from the reference clock. +* `Stratum`: the "stratum" level of the server, where 1 indicates a server + directly connected to a reference clock, and values greater than 1 + indicating the number of hops from the reference clock. * `ReferenceID`: A unique identifier for the NTP server that was contacted. -* `ReferenceTime`: The time at which the server last updated its local clock setting. +* `ReferenceTime`: The time at which the server last updated its local clock + setting. * `RootDelay`: The server's round-trip delay to the reference clock. * `RootDispersion`: The server's total dispersion to the referenced clock. * `RootDistance`: An estimate of the root synchronization distance. * `Leap`: The leap second indicator. -* `MinError`: A lower bound on the clock error between the client and the server. -* `Poll`: the maximum polling interval between successive messages on the server. - -The `Response` structure returned by the `Query` functions also contains a `Response.Validate()` function that returns an error if any of the fields returned by the server are invalid. +* `MinError`: A lower bound on the clock error between the client and the + server. +* `Poll`: the maximum polling interval between successive messages on the + server. + +The `Response` structure returned by the `Query` functions also contains a +`Response.Validate()` function that returns an error if any of the fields +returned by the server are invalid. diff --git a/vendor/github.com/beevik/ntp/auth.go b/vendor/github.com/beevik/ntp/auth.go new file mode 100644 index 00000000..63653817 --- /dev/null +++ b/vendor/github.com/beevik/ntp/auth.go @@ -0,0 +1,240 @@ +// Copyright © 2015-2023 Brett Vickers. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package ntp + +import ( + "bytes" + "crypto/aes" + "crypto/md5" + "crypto/sha1" + "crypto/sha256" + "crypto/sha512" + "crypto/subtle" + "encoding/binary" + "encoding/hex" +) + +// AuthType specifies the cryptographic hash algorithm used to generate a +// symmetric key authentication digest (or CMAC) for an NTP message. Please +// note that MD5 and SHA1 are no longer considered secure; they appear here +// solely for compatibility with existing NTP server implementations. +type AuthType int + +const ( + AuthNone AuthType = iota // no authentication + AuthMD5 // MD5 digest + AuthSHA1 // SHA-1 digest + AuthSHA256 // SHA-2 digest (256 bits) + AuthSHA512 // SHA-2 digest (512 bits) + AuthAES128 // AES-128-CMAC + AuthAES256 // AES-256-CMAC +) + +// AuthOptions contains fields used to configure symmetric key authentication +// for an NTP query. +type AuthOptions struct { + // Type determines the cryptographic hash algorithm used to compute the + // authentication digest or CMAC. + Type AuthType + + // The cryptographic key used by the client to perform authentication. The + // key may be hex-encoded or ascii-encoded. To use a hex-encoded key, + // prefix it by "HEX:". To use an ascii-encoded key, prefix it by + // "ASCII:". For example, "HEX:6931564b4a5a5045766c55356b30656c7666316c" + // or "ASCII:cvuZyN4C8HX8hNcAWDWp". + Key string + + // The identifier used by the NTP server to identify which key to use + // for authentication purposes. + KeyID uint16 +} + +var algorithms = []struct { + MinKeySize int + MaxKeySize int + DigestSize int + CalcDigest func(payload, key []byte) []byte +}{ + {0, 0, 0, nil}, // AuthNone + {4, 32, 16, calcDigest_MD5}, // AuthMD5 + {4, 32, 20, calcDigest_SHA1}, // AuthSHA1 + {4, 32, 20, calcDigest_SHA256}, // AuthSHA256 + {4, 32, 20, calcDigest_SHA512}, // AuthSHA512 + {16, 16, 16, calcCMAC_AES}, // AuthAES128 + {32, 32, 16, calcCMAC_AES}, // AuthAES256 +} + +func calcDigest_MD5(payload, key []byte) []byte { + digest := md5.Sum(append(key, payload...)) + return digest[:] +} + +func calcDigest_SHA1(payload, key []byte) []byte { + digest := sha1.Sum(append(key, payload...)) + return digest[:] +} + +func calcDigest_SHA256(payload, key []byte) []byte { + digest := sha256.Sum256(append(key, payload...)) + return digest[:20] +} + +func calcDigest_SHA512(payload, key []byte) []byte { + digest := sha512.Sum512(append(key, payload...)) + return digest[:20] +} + +func calcCMAC_AES(payload, key []byte) []byte { + // calculate the CMAC according to the algorithm defined in RFC 4493. See + // https://tools.ietf.org/html/rfc4493 for details. + c, err := aes.NewCipher(key) + if err != nil { + panic(err) + } + + // Generate subkeys. + const rb = 0x87 + k1 := make([]byte, 16) + k2 := make([]byte, 16) + c.Encrypt(k1, k1) + double(k1, k1, rb) + double(k2, k1, rb) + + // Process all but the last block. + cmac := make([]byte, 16) + for ; len(payload) > 16; payload = payload[16:] { + xor(cmac, payload[:16]) + c.Encrypt(cmac, cmac) + } + + // Process the last block, padding as necessary. + if len(payload) == 16 { + xor(cmac, payload) + xor(cmac, k1) + } else { + xor(cmac, pad(payload)) + xor(cmac, k2) + } + c.Encrypt(cmac, cmac) + + return cmac +} + +func pad(block []byte) []byte { + pad := make([]byte, 16-len(block)) + pad[0] = 0x80 + return append(block, pad...) +} + +func double(dst, src []byte, xor int) { + _ = src[15] // compiler hint: bounds check + s0 := binary.BigEndian.Uint64(src[0:8]) + s1 := binary.BigEndian.Uint64(src[8:16]) + + carry := int(s0 >> 63) + d0 := (s0 << 1) | (s1 >> 63) + d1 := (s1 << 1) ^ uint64(subtle.ConstantTimeSelect(carry, xor, 0)) + + _ = dst[15] // compiler hint: bounds check + binary.BigEndian.PutUint64(dst[0:8], d0) + binary.BigEndian.PutUint64(dst[8:16], d1) +} + +func xor(dst, src []byte) { + _ = src[15] // compiler hint: bounds check + s0 := binary.BigEndian.Uint64(src[0:8]) + s1 := binary.BigEndian.Uint64(src[8:16]) + + _ = dst[15] // compiler hint: bounds check + d0 := s0 ^ binary.BigEndian.Uint64(dst[0:8]) + d1 := s1 ^ binary.BigEndian.Uint64(dst[8:16]) + + binary.BigEndian.PutUint64(dst[0:8], d0) + binary.BigEndian.PutUint64(dst[8:16], d1) +} + +func decodeAuthKey(opt AuthOptions) (key []byte, err error) { + if opt.Type == AuthNone { + return nil, nil + } + + var keyIn string + var isHex bool + switch { + case len(opt.Key) >= 4 && opt.Key[:4] == "HEX:": + isHex, keyIn = true, opt.Key[4:] + case len(opt.Key) >= 6 && opt.Key[:6] == "ASCII:": + isHex, keyIn = false, opt.Key[6:] + case len(opt.Key) > 20: + isHex, keyIn = true, opt.Key + default: + isHex, keyIn = false, opt.Key + } + + if isHex { + key, err = hex.DecodeString(keyIn) + if err != nil { + return nil, ErrInvalidAuthKey + } + } else { + key = []byte(keyIn) + } + + a := algorithms[opt.Type] + if len(key) < a.MinKeySize { + return nil, ErrInvalidAuthKey + } + if len(key) > a.MaxKeySize { + key = key[:a.MaxKeySize] + } + + return key, nil +} + +func appendMAC(buf *bytes.Buffer, opt AuthOptions, key []byte) { + if opt.Type == AuthNone { + return + } + + a := algorithms[opt.Type] + payload := buf.Bytes() + digest := a.CalcDigest(payload, key) + binary.Write(buf, binary.BigEndian, uint32(opt.KeyID)) + binary.Write(buf, binary.BigEndian, digest) +} + +func verifyMAC(buf []byte, opt AuthOptions, key []byte) error { + if opt.Type == AuthNone { + return nil + } + + // Validate that there are enough bytes at the end of the message to + // contain a MAC. + const headerSize = 48 + a := algorithms[opt.Type] + macLen := 4 + a.DigestSize + remain := len(buf) - headerSize + if remain < macLen || (remain%4) != 0 { + return ErrAuthFailed + } + + // The key ID returned by the server must be the same as the key ID sent + // to the server. + payloadLen := len(buf) - macLen + mac := buf[payloadLen:] + keyID := binary.BigEndian.Uint32(mac[:4]) + if keyID != uint32(opt.KeyID) { + return ErrAuthFailed + } + + // Calculate and compare digests. + payload := buf[:payloadLen] + digest := a.CalcDigest(payload, key) + if subtle.ConstantTimeCompare(digest, mac[4:]) != 1 { + return ErrAuthFailed + } + + return nil +} diff --git a/vendor/github.com/beevik/ntp/ntp.go b/vendor/github.com/beevik/ntp/ntp.go index d8b4952c..535a289e 100644 --- a/vendor/github.com/beevik/ntp/ntp.go +++ b/vendor/github.com/beevik/ntp/ntp.go @@ -1,26 +1,45 @@ -// Copyright 2015-2017 Brett Vickers. +// Copyright © 2015-2023 Brett Vickers. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package ntp provides an implementation of a Simple NTP (SNTP) client // capable of querying the current time from a remote NTP server. See -// RFC5905 (https://tools.ietf.org/html/rfc5905) for more details. +// RFC 5905 (https://tools.ietf.org/html/rfc5905) for more details. // // This approach grew out of a go-nuts post by Michael Hofmann: // https://groups.google.com/forum/?fromgroups#!topic/golang-nuts/FlcdMU5fkLQ package ntp import ( + "bytes" "crypto/rand" "encoding/binary" "errors" "fmt" "net" + "strconv" + "strings" "time" "golang.org/x/net/ipv4" ) +var ( + ErrAuthFailed = errors.New("authentication failed") + ErrInvalidAuthKey = errors.New("invalid authentication key") + ErrInvalidDispersion = errors.New("invalid dispersion in response") + ErrInvalidLeapSecond = errors.New("invalid leap second in response") + ErrInvalidMode = errors.New("invalid mode in response") + ErrInvalidProtocolVersion = errors.New("invalid protocol version requested") + ErrInvalidStratum = errors.New("invalid stratum in response") + ErrInvalidTime = errors.New("invalid time reported") + ErrInvalidTransmitTime = errors.New("invalid transmit time in response") + ErrKissOfDeath = errors.New("kiss of death received") + ErrServerClockFreshness = errors.New("server clock not fresh") + ErrServerResponseMismatch = errors.New("server response didn't match request") + ErrServerTickedBackwards = errors.New("server clock ticked backwards") +) + // The LeapIndicator is used to warn if a leap second should be inserted // or deleted in the last minute of the current month. type LeapIndicator uint8 @@ -42,6 +61,7 @@ const ( // Internal constants const ( defaultNtpVersion = 4 + defaultNtpPort = 123 nanoPerSec = 1000000000 maxStratum = 16 defaultTimeout = 5 * time.Second @@ -119,71 +139,119 @@ func (t ntpTimeShort) Duration() time.Duration { return time.Duration(sec + nsec) } -// msg is an internal representation of an NTP packet. -type msg struct { +// header is an internal representation of an NTP packet header. +type header struct { LiVnMode uint8 // Leap Indicator (2) + Version (3) + Mode (3) Stratum uint8 Poll int8 Precision int8 RootDelay ntpTimeShort RootDispersion ntpTimeShort - ReferenceID uint32 + ReferenceID uint32 // KoD code if Stratum == 0 ReferenceTime ntpTime OriginTime ntpTime ReceiveTime ntpTime TransmitTime ntpTime } -// setVersion sets the NTP protocol version on the message. -func (m *msg) setVersion(v int) { - m.LiVnMode = (m.LiVnMode & 0xc7) | uint8(v)<<3 +// setVersion sets the NTP protocol version on the header. +func (h *header) setVersion(v int) { + h.LiVnMode = (h.LiVnMode & 0xc7) | uint8(v)<<3 } -// setMode sets the NTP protocol mode on the message. -func (m *msg) setMode(md mode) { - m.LiVnMode = (m.LiVnMode & 0xf8) | uint8(md) +// setMode sets the NTP protocol mode on the header. +func (h *header) setMode(md mode) { + h.LiVnMode = (h.LiVnMode & 0xf8) | uint8(md) } -// setLeap modifies the leap indicator on the message. -func (m *msg) setLeap(li LeapIndicator) { - m.LiVnMode = (m.LiVnMode & 0x3f) | uint8(li)<<6 +// setLeap modifies the leap indicator on the header. +func (h *header) setLeap(li LeapIndicator) { + h.LiVnMode = (h.LiVnMode & 0x3f) | uint8(li)<<6 } -// getVersion returns the version value in the message. -func (m *msg) getVersion() int { - return int((m.LiVnMode >> 3) & 0x07) +// getMode returns the mode value in the header. +func (h *header) getMode() mode { + return mode(h.LiVnMode & 0x07) } -// getMode returns the mode value in the message. -func (m *msg) getMode() mode { - return mode(m.LiVnMode & 0x07) +// getLeap returns the leap indicator on the header. +func (h *header) getLeap() LeapIndicator { + return LeapIndicator((h.LiVnMode >> 6) & 0x03) } -// getLeap returns the leap indicator on the message. -func (m *msg) getLeap() LeapIndicator { - return LeapIndicator((m.LiVnMode >> 6) & 0x03) +// An Extension adds custom behaviors capable of modifying NTP packets before +// being sent to the server and processing packets after being received by the +// server. +type Extension interface { + // ProcessQuery is called when the client is about to send a query to the + // NTP server. The buffer contains the NTP header. It may also contain + // extension fields added by extensions processed prior to this one. + ProcessQuery(buf *bytes.Buffer) error + + // ProcessResponse is called after the client has received the server's + // NTP response. The buffer contains the entire message returned by the + // server. + ProcessResponse(buf []byte) error } -// QueryOptions contains the list of configurable options that may be used -// with the QueryWithOptions function. +// QueryOptions contains configurable options used by the QueryWithOptions +// function. type QueryOptions struct { - Timeout time.Duration // defaults to 5 seconds - Version int // NTP protocol version, defaults to 4 - LocalAddress string // IP address to use for the client address - Port int // Server port, defaults to 123 - TTL int // IP TTL to use, defaults to system default + // Timeout determines how long the client waits for a response from the + // server before failing with a timeout error. Defaults to 5 seconds. + Timeout time.Duration + + // Version of the NTP protocol to use. Defaults to 4. + Version int + + // LocalAddress contains the local IP address to use when creating a + // connection to the remote NTP server. This may be useful when the local + // system has more than one IP address. This address should not contain + // a port number. + LocalAddress string + + // TTL specifies the maximum number of IP hops before the query datagram + // is dropped by the network. Defaults to the local system's default value. + TTL int + + // Auth contains the settings used to configure NTP symmetric key + // authentication. See RFC 5905 for further details. + Auth AuthOptions + + // Extensions may be added to modify NTP queries before they are + // transmitted and to process NTP responses after they arrive. + Extensions []Extension + + // Dialer is a callback used to override the default UDP network dialer. + // The localAddress is directly copied from the LocalAddress field + // specified in QueryOptions. It may be the empty string or a host address + // (without port number). The remoteAddress is the "host:port" string + // derived from the first parameter to QueryWithOptions. The + // remoteAddress is guaranteed to include a port number. + Dialer func(localAddress, remoteAddress string) (net.Conn, error) + + // Dial is a callback used to override the default UDP network dialer. + // + // DEPRECATED. Use Dialer instead. + Dial func(laddr string, lport int, raddr string, rport int) (net.Conn, error) + + // Port indicates the port used to reach the remote NTP server. + // + // DEPRECATED. Embed the port number in the query address string instead. + Port int } // A Response contains time data, some of which is returned by the NTP server -// and some of which is calculated by the client. +// and some of which is calculated by this client. type Response struct { // Time is the transmit time reported by the server just before it - // responded to the client's NTP query. + // responded to the client's NTP query. You should not use this value + // for time synchronization purposes. Use the ClockOffset instead. Time time.Time - // ClockOffset is the estimated offset of the client clock relative to - // the server. Add this to the client's system clock time to obtain a - // more accurate time. + // ClockOffset is the estimated offset of the local system clock relative + // to the server's clock. Add this value to subsequent local system time + // measurements in order to obtain a more accurate time. ClockOffset time.Duration // RTT is the measured round-trip-time delay estimate between the client @@ -200,8 +268,13 @@ type Response struct { // issues too many requests to the server in a short period of time. Stratum uint8 - // ReferenceID is a 32-bit identifier identifying the server or - // reference clock. + // ReferenceID is a 32-bit integer identifying the server or reference + // clock. For stratum 1 servers, this is typically a meaningful + // zero-padded ASCII-encoded string assigned to the clock. For stratum 2+ + // servers, this is a reference identifier for the server and is either + // the server's IPv4 address or a hash of its IPv6 address. For + // kiss-of-death responses (stratum 0), this is the ASCII-encoded "kiss + // code". ReferenceID uint32 // ReferenceTime is the time when the server's system clock was last @@ -233,36 +306,79 @@ type Response struct { MinError time.Duration // KissCode is a 4-character string describing the reason for a - // "kiss of death" response (stratum = 0). For a list of standard kiss + // "kiss of death" response (stratum=0). For a list of standard kiss // codes, see https://tools.ietf.org/html/rfc5905#section-7.4. KissCode string - // Poll is the maximum interval between successive NTP polling messages. - // It is not relevant for simple NTP clients like this one. + // Poll is the maximum interval between successive NTP query messages to + // the server. Poll time.Duration + + authErr error +} + +// IsKissOfDeath returns true if the response is a "kiss of death" from the +// remote server. If this function returns true, you may examine the +// response's KissCode value to determine the reason for the kiss of death. +func (r *Response) IsKissOfDeath() bool { + return r.Stratum == 0 +} + +// ReferenceString returns the response's ReferenceID value formatted as a +// string. If the response's stratum is zero, then the "kiss o' death" string +// is returned. If stratum is one, then the server is a reference clock and +// the reference clock's name is returned. If stratum is two or greater, then +// the ID is either an IPv4 address or an MD5 hash of the IPv6 address; in +// either case the reference string is reported as 4 dot-separated +// decimal-based integers. +func (r *Response) ReferenceString() string { + if r.Stratum == 0 { + return kissCode(r.ReferenceID) + } + + var b [4]byte + binary.BigEndian.PutUint32(b[:], r.ReferenceID) + + if r.Stratum == 1 { + const dot = rune(0x22c5) + var r []rune + for i := range b { + if b[i] == 0 { + break + } + if b[i] >= 32 && b[i] <= 126 { + r = append(r, rune(b[i])) + } else { + r = append(r, dot) + } + } + return fmt.Sprintf(".%s.", string(r)) + } + + return fmt.Sprintf("%d.%d.%d.%d", b[0], b[1], b[2], b[3]) } // Validate checks if the response is valid for the purposes of time // synchronization. func (r *Response) Validate() error { + // Forward authentication errors. + if r.authErr != nil { + return r.authErr + } + // Handle invalid stratum values. if r.Stratum == 0 { - return fmt.Errorf("kiss of death received: %s", r.KissCode) + return ErrKissOfDeath } if r.Stratum >= maxStratum { - return errors.New("invalid stratum in response") - } - - // Handle invalid leap second indicator. - if r.Leap == LeapNotInSync { - return errors.New("invalid leap second") + return ErrInvalidStratum } // Estimate the "freshness" of the time. If it exceeds the maximum // polling interval (~36 hours), then it cannot be considered "fresh". freshness := r.Time.Sub(r.ReferenceTime) if freshness > maxPollInterval { - return errors.New("server clock not fresh") + return ErrServerClockFreshness } // Calculate the peer synchronization distance, lambda: @@ -272,95 +388,106 @@ func (r *Response) Validate() error { // https://tools.ietf.org/html/rfc5905#appendix-A.5.1.1. lambda := r.RootDelay/2 + r.RootDispersion if lambda > maxDispersion { - return errors.New("invalid dispersion") + return ErrInvalidDispersion } // If the server's transmit time is before its reference time, the // response is invalid. if r.Time.Before(r.ReferenceTime) { - return errors.New("invalid time reported") + return ErrInvalidTime + } + + // Handle invalid leap second indicator. + if r.Leap == LeapNotInSync { + return ErrInvalidLeapSecond } // nil means the response is valid. return nil } -// Query returns a response from the remote NTP server host. It contains -// the time at which the server transmitted the response as well as other -// useful information about the time and the remote server. -func Query(host string) (*Response, error) { - return QueryWithOptions(host, QueryOptions{}) +// Query requests time data from a remote NTP server. The response contains +// information from which a more accurate local time can be inferred. +// +// The server address is of the form "host", "host:port", "host%zone:port", +// "[host]:port" or "[host%zone]:port". The host may contain an IPv4, IPv6 or +// domain name address. When specifying both a port and an IPv6 address, one +// of the bracket formats must be used. If no port is included, NTP default +// port 123 is used. +func Query(address string) (*Response, error) { + return QueryWithOptions(address, QueryOptions{}) } // QueryWithOptions performs the same function as Query but allows for the -// customization of several query options. -func QueryWithOptions(host string, opt QueryOptions) (*Response, error) { - m, now, err := getTime(host, opt) - if err != nil { +// customization of certain query behaviors. See the comments for Query and +// QueryOptions for further details. +func QueryWithOptions(address string, opt QueryOptions) (*Response, error) { + h, now, err := getTime(address, &opt) + if err != nil && err != ErrAuthFailed { return nil, err } - return parseTime(m, now), nil + + return generateResponse(h, now, err), nil } -// TimeV returns the current time using information from a remote NTP server. -// On error, it returns the local system time. The version may be 2, 3, or 4. +// Time returns the current, corrected local time using information returned +// from the remote NTP server. On error, Time returns the uncorrected local +// system time. // -// Deprecated: TimeV is deprecated. Use QueryWithOptions instead. -func TimeV(host string, version int) (time.Time, error) { - m, recvTime, err := getTime(host, QueryOptions{Version: version}) +// The server address is of the form "host", "host:port", "host%zone:port", +// "[host]:port" or "[host%zone]:port". The host may contain an IPv4, IPv6 or +// domain name address. When specifying both a port and an IPv6 address, one +// of the bracket formats must be used. If no port is included, NTP default +// port 123 is used. +func Time(address string) (time.Time, error) { + r, err := Query(address) if err != nil { return time.Now(), err } - r := parseTime(m, recvTime) err = r.Validate() if err != nil { return time.Now(), err } - // Use the clock offset to calculate the time. + // Use the response's clock offset to calculate an accurate time. return time.Now().Add(r.ClockOffset), nil } -// Time returns the current time using information from a remote NTP server. -// It uses version 4 of the NTP protocol. On error, it returns the local -// system time. -func Time(host string) (time.Time, error) { - return TimeV(host, defaultNtpVersion) -} - -// getTime performs the NTP server query and returns the response message +// getTime performs the NTP server query and returns the response header // along with the local system time it was received. -func getTime(host string, opt QueryOptions) (*msg, ntpTime, error) { +func getTime(address string, opt *QueryOptions) (*header, ntpTime, error) { + if opt.Timeout == 0 { + opt.Timeout = defaultTimeout + } if opt.Version == 0 { opt.Version = defaultNtpVersion } if opt.Version < 2 || opt.Version > 4 { - return nil, 0, errors.New("invalid protocol version requested") + return nil, 0, ErrInvalidProtocolVersion } - - // Resolve the remote NTP server address. - raddr, err := net.ResolveUDPAddr("udp", net.JoinHostPort(host, "123")) - if err != nil { - return nil, 0, err + if opt.Port == 0 { + opt.Port = defaultNtpPort } - - // Resolve the local address if specified as an option. - var laddr *net.UDPAddr - if opt.LocalAddress != "" { - laddr, err = net.ResolveUDPAddr("udp", net.JoinHostPort(opt.LocalAddress, "0")) - if err != nil { - return nil, 0, err + if opt.Dial != nil { + // wrapper for the deprecated Dial callback. + opt.Dialer = func(la, ra string) (net.Conn, error) { + return dialWrapper(la, ra, opt.Dial) } } + if opt.Dialer == nil { + opt.Dialer = defaultDialer + } - // Override the port if requested. - if opt.Port != 0 { - raddr.Port = opt.Port + // Compose a conforming host:port remote address string if the address + // string doesn't already contain a port. + remoteAddress, err := fixHostPort(address, opt.Port) + if err != nil { + return nil, 0, err } - // Prepare a "connection" to the remote server. - con, err := net.DialUDP("udp", laddr, raddr) + // Connect to the remote server. + con, err := opt.Dialer(opt.LocalAddress, remoteAddress) if err != nil { return nil, 0, err } @@ -376,96 +503,205 @@ func getTime(host string, opt QueryOptions) (*msg, ntpTime, error) { } // Set a timeout on the connection. - if opt.Timeout == 0 { - opt.Timeout = defaultTimeout - } con.SetDeadline(time.Now().Add(opt.Timeout)) - // Allocate a message to hold the response. - recvMsg := new(msg) + // Allocate a buffer big enough to hold an entire response datagram. + recvBuf := make([]byte, 8192) + recvHdr := new(header) - // Allocate a message to hold the query. - xmitMsg := new(msg) - xmitMsg.setMode(client) - xmitMsg.setVersion(opt.Version) - xmitMsg.setLeap(LeapNotInSync) + // Allocate the query message header. + xmitHdr := new(header) + xmitHdr.setMode(client) + xmitHdr.setVersion(opt.Version) + xmitHdr.setLeap(LeapNoWarning) + xmitHdr.Precision = 0x20 - // To ensure privacy and prevent spoofing, try to use a random 64-bit - // value for the TransmitTime. If crypto/rand couldn't generate a - // random value, fall back to using the system clock. Keep track of - // when the messsage was actually transmitted. + // To help prevent spoofing and client fingerprinting, use a + // cryptographically random 64-bit value for the TransmitTime. See: + // https://www.ietf.org/archive/id/draft-ietf-ntp-data-minimization-04.txt bits := make([]byte, 8) _, err = rand.Read(bits) - var xmitTime time.Time - if err == nil { - xmitMsg.TransmitTime = ntpTime(binary.BigEndian.Uint64(bits)) - xmitTime = time.Now() - } else { - xmitTime = time.Now() - xmitMsg.TransmitTime = toNtpTime(xmitTime) + if err != nil { + return nil, 0, err } + xmitHdr.TransmitTime = ntpTime(binary.BigEndian.Uint64(bits)) + + // Write the query header to a transmit buffer. + var xmitBuf bytes.Buffer + binary.Write(&xmitBuf, binary.BigEndian, xmitHdr) - // Transmit the query. - err = binary.Write(con, binary.BigEndian, xmitMsg) + // Allow extensions to process the query and add to the transmit buffer. + for _, e := range opt.Extensions { + err = e.ProcessQuery(&xmitBuf) + if err != nil { + return nil, 0, err + } + } + + // If using symmetric key authentication, decode and validate the auth key + // string. + authKey, err := decodeAuthKey(opt.Auth) + if err != nil { + return nil, 0, err + } + + // Append a MAC if authentication is being used. + appendMAC(&xmitBuf, opt.Auth, authKey) + + // Transmit the query and keep track of when it was transmitted. + xmitTime := time.Now() + _, err = con.Write(xmitBuf.Bytes()) if err != nil { return nil, 0, err } // Receive the response. - err = binary.Read(con, binary.BigEndian, recvMsg) + recvBytes, err := con.Read(recvBuf) if err != nil { return nil, 0, err } - // Keep track of the time the response was received. + // Keep track of the time the response was received. As of go 1.9, the + // time package uses a monotonic clock, so delta will never be less than + // zero for go version 1.9 or higher. delta := time.Since(xmitTime) if delta < 0 { - // The local system may have had its clock adjusted since it - // sent the query. In go 1.9 and later, time.Since ensures - // that a monotonic clock is used, so delta can never be less - // than zero. In versions before 1.9, a monotonic clock is - // not used, so we have to check. - return nil, 0, errors.New("client clock ticked backwards") + delta = 0 + } + recvTime := xmitTime.Add(delta) + + // Parse the response header. + recvBuf = recvBuf[:recvBytes] + recvReader := bytes.NewReader(recvBuf) + err = binary.Read(recvReader, binary.BigEndian, recvHdr) + if err != nil { + return nil, 0, err + } + + // Allow extensions to process the response. + for i := len(opt.Extensions) - 1; i >= 0; i-- { + err = opt.Extensions[i].ProcessResponse(recvBuf) + if err != nil { + return nil, 0, err + } } - recvTime := toNtpTime(xmitTime.Add(delta)) // Check for invalid fields. - if recvMsg.getMode() != server { - return nil, 0, errors.New("invalid mode in response") + if recvHdr.getMode() != server { + return nil, 0, ErrInvalidMode } - if recvMsg.TransmitTime == ntpTime(0) { - return nil, 0, errors.New("invalid transmit time in response") + if recvHdr.TransmitTime == ntpTime(0) { + return nil, 0, ErrInvalidTransmitTime } - if recvMsg.OriginTime != xmitMsg.TransmitTime { - return nil, 0, errors.New("server response mismatch") + if recvHdr.OriginTime != xmitHdr.TransmitTime { + return nil, 0, ErrServerResponseMismatch } - if recvMsg.ReceiveTime > recvMsg.TransmitTime { - return nil, 0, errors.New("server clock ticked backwards") + if recvHdr.ReceiveTime > recvHdr.TransmitTime { + return nil, 0, ErrServerTickedBackwards } // Correct the received message's origin time using the actual // transmit time. - recvMsg.OriginTime = toNtpTime(xmitTime) + recvHdr.OriginTime = toNtpTime(xmitTime) + + // Perform authentication of the server response. + authErr := verifyMAC(recvBuf, opt.Auth, authKey) + + return recvHdr, toNtpTime(recvTime), authErr +} + +// defaultDialer provides a UDP dialer based on Go's built-in net stack. +func defaultDialer(localAddress, remoteAddress string) (net.Conn, error) { + var laddr *net.UDPAddr + if localAddress != "" { + var err error + laddr, err = net.ResolveUDPAddr("udp", net.JoinHostPort(localAddress, "0")) + if err != nil { + return nil, err + } + } + + raddr, err := net.ResolveUDPAddr("udp", remoteAddress) + if err != nil { + return nil, err + } + + return net.DialUDP("udp", laddr, raddr) +} + +// dialWrapper is used to wrap the deprecated Dial callback in QueryOptions. +func dialWrapper(la, ra string, + dial func(la string, lp int, ra string, rp int) (net.Conn, error)) (net.Conn, error) { + rhost, rport, err := net.SplitHostPort(ra) + if err != nil { + return nil, err + } + + rportValue, err := strconv.Atoi(rport) + if err != nil { + return nil, err + } + + return dial(la, 0, rhost, rportValue) +} + +// fixHostPort examines an address in one of the accepted forms and fixes it +// to include a port number if necessary. +func fixHostPort(address string, defaultPort int) (fixed string, err error) { + if len(address) == 0 { + return "", errors.New("address string is empty") + } + + // If the address is wrapped in brackets, append a port if necessary. + if address[0] == '[' { + end := strings.IndexByte(address, ']') + switch { + case end < 0: + return "", errors.New("missing ']' in address") + case end+1 == len(address): + return fmt.Sprintf("%s:%d", address, defaultPort), nil + case address[end+1] == ':': + return address, nil + default: + return "", errors.New("unexpected character following ']' in address") + } + } + + // No colons? Must be a port-less IPv4 or domain address. + last := strings.LastIndexByte(address, ':') + if last < 0 { + return fmt.Sprintf("%s:%d", address, defaultPort), nil + } + + // Exactly one colon? A port have been included along with an IPv4 or + // domain address. (IPv6 addresses are guaranteed to have more than one + // colon.) + prev := strings.LastIndexByte(address[:last], ':') + if prev < 0 { + return address, nil + } - return recvMsg, recvTime, nil + // Two or more colons means we must have an IPv6 address without a port. + return fmt.Sprintf("[%s]:%d", address, defaultPort), nil } -// parseTime parses the NTP packet along with the packet receive time to -// generate a Response record. -func parseTime(m *msg, recvTime ntpTime) *Response { +// generateResponse processes NTP header fields along with the its receive +// time to generate a Response record. +func generateResponse(h *header, recvTime ntpTime, authErr error) *Response { r := &Response{ - Time: m.TransmitTime.Time(), - ClockOffset: offset(m.OriginTime, m.ReceiveTime, m.TransmitTime, recvTime), - RTT: rtt(m.OriginTime, m.ReceiveTime, m.TransmitTime, recvTime), - Precision: toInterval(m.Precision), - Stratum: m.Stratum, - ReferenceID: m.ReferenceID, - ReferenceTime: m.ReferenceTime.Time(), - RootDelay: m.RootDelay.Duration(), - RootDispersion: m.RootDispersion.Duration(), - Leap: m.getLeap(), - MinError: minError(m.OriginTime, m.ReceiveTime, m.TransmitTime, recvTime), - Poll: toInterval(m.Poll), + Time: h.TransmitTime.Time(), + ClockOffset: offset(h.OriginTime, h.ReceiveTime, h.TransmitTime, recvTime), + RTT: rtt(h.OriginTime, h.ReceiveTime, h.TransmitTime, recvTime), + Precision: toInterval(h.Precision), + Stratum: h.Stratum, + ReferenceID: h.ReferenceID, + ReferenceTime: h.ReferenceTime.Time(), + RootDelay: h.RootDelay.Duration(), + RootDispersion: h.RootDispersion.Duration(), + Leap: h.getLeap(), + MinError: minError(h.OriginTime, h.ReceiveTime, h.TransmitTime, recvTime), + Poll: toInterval(h.Poll), + authErr: authErr, } // Calculate values depending on other calculated values @@ -558,7 +794,7 @@ func toInterval(t int8) time.Duration { func kissCode(id uint32) string { isPrintable := func(ch byte) bool { return ch >= 32 && ch <= 126 } - b := []byte{ + b := [4]byte{ byte(id >> 24), byte(id >> 16), byte(id >> 8), @@ -569,5 +805,5 @@ func kissCode(id uint32) string { return "" } } - return string(b) + return string(b[:]) } diff --git a/vendor/github.com/cespare/xxhash/v2/.travis.yml b/vendor/github.com/cespare/xxhash/v2/.travis.yml deleted file mode 100644 index c516ea88..00000000 --- a/vendor/github.com/cespare/xxhash/v2/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: go -go: - - "1.x" - - master -env: - - TAGS="" - - TAGS="-tags purego" -script: go test $TAGS -v ./... diff --git a/vendor/github.com/cespare/xxhash/v2/README.md b/vendor/github.com/cespare/xxhash/v2/README.md index 2fd8693c..8bf0e5b7 100644 --- a/vendor/github.com/cespare/xxhash/v2/README.md +++ b/vendor/github.com/cespare/xxhash/v2/README.md @@ -1,10 +1,9 @@ # xxhash -[![GoDoc](https://godoc.org/github.com/cespare/xxhash?status.svg)](https://godoc.org/github.com/cespare/xxhash) -[![Build Status](https://travis-ci.org/cespare/xxhash.svg?branch=master)](https://travis-ci.org/cespare/xxhash) +[![Go Reference](https://pkg.go.dev/badge/github.com/cespare/xxhash/v2.svg)](https://pkg.go.dev/github.com/cespare/xxhash/v2) +[![Test](https://github.com/cespare/xxhash/actions/workflows/test.yml/badge.svg)](https://github.com/cespare/xxhash/actions/workflows/test.yml) -xxhash is a Go implementation of the 64-bit -[xxHash](http://cyan4973.github.io/xxHash/) algorithm, XXH64. This is a +xxhash is a Go implementation of the 64-bit [xxHash] algorithm, XXH64. This is a high-quality hashing algorithm that is much faster than anything in the Go standard library. @@ -25,8 +24,11 @@ func (*Digest) WriteString(string) (int, error) func (*Digest) Sum64() uint64 ``` -This implementation provides a fast pure-Go implementation and an even faster -assembly implementation for amd64. +The package is written with optimized pure Go and also contains even faster +assembly implementations for amd64 and arm64. If desired, the `purego` build tag +opts into using the Go code even on those architectures. + +[xxHash]: http://cyan4973.github.io/xxHash/ ## Compatibility @@ -45,23 +47,26 @@ I recommend using the latest release of Go. Here are some quick benchmarks comparing the pure-Go and assembly implementations of Sum64. -| input size | purego | asm | -| --- | --- | --- | -| 5 B | 979.66 MB/s | 1291.17 MB/s | -| 100 B | 7475.26 MB/s | 7973.40 MB/s | -| 4 KB | 17573.46 MB/s | 17602.65 MB/s | -| 10 MB | 17131.46 MB/s | 17142.16 MB/s | +| input size | purego | asm | +| ---------- | --------- | --------- | +| 4 B | 1.3 GB/s | 1.2 GB/s | +| 16 B | 2.9 GB/s | 3.5 GB/s | +| 100 B | 6.9 GB/s | 8.1 GB/s | +| 4 KB | 11.7 GB/s | 16.7 GB/s | +| 10 MB | 12.0 GB/s | 17.3 GB/s | -These numbers were generated on Ubuntu 18.04 with an Intel i7-8700K CPU using -the following commands under Go 1.11.2: +These numbers were generated on Ubuntu 20.04 with an Intel Xeon Platinum 8252C +CPU using the following commands under Go 1.19.2: ``` -$ go test -tags purego -benchtime 10s -bench '/xxhash,direct,bytes' -$ go test -benchtime 10s -bench '/xxhash,direct,bytes' +benchstat <(go test -tags purego -benchtime 500ms -count 15 -bench 'Sum64$') +benchstat <(go test -benchtime 500ms -count 15 -bench 'Sum64$') ``` ## Projects using this package - [InfluxDB](https://github.com/influxdata/influxdb) - [Prometheus](https://github.com/prometheus/prometheus) +- [VictoriaMetrics](https://github.com/VictoriaMetrics/VictoriaMetrics) - [FreeCache](https://github.com/coocood/freecache) +- [FastCache](https://github.com/VictoriaMetrics/fastcache) diff --git a/vendor/github.com/cespare/xxhash/v2/testall.sh b/vendor/github.com/cespare/xxhash/v2/testall.sh new file mode 100644 index 00000000..94b9c443 --- /dev/null +++ b/vendor/github.com/cespare/xxhash/v2/testall.sh @@ -0,0 +1,10 @@ +#!/bin/bash +set -eu -o pipefail + +# Small convenience script for running the tests with various combinations of +# arch/tags. This assumes we're running on amd64 and have qemu available. + +go test ./... +go test -tags purego ./... +GOARCH=arm64 go test +GOARCH=arm64 go test -tags purego diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash.go b/vendor/github.com/cespare/xxhash/v2/xxhash.go index db0b35fb..a9e0d45c 100644 --- a/vendor/github.com/cespare/xxhash/v2/xxhash.go +++ b/vendor/github.com/cespare/xxhash/v2/xxhash.go @@ -16,19 +16,11 @@ const ( prime5 uint64 = 2870177450012600261 ) -// NOTE(caleb): I'm using both consts and vars of the primes. Using consts where -// possible in the Go code is worth a small (but measurable) performance boost -// by avoiding some MOVQs. Vars are needed for the asm and also are useful for -// convenience in the Go code in a few places where we need to intentionally -// avoid constant arithmetic (e.g., v1 := prime1 + prime2 fails because the -// result overflows a uint64). -var ( - prime1v = prime1 - prime2v = prime2 - prime3v = prime3 - prime4v = prime4 - prime5v = prime5 -) +// Store the primes in an array as well. +// +// The consts are used when possible in Go code to avoid MOVs but we need a +// contiguous array of the assembly code. +var primes = [...]uint64{prime1, prime2, prime3, prime4, prime5} // Digest implements hash.Hash64. type Digest struct { @@ -50,10 +42,10 @@ func New() *Digest { // Reset clears the Digest's state so that it can be reused. func (d *Digest) Reset() { - d.v1 = prime1v + prime2 + d.v1 = primes[0] + prime2 d.v2 = prime2 d.v3 = 0 - d.v4 = -prime1v + d.v4 = -primes[0] d.total = 0 d.n = 0 } @@ -69,21 +61,23 @@ func (d *Digest) Write(b []byte) (n int, err error) { n = len(b) d.total += uint64(n) + memleft := d.mem[d.n&(len(d.mem)-1):] + if d.n+n < 32 { // This new data doesn't even fill the current block. - copy(d.mem[d.n:], b) + copy(memleft, b) d.n += n return } if d.n > 0 { // Finish off the partial block. - copy(d.mem[d.n:], b) + c := copy(memleft, b) d.v1 = round(d.v1, u64(d.mem[0:8])) d.v2 = round(d.v2, u64(d.mem[8:16])) d.v3 = round(d.v3, u64(d.mem[16:24])) d.v4 = round(d.v4, u64(d.mem[24:32])) - b = b[32-d.n:] + b = b[c:] d.n = 0 } @@ -133,21 +127,20 @@ func (d *Digest) Sum64() uint64 { h += d.total - i, end := 0, d.n - for ; i+8 <= end; i += 8 { - k1 := round(0, u64(d.mem[i:i+8])) + b := d.mem[:d.n&(len(d.mem)-1)] + for ; len(b) >= 8; b = b[8:] { + k1 := round(0, u64(b[:8])) h ^= k1 h = rol27(h)*prime1 + prime4 } - if i+4 <= end { - h ^= uint64(u32(d.mem[i:i+4])) * prime1 + if len(b) >= 4 { + h ^= uint64(u32(b[:4])) * prime1 h = rol23(h)*prime2 + prime3 - i += 4 + b = b[4:] } - for i < end { - h ^= uint64(d.mem[i]) * prime5 + for ; len(b) > 0; b = b[1:] { + h ^= uint64(b[0]) * prime5 h = rol11(h) * prime1 - i++ } h ^= h >> 33 @@ -193,7 +186,6 @@ func (d *Digest) UnmarshalBinary(b []byte) error { b, d.v4 = consumeUint64(b) b, d.total = consumeUint64(b) copy(d.mem[:], b) - b = b[len(d.mem):] d.n = int(d.total % uint64(len(d.mem))) return nil } diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s b/vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s index d580e32a..3e8b1325 100644 --- a/vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s +++ b/vendor/github.com/cespare/xxhash/v2/xxhash_amd64.s @@ -1,215 +1,209 @@ +//go:build !appengine && gc && !purego // +build !appengine // +build gc // +build !purego #include "textflag.h" -// Register allocation: -// AX h -// CX pointer to advance through b -// DX n -// BX loop end -// R8 v1, k1 -// R9 v2 -// R10 v3 -// R11 v4 -// R12 tmp -// R13 prime1v -// R14 prime2v -// R15 prime4v - -// round reads from and advances the buffer pointer in CX. -// It assumes that R13 has prime1v and R14 has prime2v. -#define round(r) \ - MOVQ (CX), R12 \ - ADDQ $8, CX \ - IMULQ R14, R12 \ - ADDQ R12, r \ - ROLQ $31, r \ - IMULQ R13, r - -// mergeRound applies a merge round on the two registers acc and val. -// It assumes that R13 has prime1v, R14 has prime2v, and R15 has prime4v. -#define mergeRound(acc, val) \ - IMULQ R14, val \ - ROLQ $31, val \ - IMULQ R13, val \ - XORQ val, acc \ - IMULQ R13, acc \ - ADDQ R15, acc +// Registers: +#define h AX +#define d AX +#define p SI // pointer to advance through b +#define n DX +#define end BX // loop end +#define v1 R8 +#define v2 R9 +#define v3 R10 +#define v4 R11 +#define x R12 +#define prime1 R13 +#define prime2 R14 +#define prime4 DI + +#define round(acc, x) \ + IMULQ prime2, x \ + ADDQ x, acc \ + ROLQ $31, acc \ + IMULQ prime1, acc + +// round0 performs the operation x = round(0, x). +#define round0(x) \ + IMULQ prime2, x \ + ROLQ $31, x \ + IMULQ prime1, x + +// mergeRound applies a merge round on the two registers acc and x. +// It assumes that prime1, prime2, and prime4 have been loaded. +#define mergeRound(acc, x) \ + round0(x) \ + XORQ x, acc \ + IMULQ prime1, acc \ + ADDQ prime4, acc + +// blockLoop processes as many 32-byte blocks as possible, +// updating v1, v2, v3, and v4. It assumes that there is at least one block +// to process. +#define blockLoop() \ +loop: \ + MOVQ +0(p), x \ + round(v1, x) \ + MOVQ +8(p), x \ + round(v2, x) \ + MOVQ +16(p), x \ + round(v3, x) \ + MOVQ +24(p), x \ + round(v4, x) \ + ADDQ $32, p \ + CMPQ p, end \ + JLE loop // func Sum64(b []byte) uint64 -TEXT ·Sum64(SB), NOSPLIT, $0-32 +TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32 // Load fixed primes. - MOVQ ·prime1v(SB), R13 - MOVQ ·prime2v(SB), R14 - MOVQ ·prime4v(SB), R15 + MOVQ ·primes+0(SB), prime1 + MOVQ ·primes+8(SB), prime2 + MOVQ ·primes+24(SB), prime4 // Load slice. - MOVQ b_base+0(FP), CX - MOVQ b_len+8(FP), DX - LEAQ (CX)(DX*1), BX + MOVQ b_base+0(FP), p + MOVQ b_len+8(FP), n + LEAQ (p)(n*1), end // The first loop limit will be len(b)-32. - SUBQ $32, BX + SUBQ $32, end // Check whether we have at least one block. - CMPQ DX, $32 + CMPQ n, $32 JLT noBlocks // Set up initial state (v1, v2, v3, v4). - MOVQ R13, R8 - ADDQ R14, R8 - MOVQ R14, R9 - XORQ R10, R10 - XORQ R11, R11 - SUBQ R13, R11 - - // Loop until CX > BX. -blockLoop: - round(R8) - round(R9) - round(R10) - round(R11) - - CMPQ CX, BX - JLE blockLoop - - MOVQ R8, AX - ROLQ $1, AX - MOVQ R9, R12 - ROLQ $7, R12 - ADDQ R12, AX - MOVQ R10, R12 - ROLQ $12, R12 - ADDQ R12, AX - MOVQ R11, R12 - ROLQ $18, R12 - ADDQ R12, AX - - mergeRound(AX, R8) - mergeRound(AX, R9) - mergeRound(AX, R10) - mergeRound(AX, R11) + MOVQ prime1, v1 + ADDQ prime2, v1 + MOVQ prime2, v2 + XORQ v3, v3 + XORQ v4, v4 + SUBQ prime1, v4 + + blockLoop() + + MOVQ v1, h + ROLQ $1, h + MOVQ v2, x + ROLQ $7, x + ADDQ x, h + MOVQ v3, x + ROLQ $12, x + ADDQ x, h + MOVQ v4, x + ROLQ $18, x + ADDQ x, h + + mergeRound(h, v1) + mergeRound(h, v2) + mergeRound(h, v3) + mergeRound(h, v4) JMP afterBlocks noBlocks: - MOVQ ·prime5v(SB), AX + MOVQ ·primes+32(SB), h afterBlocks: - ADDQ DX, AX - - // Right now BX has len(b)-32, and we want to loop until CX > len(b)-8. - ADDQ $24, BX - - CMPQ CX, BX - JG fourByte - -wordLoop: - // Calculate k1. - MOVQ (CX), R8 - ADDQ $8, CX - IMULQ R14, R8 - ROLQ $31, R8 - IMULQ R13, R8 - - XORQ R8, AX - ROLQ $27, AX - IMULQ R13, AX - ADDQ R15, AX - - CMPQ CX, BX - JLE wordLoop - -fourByte: - ADDQ $4, BX - CMPQ CX, BX - JG singles - - MOVL (CX), R8 - ADDQ $4, CX - IMULQ R13, R8 - XORQ R8, AX - - ROLQ $23, AX - IMULQ R14, AX - ADDQ ·prime3v(SB), AX - -singles: - ADDQ $4, BX - CMPQ CX, BX + ADDQ n, h + + ADDQ $24, end + CMPQ p, end + JG try4 + +loop8: + MOVQ (p), x + ADDQ $8, p + round0(x) + XORQ x, h + ROLQ $27, h + IMULQ prime1, h + ADDQ prime4, h + + CMPQ p, end + JLE loop8 + +try4: + ADDQ $4, end + CMPQ p, end + JG try1 + + MOVL (p), x + ADDQ $4, p + IMULQ prime1, x + XORQ x, h + + ROLQ $23, h + IMULQ prime2, h + ADDQ ·primes+16(SB), h + +try1: + ADDQ $4, end + CMPQ p, end JGE finalize -singlesLoop: - MOVBQZX (CX), R12 - ADDQ $1, CX - IMULQ ·prime5v(SB), R12 - XORQ R12, AX +loop1: + MOVBQZX (p), x + ADDQ $1, p + IMULQ ·primes+32(SB), x + XORQ x, h + ROLQ $11, h + IMULQ prime1, h - ROLQ $11, AX - IMULQ R13, AX - - CMPQ CX, BX - JL singlesLoop + CMPQ p, end + JL loop1 finalize: - MOVQ AX, R12 - SHRQ $33, R12 - XORQ R12, AX - IMULQ R14, AX - MOVQ AX, R12 - SHRQ $29, R12 - XORQ R12, AX - IMULQ ·prime3v(SB), AX - MOVQ AX, R12 - SHRQ $32, R12 - XORQ R12, AX - - MOVQ AX, ret+24(FP) + MOVQ h, x + SHRQ $33, x + XORQ x, h + IMULQ prime2, h + MOVQ h, x + SHRQ $29, x + XORQ x, h + IMULQ ·primes+16(SB), h + MOVQ h, x + SHRQ $32, x + XORQ x, h + + MOVQ h, ret+24(FP) RET -// writeBlocks uses the same registers as above except that it uses AX to store -// the d pointer. - // func writeBlocks(d *Digest, b []byte) int -TEXT ·writeBlocks(SB), NOSPLIT, $0-40 +TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40 // Load fixed primes needed for round. - MOVQ ·prime1v(SB), R13 - MOVQ ·prime2v(SB), R14 + MOVQ ·primes+0(SB), prime1 + MOVQ ·primes+8(SB), prime2 // Load slice. - MOVQ b_base+8(FP), CX - MOVQ b_len+16(FP), DX - LEAQ (CX)(DX*1), BX - SUBQ $32, BX + MOVQ b_base+8(FP), p + MOVQ b_len+16(FP), n + LEAQ (p)(n*1), end + SUBQ $32, end // Load vN from d. - MOVQ d+0(FP), AX - MOVQ 0(AX), R8 // v1 - MOVQ 8(AX), R9 // v2 - MOVQ 16(AX), R10 // v3 - MOVQ 24(AX), R11 // v4 + MOVQ s+0(FP), d + MOVQ 0(d), v1 + MOVQ 8(d), v2 + MOVQ 16(d), v3 + MOVQ 24(d), v4 // We don't need to check the loop condition here; this function is // always called with at least one block of data to process. -blockLoop: - round(R8) - round(R9) - round(R10) - round(R11) - - CMPQ CX, BX - JLE blockLoop + blockLoop() // Copy vN back to d. - MOVQ R8, 0(AX) - MOVQ R9, 8(AX) - MOVQ R10, 16(AX) - MOVQ R11, 24(AX) - - // The number of bytes written is CX minus the old base pointer. - SUBQ b_base+8(FP), CX - MOVQ CX, ret+32(FP) + MOVQ v1, 0(d) + MOVQ v2, 8(d) + MOVQ v3, 16(d) + MOVQ v4, 24(d) + + // The number of bytes written is p minus the old base pointer. + SUBQ b_base+8(FP), p + MOVQ p, ret+32(FP) RET diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash_arm64.s b/vendor/github.com/cespare/xxhash/v2/xxhash_arm64.s new file mode 100644 index 00000000..7e3145a2 --- /dev/null +++ b/vendor/github.com/cespare/xxhash/v2/xxhash_arm64.s @@ -0,0 +1,183 @@ +//go:build !appengine && gc && !purego +// +build !appengine +// +build gc +// +build !purego + +#include "textflag.h" + +// Registers: +#define digest R1 +#define h R2 // return value +#define p R3 // input pointer +#define n R4 // input length +#define nblocks R5 // n / 32 +#define prime1 R7 +#define prime2 R8 +#define prime3 R9 +#define prime4 R10 +#define prime5 R11 +#define v1 R12 +#define v2 R13 +#define v3 R14 +#define v4 R15 +#define x1 R20 +#define x2 R21 +#define x3 R22 +#define x4 R23 + +#define round(acc, x) \ + MADD prime2, acc, x, acc \ + ROR $64-31, acc \ + MUL prime1, acc + +// round0 performs the operation x = round(0, x). +#define round0(x) \ + MUL prime2, x \ + ROR $64-31, x \ + MUL prime1, x + +#define mergeRound(acc, x) \ + round0(x) \ + EOR x, acc \ + MADD acc, prime4, prime1, acc + +// blockLoop processes as many 32-byte blocks as possible, +// updating v1, v2, v3, and v4. It assumes that n >= 32. +#define blockLoop() \ + LSR $5, n, nblocks \ + PCALIGN $16 \ + loop: \ + LDP.P 16(p), (x1, x2) \ + LDP.P 16(p), (x3, x4) \ + round(v1, x1) \ + round(v2, x2) \ + round(v3, x3) \ + round(v4, x4) \ + SUB $1, nblocks \ + CBNZ nblocks, loop + +// func Sum64(b []byte) uint64 +TEXT ·Sum64(SB), NOSPLIT|NOFRAME, $0-32 + LDP b_base+0(FP), (p, n) + + LDP ·primes+0(SB), (prime1, prime2) + LDP ·primes+16(SB), (prime3, prime4) + MOVD ·primes+32(SB), prime5 + + CMP $32, n + CSEL LT, prime5, ZR, h // if n < 32 { h = prime5 } else { h = 0 } + BLT afterLoop + + ADD prime1, prime2, v1 + MOVD prime2, v2 + MOVD $0, v3 + NEG prime1, v4 + + blockLoop() + + ROR $64-1, v1, x1 + ROR $64-7, v2, x2 + ADD x1, x2 + ROR $64-12, v3, x3 + ROR $64-18, v4, x4 + ADD x3, x4 + ADD x2, x4, h + + mergeRound(h, v1) + mergeRound(h, v2) + mergeRound(h, v3) + mergeRound(h, v4) + +afterLoop: + ADD n, h + + TBZ $4, n, try8 + LDP.P 16(p), (x1, x2) + + round0(x1) + + // NOTE: here and below, sequencing the EOR after the ROR (using a + // rotated register) is worth a small but measurable speedup for small + // inputs. + ROR $64-27, h + EOR x1 @> 64-27, h, h + MADD h, prime4, prime1, h + + round0(x2) + ROR $64-27, h + EOR x2 @> 64-27, h, h + MADD h, prime4, prime1, h + +try8: + TBZ $3, n, try4 + MOVD.P 8(p), x1 + + round0(x1) + ROR $64-27, h + EOR x1 @> 64-27, h, h + MADD h, prime4, prime1, h + +try4: + TBZ $2, n, try2 + MOVWU.P 4(p), x2 + + MUL prime1, x2 + ROR $64-23, h + EOR x2 @> 64-23, h, h + MADD h, prime3, prime2, h + +try2: + TBZ $1, n, try1 + MOVHU.P 2(p), x3 + AND $255, x3, x1 + LSR $8, x3, x2 + + MUL prime5, x1 + ROR $64-11, h + EOR x1 @> 64-11, h, h + MUL prime1, h + + MUL prime5, x2 + ROR $64-11, h + EOR x2 @> 64-11, h, h + MUL prime1, h + +try1: + TBZ $0, n, finalize + MOVBU (p), x4 + + MUL prime5, x4 + ROR $64-11, h + EOR x4 @> 64-11, h, h + MUL prime1, h + +finalize: + EOR h >> 33, h + MUL prime2, h + EOR h >> 29, h + MUL prime3, h + EOR h >> 32, h + + MOVD h, ret+24(FP) + RET + +// func writeBlocks(d *Digest, b []byte) int +TEXT ·writeBlocks(SB), NOSPLIT|NOFRAME, $0-40 + LDP ·primes+0(SB), (prime1, prime2) + + // Load state. Assume v[1-4] are stored contiguously. + MOVD d+0(FP), digest + LDP 0(digest), (v1, v2) + LDP 16(digest), (v3, v4) + + LDP b_base+8(FP), (p, n) + + blockLoop() + + // Store updated state. + STP (v1, v2), 0(digest) + STP (v3, v4), 16(digest) + + BIC $31, n + MOVD n, ret+32(FP) + RET diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash_amd64.go b/vendor/github.com/cespare/xxhash/v2/xxhash_asm.go similarity index 73% rename from vendor/github.com/cespare/xxhash/v2/xxhash_amd64.go rename to vendor/github.com/cespare/xxhash/v2/xxhash_asm.go index ad14b807..9216e0a4 100644 --- a/vendor/github.com/cespare/xxhash/v2/xxhash_amd64.go +++ b/vendor/github.com/cespare/xxhash/v2/xxhash_asm.go @@ -1,3 +1,5 @@ +//go:build (amd64 || arm64) && !appengine && gc && !purego +// +build amd64 arm64 // +build !appengine // +build gc // +build !purego diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash_other.go b/vendor/github.com/cespare/xxhash/v2/xxhash_other.go index 4a5a8216..26df13bb 100644 --- a/vendor/github.com/cespare/xxhash/v2/xxhash_other.go +++ b/vendor/github.com/cespare/xxhash/v2/xxhash_other.go @@ -1,4 +1,5 @@ -// +build !amd64 appengine !gc purego +//go:build (!amd64 && !arm64) || appengine || !gc || purego +// +build !amd64,!arm64 appengine !gc purego package xxhash @@ -14,10 +15,10 @@ func Sum64(b []byte) uint64 { var h uint64 if n >= 32 { - v1 := prime1v + prime2 + v1 := primes[0] + prime2 v2 := prime2 v3 := uint64(0) - v4 := -prime1v + v4 := -primes[0] for len(b) >= 32 { v1 = round(v1, u64(b[0:8:len(b)])) v2 = round(v2, u64(b[8:16:len(b)])) @@ -36,19 +37,18 @@ func Sum64(b []byte) uint64 { h += uint64(n) - i, end := 0, len(b) - for ; i+8 <= end; i += 8 { - k1 := round(0, u64(b[i:i+8:len(b)])) + for ; len(b) >= 8; b = b[8:] { + k1 := round(0, u64(b[:8])) h ^= k1 h = rol27(h)*prime1 + prime4 } - if i+4 <= end { - h ^= uint64(u32(b[i:i+4:len(b)])) * prime1 + if len(b) >= 4 { + h ^= uint64(u32(b[:4])) * prime1 h = rol23(h)*prime2 + prime3 - i += 4 + b = b[4:] } - for ; i < end; i++ { - h ^= uint64(b[i]) * prime5 + for ; len(b) > 0; b = b[1:] { + h ^= uint64(b[0]) * prime5 h = rol11(h) * prime1 } diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash_safe.go b/vendor/github.com/cespare/xxhash/v2/xxhash_safe.go index fc9bea7a..e86f1b5f 100644 --- a/vendor/github.com/cespare/xxhash/v2/xxhash_safe.go +++ b/vendor/github.com/cespare/xxhash/v2/xxhash_safe.go @@ -1,3 +1,4 @@ +//go:build appengine // +build appengine // This file contains the safe implementations of otherwise unsafe-using code. diff --git a/vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go b/vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go index 53bf76ef..1c1638fd 100644 --- a/vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go +++ b/vendor/github.com/cespare/xxhash/v2/xxhash_unsafe.go @@ -1,3 +1,4 @@ +//go:build !appengine // +build !appengine // This file encapsulates usage of unsafe. @@ -6,41 +7,52 @@ package xxhash import ( - "reflect" "unsafe" ) -// Notes: +// In the future it's possible that compiler optimizations will make these +// XxxString functions unnecessary by realizing that calls such as +// Sum64([]byte(s)) don't need to copy s. See https://go.dev/issue/2205. +// If that happens, even if we keep these functions they can be replaced with +// the trivial safe code. + +// NOTE: The usual way of doing an unsafe string-to-[]byte conversion is: // -// See https://groups.google.com/d/msg/golang-nuts/dcjzJy-bSpw/tcZYBzQqAQAJ -// for some discussion about these unsafe conversions. +// var b []byte +// bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) +// bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data +// bh.Len = len(s) +// bh.Cap = len(s) // -// In the future it's possible that compiler optimizations will make these -// unsafe operations unnecessary: https://golang.org/issue/2205. +// Unfortunately, as of Go 1.15.3 the inliner's cost model assigns a high enough +// weight to this sequence of expressions that any function that uses it will +// not be inlined. Instead, the functions below use a different unsafe +// conversion designed to minimize the inliner weight and allow both to be +// inlined. There is also a test (TestInlining) which verifies that these are +// inlined. // -// Both of these wrapper functions still incur function call overhead since they -// will not be inlined. We could write Go/asm copies of Sum64 and Digest.Write -// for strings to squeeze out a bit more speed. Mid-stack inlining should -// eventually fix this. +// See https://github.com/golang/go/issues/42739 for discussion. // Sum64String computes the 64-bit xxHash digest of s. // It may be faster than Sum64([]byte(s)) by avoiding a copy. func Sum64String(s string) uint64 { - var b []byte - bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data - bh.Len = len(s) - bh.Cap = len(s) + b := *(*[]byte)(unsafe.Pointer(&sliceHeader{s, len(s)})) return Sum64(b) } // WriteString adds more data to d. It always returns len(s), nil. // It may be faster than Write([]byte(s)) by avoiding a copy. func (d *Digest) WriteString(s string) (n int, err error) { - var b []byte - bh := (*reflect.SliceHeader)(unsafe.Pointer(&b)) - bh.Data = (*reflect.StringHeader)(unsafe.Pointer(&s)).Data - bh.Len = len(s) - bh.Cap = len(s) - return d.Write(b) + d.Write(*(*[]byte)(unsafe.Pointer(&sliceHeader{s, len(s)}))) + // d.Write always returns len(s), nil. + // Ignoring the return output and returning these fixed values buys a + // savings of 6 in the inliner's cost model. + return len(s), nil +} + +// sliceHeader is similar to reflect.SliceHeader, but it assumes that the layout +// of the first two words is the same as the layout of a string. +type sliceHeader struct { + s string + cap int } diff --git a/vendor/github.com/coreos/go-systemd/dbus/methods.go b/vendor/github.com/coreos/go-systemd/dbus/methods.go deleted file mode 100644 index 5859583e..00000000 --- a/vendor/github.com/coreos/go-systemd/dbus/methods.go +++ /dev/null @@ -1,600 +0,0 @@ -// Copyright 2015, 2018 CoreOS, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package dbus - -import ( - "errors" - "fmt" - "path" - "strconv" - - "github.com/godbus/dbus" -) - -func (c *Conn) jobComplete(signal *dbus.Signal) { - var id uint32 - var job dbus.ObjectPath - var unit string - var result string - dbus.Store(signal.Body, &id, &job, &unit, &result) - c.jobListener.Lock() - out, ok := c.jobListener.jobs[job] - if ok { - out <- result - delete(c.jobListener.jobs, job) - } - c.jobListener.Unlock() -} - -func (c *Conn) startJob(ch chan<- string, job string, args ...interface{}) (int, error) { - if ch != nil { - c.jobListener.Lock() - defer c.jobListener.Unlock() - } - - var p dbus.ObjectPath - err := c.sysobj.Call(job, 0, args...).Store(&p) - if err != nil { - return 0, err - } - - if ch != nil { - c.jobListener.jobs[p] = ch - } - - // ignore error since 0 is fine if conversion fails - jobID, _ := strconv.Atoi(path.Base(string(p))) - - return jobID, nil -} - -// StartUnit enqueues a start job and depending jobs, if any (unless otherwise -// specified by the mode string). -// -// Takes the unit to activate, plus a mode string. The mode needs to be one of -// replace, fail, isolate, ignore-dependencies, ignore-requirements. If -// "replace" the call will start the unit and its dependencies, possibly -// replacing already queued jobs that conflict with this. If "fail" the call -// will start the unit and its dependencies, but will fail if this would change -// an already queued job. If "isolate" the call will start the unit in question -// and terminate all units that aren't dependencies of it. If -// "ignore-dependencies" it will start a unit but ignore all its dependencies. -// If "ignore-requirements" it will start a unit but only ignore the -// requirement dependencies. It is not recommended to make use of the latter -// two options. -// -// If the provided channel is non-nil, a result string will be sent to it upon -// job completion: one of done, canceled, timeout, failed, dependency, skipped. -// done indicates successful execution of a job. canceled indicates that a job -// has been canceled before it finished execution. timeout indicates that the -// job timeout was reached. failed indicates that the job failed. dependency -// indicates that a job this job has been depending on failed and the job hence -// has been removed too. skipped indicates that a job was skipped because it -// didn't apply to the units current state. -// -// If no error occurs, the ID of the underlying systemd job will be returned. There -// does exist the possibility for no error to be returned, but for the returned job -// ID to be 0. In this case, the actual underlying ID is not 0 and this datapoint -// should not be considered authoritative. -// -// If an error does occur, it will be returned to the user alongside a job ID of 0. -func (c *Conn) StartUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.StartUnit", name, mode) -} - -// StopUnit is similar to StartUnit but stops the specified unit rather -// than starting it. -func (c *Conn) StopUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.StopUnit", name, mode) -} - -// ReloadUnit reloads a unit. Reloading is done only if the unit is already running and fails otherwise. -func (c *Conn) ReloadUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.ReloadUnit", name, mode) -} - -// RestartUnit restarts a service. If a service is restarted that isn't -// running it will be started. -func (c *Conn) RestartUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.RestartUnit", name, mode) -} - -// TryRestartUnit is like RestartUnit, except that a service that isn't running -// is not affected by the restart. -func (c *Conn) TryRestartUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.TryRestartUnit", name, mode) -} - -// ReloadOrRestartUnit attempts a reload if the unit supports it and use a restart -// otherwise. -func (c *Conn) ReloadOrRestartUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.ReloadOrRestartUnit", name, mode) -} - -// ReloadOrTryRestartUnit attempts a reload if the unit supports it and use a "Try" -// flavored restart otherwise. -func (c *Conn) ReloadOrTryRestartUnit(name string, mode string, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.ReloadOrTryRestartUnit", name, mode) -} - -// StartTransientUnit() may be used to create and start a transient unit, which -// will be released as soon as it is not running or referenced anymore or the -// system is rebooted. name is the unit name including suffix, and must be -// unique. mode is the same as in StartUnit(), properties contains properties -// of the unit. -func (c *Conn) StartTransientUnit(name string, mode string, properties []Property, ch chan<- string) (int, error) { - return c.startJob(ch, "org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0)) -} - -// KillUnit takes the unit name and a UNIX signal number to send. All of the unit's -// processes are killed. -func (c *Conn) KillUnit(name string, signal int32) { - c.sysobj.Call("org.freedesktop.systemd1.Manager.KillUnit", 0, name, "all", signal).Store() -} - -// ResetFailedUnit resets the "failed" state of a specific unit. -func (c *Conn) ResetFailedUnit(name string) error { - return c.sysobj.Call("org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store() -} - -// SystemState returns the systemd state. Equivalent to `systemctl is-system-running`. -func (c *Conn) SystemState() (*Property, error) { - var err error - var prop dbus.Variant - - obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1") - err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop) - if err != nil { - return nil, err - } - - return &Property{Name: "SystemState", Value: prop}, nil -} - -// getProperties takes the unit path and returns all of its dbus object properties, for the given dbus interface -func (c *Conn) getProperties(path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) { - var err error - var props map[string]dbus.Variant - - if !path.IsValid() { - return nil, fmt.Errorf("invalid unit name: %v", path) - } - - obj := c.sysconn.Object("org.freedesktop.systemd1", path) - err = obj.Call("org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props) - if err != nil { - return nil, err - } - - out := make(map[string]interface{}, len(props)) - for k, v := range props { - out[k] = v.Value() - } - - return out, nil -} - -// GetUnitProperties takes the (unescaped) unit name and returns all of its dbus object properties. -func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) { - path := unitPath(unit) - return c.getProperties(path, "org.freedesktop.systemd1.Unit") -} - -// GetUnitPathProperties takes the (escaped) unit path and returns all of its dbus object properties. -func (c *Conn) GetUnitPathProperties(path dbus.ObjectPath) (map[string]interface{}, error) { - return c.getProperties(path, "org.freedesktop.systemd1.Unit") -} - -// GetAllProperties takes the (unescaped) unit name and returns all of its dbus object properties. -func (c *Conn) GetAllProperties(unit string) (map[string]interface{}, error) { - path := unitPath(unit) - return c.getProperties(path, "") -} - -func (c *Conn) getProperty(unit string, dbusInterface string, propertyName string) (*Property, error) { - var err error - var prop dbus.Variant - - path := unitPath(unit) - if !path.IsValid() { - return nil, errors.New("invalid unit name: " + unit) - } - - obj := c.sysconn.Object("org.freedesktop.systemd1", path) - err = obj.Call("org.freedesktop.DBus.Properties.Get", 0, dbusInterface, propertyName).Store(&prop) - if err != nil { - return nil, err - } - - return &Property{Name: propertyName, Value: prop}, nil -} - -func (c *Conn) GetUnitProperty(unit string, propertyName string) (*Property, error) { - return c.getProperty(unit, "org.freedesktop.systemd1.Unit", propertyName) -} - -// GetServiceProperty returns property for given service name and property name -func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) { - return c.getProperty(service, "org.freedesktop.systemd1.Service", propertyName) -} - -// GetUnitTypeProperties returns the extra properties for a unit, specific to the unit type. -// Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope -// return "dbus.Error: Unknown interface" if the unitType is not the correct type of the unit -func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error) { - path := unitPath(unit) - return c.getProperties(path, "org.freedesktop.systemd1."+unitType) -} - -// SetUnitProperties() may be used to modify certain unit properties at runtime. -// Not all properties may be changed at runtime, but many resource management -// settings (primarily those in systemd.cgroup(5)) may. The changes are applied -// instantly, and stored on disk for future boots, unless runtime is true, in which -// case the settings only apply until the next reboot. name is the name of the unit -// to modify. properties are the settings to set, encoded as an array of property -// name and value pairs. -func (c *Conn) SetUnitProperties(name string, runtime bool, properties ...Property) error { - return c.sysobj.Call("org.freedesktop.systemd1.Manager.SetUnitProperties", 0, name, runtime, properties).Store() -} - -func (c *Conn) GetUnitTypeProperty(unit string, unitType string, propertyName string) (*Property, error) { - return c.getProperty(unit, "org.freedesktop.systemd1."+unitType, propertyName) -} - -type UnitStatus struct { - Name string // The primary unit name as string - Description string // The human readable description string - LoadState string // The load state (i.e. whether the unit file has been loaded successfully) - ActiveState string // The active state (i.e. whether the unit is currently started or not) - SubState string // The sub state (a more fine-grained version of the active state that is specific to the unit type, which the active state is not) - Followed string // A unit that is being followed in its state by this unit, if there is any, otherwise the empty string. - Path dbus.ObjectPath // The unit object path - JobId uint32 // If there is a job queued for the job unit the numeric job id, 0 otherwise - JobType string // The job type as string - JobPath dbus.ObjectPath // The job object path -} - -type storeFunc func(retvalues ...interface{}) error - -func (c *Conn) listUnitsInternal(f storeFunc) ([]UnitStatus, error) { - result := make([][]interface{}, 0) - err := f(&result) - if err != nil { - return nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - status := make([]UnitStatus, len(result)) - statusInterface := make([]interface{}, len(status)) - for i := range status { - statusInterface[i] = &status[i] - } - - err = dbus.Store(resultInterface, statusInterface...) - if err != nil { - return nil, err - } - - return status, nil -} - -// ListUnits returns an array with all currently loaded units. Note that -// units may be known by multiple names at the same time, and hence there might -// be more unit names loaded than actual units behind them. -// Also note that a unit is only loaded if it is active and/or enabled. -// Units that are both disabled and inactive will thus not be returned. -func (c *Conn) ListUnits() ([]UnitStatus, error) { - return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnits", 0).Store) -} - -// ListUnitsFiltered returns an array with units filtered by state. -// It takes a list of units' statuses to filter. -func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) { - return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store) -} - -// ListUnitsByPatterns returns an array with units. -// It takes a list of units' statuses and names to filter. -// Note that units may be known by multiple names at the same time, -// and hence there might be more unit names loaded than actual units behind them. -func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) { - return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store) -} - -// ListUnitsByNames returns an array with units. It takes a list of units' -// names and returns an UnitStatus array. Comparing to ListUnitsByPatterns -// method, this method returns statuses even for inactive or non-existing -// units. Input array should contain exact unit names, but not patterns. -// Note: Requires systemd v230 or higher -func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error) { - return c.listUnitsInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store) -} - -type UnitFile struct { - Path string - Type string -} - -func (c *Conn) listUnitFilesInternal(f storeFunc) ([]UnitFile, error) { - result := make([][]interface{}, 0) - err := f(&result) - if err != nil { - return nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - files := make([]UnitFile, len(result)) - fileInterface := make([]interface{}, len(files)) - for i := range files { - fileInterface[i] = &files[i] - } - - err = dbus.Store(resultInterface, fileInterface...) - if err != nil { - return nil, err - } - - return files, nil -} - -// ListUnitFiles returns an array of all available units on disk. -func (c *Conn) ListUnitFiles() ([]UnitFile, error) { - return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store) -} - -// ListUnitFilesByPatterns returns an array of all available units on disk matched the patterns. -func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) { - return c.listUnitFilesInternal(c.sysobj.Call("org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store) -} - -type LinkUnitFileChange EnableUnitFileChange - -// LinkUnitFiles() links unit files (that are located outside of the -// usual unit search paths) into the unit search path. -// -// It takes a list of absolute paths to unit files to link and two -// booleans. The first boolean controls whether the unit shall be -// enabled for runtime only (true, /run), or persistently (false, -// /etc). -// The second controls whether symlinks pointing to other units shall -// be replaced if necessary. -// -// This call returns a list of the changes made. The list consists of -// structures with three strings: the type of the change (one of symlink -// or unlink), the file name of the symlink and the destination of the -// symlink. -func (c *Conn) LinkUnitFiles(files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) { - result := make([][]interface{}, 0) - err := c.sysobj.Call("org.freedesktop.systemd1.Manager.LinkUnitFiles", 0, files, runtime, force).Store(&result) - if err != nil { - return nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - changes := make([]LinkUnitFileChange, len(result)) - changesInterface := make([]interface{}, len(changes)) - for i := range changes { - changesInterface[i] = &changes[i] - } - - err = dbus.Store(resultInterface, changesInterface...) - if err != nil { - return nil, err - } - - return changes, nil -} - -// EnableUnitFiles() may be used to enable one or more units in the system (by -// creating symlinks to them in /etc or /run). -// -// It takes a list of unit files to enable (either just file names or full -// absolute paths if the unit files are residing outside the usual unit -// search paths), and two booleans: the first controls whether the unit shall -// be enabled for runtime only (true, /run), or persistently (false, /etc). -// The second one controls whether symlinks pointing to other units shall -// be replaced if necessary. -// -// This call returns one boolean and an array with the changes made. The -// boolean signals whether the unit files contained any enablement -// information (i.e. an [Install]) section. The changes list consists of -// structures with three strings: the type of the change (one of symlink -// or unlink), the file name of the symlink and the destination of the -// symlink. -func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) { - var carries_install_info bool - - result := make([][]interface{}, 0) - err := c.sysobj.Call("org.freedesktop.systemd1.Manager.EnableUnitFiles", 0, files, runtime, force).Store(&carries_install_info, &result) - if err != nil { - return false, nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - changes := make([]EnableUnitFileChange, len(result)) - changesInterface := make([]interface{}, len(changes)) - for i := range changes { - changesInterface[i] = &changes[i] - } - - err = dbus.Store(resultInterface, changesInterface...) - if err != nil { - return false, nil, err - } - - return carries_install_info, changes, nil -} - -type EnableUnitFileChange struct { - Type string // Type of the change (one of symlink or unlink) - Filename string // File name of the symlink - Destination string // Destination of the symlink -} - -// DisableUnitFiles() may be used to disable one or more units in the system (by -// removing symlinks to them from /etc or /run). -// -// It takes a list of unit files to disable (either just file names or full -// absolute paths if the unit files are residing outside the usual unit -// search paths), and one boolean: whether the unit was enabled for runtime -// only (true, /run), or persistently (false, /etc). -// -// This call returns an array with the changes made. The changes list -// consists of structures with three strings: the type of the change (one of -// symlink or unlink), the file name of the symlink and the destination of the -// symlink. -func (c *Conn) DisableUnitFiles(files []string, runtime bool) ([]DisableUnitFileChange, error) { - result := make([][]interface{}, 0) - err := c.sysobj.Call("org.freedesktop.systemd1.Manager.DisableUnitFiles", 0, files, runtime).Store(&result) - if err != nil { - return nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - changes := make([]DisableUnitFileChange, len(result)) - changesInterface := make([]interface{}, len(changes)) - for i := range changes { - changesInterface[i] = &changes[i] - } - - err = dbus.Store(resultInterface, changesInterface...) - if err != nil { - return nil, err - } - - return changes, nil -} - -type DisableUnitFileChange struct { - Type string // Type of the change (one of symlink or unlink) - Filename string // File name of the symlink - Destination string // Destination of the symlink -} - -// MaskUnitFiles masks one or more units in the system -// -// It takes three arguments: -// * list of units to mask (either just file names or full -// absolute paths if the unit files are residing outside -// the usual unit search paths) -// * runtime to specify whether the unit was enabled for runtime -// only (true, /run/systemd/..), or persistently (false, /etc/systemd/..) -// * force flag -func (c *Conn) MaskUnitFiles(files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) { - result := make([][]interface{}, 0) - err := c.sysobj.Call("org.freedesktop.systemd1.Manager.MaskUnitFiles", 0, files, runtime, force).Store(&result) - if err != nil { - return nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - changes := make([]MaskUnitFileChange, len(result)) - changesInterface := make([]interface{}, len(changes)) - for i := range changes { - changesInterface[i] = &changes[i] - } - - err = dbus.Store(resultInterface, changesInterface...) - if err != nil { - return nil, err - } - - return changes, nil -} - -type MaskUnitFileChange struct { - Type string // Type of the change (one of symlink or unlink) - Filename string // File name of the symlink - Destination string // Destination of the symlink -} - -// UnmaskUnitFiles unmasks one or more units in the system -// -// It takes two arguments: -// * list of unit files to mask (either just file names or full -// absolute paths if the unit files are residing outside -// the usual unit search paths) -// * runtime to specify whether the unit was enabled for runtime -// only (true, /run/systemd/..), or persistently (false, /etc/systemd/..) -func (c *Conn) UnmaskUnitFiles(files []string, runtime bool) ([]UnmaskUnitFileChange, error) { - result := make([][]interface{}, 0) - err := c.sysobj.Call("org.freedesktop.systemd1.Manager.UnmaskUnitFiles", 0, files, runtime).Store(&result) - if err != nil { - return nil, err - } - - resultInterface := make([]interface{}, len(result)) - for i := range result { - resultInterface[i] = result[i] - } - - changes := make([]UnmaskUnitFileChange, len(result)) - changesInterface := make([]interface{}, len(changes)) - for i := range changes { - changesInterface[i] = &changes[i] - } - - err = dbus.Store(resultInterface, changesInterface...) - if err != nil { - return nil, err - } - - return changes, nil -} - -type UnmaskUnitFileChange struct { - Type string // Type of the change (one of symlink or unlink) - Filename string // File name of the symlink - Destination string // Destination of the symlink -} - -// Reload instructs systemd to scan for and reload unit files. This is -// equivalent to a 'systemctl daemon-reload'. -func (c *Conn) Reload() error { - return c.sysobj.Call("org.freedesktop.systemd1.Manager.Reload", 0).Store() -} - -func unitPath(name string) dbus.ObjectPath { - return dbus.ObjectPath("/org/freedesktop/systemd1/unit/" + PathBusEscape(name)) -} - -// unitName returns the unescaped base element of the supplied escaped path -func unitName(dpath dbus.ObjectPath) string { - return pathBusUnescape(path.Base(string(dpath))) -} diff --git a/vendor/github.com/coreos/go-systemd/LICENSE b/vendor/github.com/coreos/go-systemd/v22/LICENSE similarity index 100% rename from vendor/github.com/coreos/go-systemd/LICENSE rename to vendor/github.com/coreos/go-systemd/v22/LICENSE diff --git a/vendor/github.com/coreos/go-systemd/NOTICE b/vendor/github.com/coreos/go-systemd/v22/NOTICE similarity index 100% rename from vendor/github.com/coreos/go-systemd/NOTICE rename to vendor/github.com/coreos/go-systemd/v22/NOTICE diff --git a/vendor/github.com/coreos/go-systemd/dbus/dbus.go b/vendor/github.com/coreos/go-systemd/v22/dbus/dbus.go similarity index 73% rename from vendor/github.com/coreos/go-systemd/dbus/dbus.go rename to vendor/github.com/coreos/go-systemd/v22/dbus/dbus.go index f652582e..147f756f 100644 --- a/vendor/github.com/coreos/go-systemd/dbus/dbus.go +++ b/vendor/github.com/coreos/go-systemd/v22/dbus/dbus.go @@ -16,6 +16,7 @@ package dbus import ( + "context" "encoding/hex" "fmt" "os" @@ -23,7 +24,7 @@ import ( "strings" "sync" - "github.com/godbus/dbus" + "github.com/godbus/dbus/v5" ) const ( @@ -110,51 +111,76 @@ type Conn struct { } } -// New establishes a connection to any available bus and authenticates. -// Callers should call Close() when done with the connection. +// Deprecated: use NewWithContext instead. func New() (*Conn, error) { - conn, err := NewSystemConnection() + return NewWithContext(context.Background()) +} + +// NewWithContext establishes a connection to any available bus and authenticates. +// Callers should call Close() when done with the connection. +func NewWithContext(ctx context.Context) (*Conn, error) { + conn, err := NewSystemConnectionContext(ctx) if err != nil && os.Geteuid() == 0 { - return NewSystemdConnection() + return NewSystemdConnectionContext(ctx) } return conn, err } -// NewSystemConnection establishes a connection to the system bus and authenticates. -// Callers should call Close() when done with the connection +// Deprecated: use NewSystemConnectionContext instead. func NewSystemConnection() (*Conn, error) { + return NewSystemConnectionContext(context.Background()) +} + +// NewSystemConnectionContext establishes a connection to the system bus and authenticates. +// Callers should call Close() when done with the connection. +func NewSystemConnectionContext(ctx context.Context) (*Conn, error) { return NewConnection(func() (*dbus.Conn, error) { - return dbusAuthHelloConnection(dbus.SystemBusPrivate) + return dbusAuthHelloConnection(ctx, dbus.SystemBusPrivate) }) } -// NewUserConnection establishes a connection to the session bus and +// Deprecated: use NewUserConnectionContext instead. +func NewUserConnection() (*Conn, error) { + return NewUserConnectionContext(context.Background()) +} + +// NewUserConnectionContext establishes a connection to the session bus and // authenticates. This can be used to connect to systemd user instances. // Callers should call Close() when done with the connection. -func NewUserConnection() (*Conn, error) { +func NewUserConnectionContext(ctx context.Context) (*Conn, error) { return NewConnection(func() (*dbus.Conn, error) { - return dbusAuthHelloConnection(dbus.SessionBusPrivate) + return dbusAuthHelloConnection(ctx, dbus.SessionBusPrivate) }) } -// NewSystemdConnection establishes a private, direct connection to systemd. +// Deprecated: use NewSystemdConnectionContext instead. +func NewSystemdConnection() (*Conn, error) { + return NewSystemdConnectionContext(context.Background()) +} + +// NewSystemdConnectionContext establishes a private, direct connection to systemd. // This can be used for communicating with systemd without a dbus daemon. // Callers should call Close() when done with the connection. -func NewSystemdConnection() (*Conn, error) { +func NewSystemdConnectionContext(ctx context.Context) (*Conn, error) { return NewConnection(func() (*dbus.Conn, error) { // We skip Hello when talking directly to systemd. - return dbusAuthConnection(func(opts ...dbus.ConnOption) (*dbus.Conn, error) { - return dbus.Dial("unix:path=/run/systemd/private") + return dbusAuthConnection(ctx, func(opts ...dbus.ConnOption) (*dbus.Conn, error) { + return dbus.Dial("unix:path=/run/systemd/private", opts...) }) }) } -// Close closes an established connection +// Close closes an established connection. func (c *Conn) Close() { c.sysconn.Close() c.sigconn.Close() } +// Connected returns whether conn is connected +func (c *Conn) Connected() bool { + return c.sysconn.Connected() && c.sigconn.Connected() +} + // NewConnection establishes a connection to a bus using a caller-supplied function. // This allows connecting to remote buses through a user-supplied mechanism. // The supplied function may be called multiple times, and should return independent connections. @@ -192,7 +218,7 @@ func NewConnection(dialBus func() (*dbus.Conn, error)) (*Conn, error) { // GetManagerProperty returns the value of a property on the org.freedesktop.systemd1.Manager // interface. The value is returned in its string representation, as defined at -// https://developer.gnome.org/glib/unstable/gvariant-text.html +// https://developer.gnome.org/glib/unstable/gvariant-text.html. func (c *Conn) GetManagerProperty(prop string) (string, error) { variant, err := c.sysobj.GetProperty("org.freedesktop.systemd1.Manager." + prop) if err != nil { @@ -201,8 +227,8 @@ func (c *Conn) GetManagerProperty(prop string) (string, error) { return variant.String(), nil } -func dbusAuthConnection(createBus func(opts ...dbus.ConnOption) (*dbus.Conn, error)) (*dbus.Conn, error) { - conn, err := createBus() +func dbusAuthConnection(ctx context.Context, createBus func(opts ...dbus.ConnOption) (*dbus.Conn, error)) (*dbus.Conn, error) { + conn, err := createBus(dbus.WithContext(ctx)) if err != nil { return nil, err } @@ -221,8 +247,8 @@ func dbusAuthConnection(createBus func(opts ...dbus.ConnOption) (*dbus.Conn, err return conn, nil } -func dbusAuthHelloConnection(createBus func(opts ...dbus.ConnOption) (*dbus.Conn, error)) (*dbus.Conn, error) { - conn, err := dbusAuthConnection(createBus) +func dbusAuthHelloConnection(ctx context.Context, createBus func(opts ...dbus.ConnOption) (*dbus.Conn, error)) (*dbus.Conn, error) { + conn, err := dbusAuthConnection(ctx, createBus) if err != nil { return nil, err } diff --git a/vendor/github.com/coreos/go-systemd/v22/dbus/methods.go b/vendor/github.com/coreos/go-systemd/v22/dbus/methods.go new file mode 100644 index 00000000..074148cb --- /dev/null +++ b/vendor/github.com/coreos/go-systemd/v22/dbus/methods.go @@ -0,0 +1,864 @@ +// Copyright 2015, 2018 CoreOS, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dbus + +import ( + "context" + "errors" + "fmt" + "path" + "strconv" + + "github.com/godbus/dbus/v5" +) + +// Who can be used to specify which process to kill in the unit via the KillUnitWithTarget API +type Who string + +const ( + // All sends the signal to all processes in the unit + All Who = "all" + // Main sends the signal to the main process of the unit + Main Who = "main" + // Control sends the signal to the control process of the unit + Control Who = "control" +) + +func (c *Conn) jobComplete(signal *dbus.Signal) { + var id uint32 + var job dbus.ObjectPath + var unit string + var result string + dbus.Store(signal.Body, &id, &job, &unit, &result) + c.jobListener.Lock() + out, ok := c.jobListener.jobs[job] + if ok { + out <- result + delete(c.jobListener.jobs, job) + } + c.jobListener.Unlock() +} + +func (c *Conn) startJob(ctx context.Context, ch chan<- string, job string, args ...interface{}) (int, error) { + if ch != nil { + c.jobListener.Lock() + defer c.jobListener.Unlock() + } + + var p dbus.ObjectPath + err := c.sysobj.CallWithContext(ctx, job, 0, args...).Store(&p) + if err != nil { + return 0, err + } + + if ch != nil { + c.jobListener.jobs[p] = ch + } + + // ignore error since 0 is fine if conversion fails + jobID, _ := strconv.Atoi(path.Base(string(p))) + + return jobID, nil +} + +// Deprecated: use StartUnitContext instead. +func (c *Conn) StartUnit(name string, mode string, ch chan<- string) (int, error) { + return c.StartUnitContext(context.Background(), name, mode, ch) +} + +// StartUnitContext enqueues a start job and depending jobs, if any (unless otherwise +// specified by the mode string). +// +// Takes the unit to activate, plus a mode string. The mode needs to be one of +// replace, fail, isolate, ignore-dependencies, ignore-requirements. If +// "replace" the call will start the unit and its dependencies, possibly +// replacing already queued jobs that conflict with this. If "fail" the call +// will start the unit and its dependencies, but will fail if this would change +// an already queued job. If "isolate" the call will start the unit in question +// and terminate all units that aren't dependencies of it. If +// "ignore-dependencies" it will start a unit but ignore all its dependencies. +// If "ignore-requirements" it will start a unit but only ignore the +// requirement dependencies. It is not recommended to make use of the latter +// two options. +// +// If the provided channel is non-nil, a result string will be sent to it upon +// job completion: one of done, canceled, timeout, failed, dependency, skipped. +// done indicates successful execution of a job. canceled indicates that a job +// has been canceled before it finished execution. timeout indicates that the +// job timeout was reached. failed indicates that the job failed. dependency +// indicates that a job this job has been depending on failed and the job hence +// has been removed too. skipped indicates that a job was skipped because it +// didn't apply to the units current state. +// +// If no error occurs, the ID of the underlying systemd job will be returned. There +// does exist the possibility for no error to be returned, but for the returned job +// ID to be 0. In this case, the actual underlying ID is not 0 and this datapoint +// should not be considered authoritative. +// +// If an error does occur, it will be returned to the user alongside a job ID of 0. +func (c *Conn) StartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StartUnit", name, mode) +} + +// Deprecated: use StopUnitContext instead. +func (c *Conn) StopUnit(name string, mode string, ch chan<- string) (int, error) { + return c.StopUnitContext(context.Background(), name, mode, ch) +} + +// StopUnitContext is similar to StartUnitContext, but stops the specified unit +// rather than starting it. +func (c *Conn) StopUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StopUnit", name, mode) +} + +// Deprecated: use ReloadUnitContext instead. +func (c *Conn) ReloadUnit(name string, mode string, ch chan<- string) (int, error) { + return c.ReloadUnitContext(context.Background(), name, mode, ch) +} + +// ReloadUnitContext reloads a unit. Reloading is done only if the unit +// is already running, and fails otherwise. +func (c *Conn) ReloadUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.ReloadUnit", name, mode) +} + +// Deprecated: use RestartUnitContext instead. +func (c *Conn) RestartUnit(name string, mode string, ch chan<- string) (int, error) { + return c.RestartUnitContext(context.Background(), name, mode, ch) +} + +// RestartUnitContext restarts a service. If a service is restarted that isn't +// running it will be started. +func (c *Conn) RestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.RestartUnit", name, mode) +} + +// Deprecated: use TryRestartUnitContext instead. +func (c *Conn) TryRestartUnit(name string, mode string, ch chan<- string) (int, error) { + return c.TryRestartUnitContext(context.Background(), name, mode, ch) +} + +// TryRestartUnitContext is like RestartUnitContext, except that a service that +// isn't running is not affected by the restart. +func (c *Conn) TryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.TryRestartUnit", name, mode) +} + +// Deprecated: use ReloadOrRestartUnitContext instead. +func (c *Conn) ReloadOrRestartUnit(name string, mode string, ch chan<- string) (int, error) { + return c.ReloadOrRestartUnitContext(context.Background(), name, mode, ch) +} + +// ReloadOrRestartUnitContext attempts a reload if the unit supports it and use +// a restart otherwise. +func (c *Conn) ReloadOrRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.ReloadOrRestartUnit", name, mode) +} + +// Deprecated: use ReloadOrTryRestartUnitContext instead. +func (c *Conn) ReloadOrTryRestartUnit(name string, mode string, ch chan<- string) (int, error) { + return c.ReloadOrTryRestartUnitContext(context.Background(), name, mode, ch) +} + +// ReloadOrTryRestartUnitContext attempts a reload if the unit supports it, +// and use a "Try" flavored restart otherwise. +func (c *Conn) ReloadOrTryRestartUnitContext(ctx context.Context, name string, mode string, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.ReloadOrTryRestartUnit", name, mode) +} + +// Deprecated: use StartTransientUnitContext instead. +func (c *Conn) StartTransientUnit(name string, mode string, properties []Property, ch chan<- string) (int, error) { + return c.StartTransientUnitContext(context.Background(), name, mode, properties, ch) +} + +// StartTransientUnitContext may be used to create and start a transient unit, which +// will be released as soon as it is not running or referenced anymore or the +// system is rebooted. name is the unit name including suffix, and must be +// unique. mode is the same as in StartUnitContext, properties contains properties +// of the unit. +func (c *Conn) StartTransientUnitContext(ctx context.Context, name string, mode string, properties []Property, ch chan<- string) (int, error) { + return c.startJob(ctx, ch, "org.freedesktop.systemd1.Manager.StartTransientUnit", name, mode, properties, make([]PropertyCollection, 0)) +} + +// Deprecated: use KillUnitContext instead. +func (c *Conn) KillUnit(name string, signal int32) { + c.KillUnitContext(context.Background(), name, signal) +} + +// KillUnitContext takes the unit name and a UNIX signal number to send. +// All of the unit's processes are killed. +func (c *Conn) KillUnitContext(ctx context.Context, name string, signal int32) { + c.KillUnitWithTarget(ctx, name, All, signal) +} + +// KillUnitWithTarget is like KillUnitContext, but allows you to specify which +// process in the unit to send the signal to. +func (c *Conn) KillUnitWithTarget(ctx context.Context, name string, target Who, signal int32) error { + return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.KillUnit", 0, name, string(target), signal).Store() +} + +// Deprecated: use ResetFailedUnitContext instead. +func (c *Conn) ResetFailedUnit(name string) error { + return c.ResetFailedUnitContext(context.Background(), name) +} + +// ResetFailedUnitContext resets the "failed" state of a specific unit. +func (c *Conn) ResetFailedUnitContext(ctx context.Context, name string) error { + return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ResetFailedUnit", 0, name).Store() +} + +// Deprecated: use SystemStateContext instead. +func (c *Conn) SystemState() (*Property, error) { + return c.SystemStateContext(context.Background()) +} + +// SystemStateContext returns the systemd state. Equivalent to +// systemctl is-system-running. +func (c *Conn) SystemStateContext(ctx context.Context) (*Property, error) { + var err error + var prop dbus.Variant + + obj := c.sysconn.Object("org.freedesktop.systemd1", "/org/freedesktop/systemd1") + err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.Get", 0, "org.freedesktop.systemd1.Manager", "SystemState").Store(&prop) + if err != nil { + return nil, err + } + + return &Property{Name: "SystemState", Value: prop}, nil +} + +// getProperties takes the unit path and returns all of its dbus object properties, for the given dbus interface. +func (c *Conn) getProperties(ctx context.Context, path dbus.ObjectPath, dbusInterface string) (map[string]interface{}, error) { + var err error + var props map[string]dbus.Variant + + if !path.IsValid() { + return nil, fmt.Errorf("invalid unit name: %v", path) + } + + obj := c.sysconn.Object("org.freedesktop.systemd1", path) + err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.GetAll", 0, dbusInterface).Store(&props) + if err != nil { + return nil, err + } + + out := make(map[string]interface{}, len(props)) + for k, v := range props { + out[k] = v.Value() + } + + return out, nil +} + +// Deprecated: use GetUnitPropertiesContext instead. +func (c *Conn) GetUnitProperties(unit string) (map[string]interface{}, error) { + return c.GetUnitPropertiesContext(context.Background(), unit) +} + +// GetUnitPropertiesContext takes the (unescaped) unit name and returns all of +// its dbus object properties. +func (c *Conn) GetUnitPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error) { + path := unitPath(unit) + return c.getProperties(ctx, path, "org.freedesktop.systemd1.Unit") +} + +// Deprecated: use GetUnitPathPropertiesContext instead. +func (c *Conn) GetUnitPathProperties(path dbus.ObjectPath) (map[string]interface{}, error) { + return c.GetUnitPathPropertiesContext(context.Background(), path) +} + +// GetUnitPathPropertiesContext takes the (escaped) unit path and returns all +// of its dbus object properties. +func (c *Conn) GetUnitPathPropertiesContext(ctx context.Context, path dbus.ObjectPath) (map[string]interface{}, error) { + return c.getProperties(ctx, path, "org.freedesktop.systemd1.Unit") +} + +// Deprecated: use GetAllPropertiesContext instead. +func (c *Conn) GetAllProperties(unit string) (map[string]interface{}, error) { + return c.GetAllPropertiesContext(context.Background(), unit) +} + +// GetAllPropertiesContext takes the (unescaped) unit name and returns all of +// its dbus object properties. +func (c *Conn) GetAllPropertiesContext(ctx context.Context, unit string) (map[string]interface{}, error) { + path := unitPath(unit) + return c.getProperties(ctx, path, "") +} + +func (c *Conn) getProperty(ctx context.Context, unit string, dbusInterface string, propertyName string) (*Property, error) { + var err error + var prop dbus.Variant + + path := unitPath(unit) + if !path.IsValid() { + return nil, errors.New("invalid unit name: " + unit) + } + + obj := c.sysconn.Object("org.freedesktop.systemd1", path) + err = obj.CallWithContext(ctx, "org.freedesktop.DBus.Properties.Get", 0, dbusInterface, propertyName).Store(&prop) + if err != nil { + return nil, err + } + + return &Property{Name: propertyName, Value: prop}, nil +} + +// Deprecated: use GetUnitPropertyContext instead. +func (c *Conn) GetUnitProperty(unit string, propertyName string) (*Property, error) { + return c.GetUnitPropertyContext(context.Background(), unit, propertyName) +} + +// GetUnitPropertyContext takes an (unescaped) unit name, and a property name, +// and returns the property value. +func (c *Conn) GetUnitPropertyContext(ctx context.Context, unit string, propertyName string) (*Property, error) { + return c.getProperty(ctx, unit, "org.freedesktop.systemd1.Unit", propertyName) +} + +// Deprecated: use GetServicePropertyContext instead. +func (c *Conn) GetServiceProperty(service string, propertyName string) (*Property, error) { + return c.GetServicePropertyContext(context.Background(), service, propertyName) +} + +// GetServiceProperty returns property for given service name and property name. +func (c *Conn) GetServicePropertyContext(ctx context.Context, service string, propertyName string) (*Property, error) { + return c.getProperty(ctx, service, "org.freedesktop.systemd1.Service", propertyName) +} + +// Deprecated: use GetUnitTypePropertiesContext instead. +func (c *Conn) GetUnitTypeProperties(unit string, unitType string) (map[string]interface{}, error) { + return c.GetUnitTypePropertiesContext(context.Background(), unit, unitType) +} + +// GetUnitTypePropertiesContext returns the extra properties for a unit, specific to the unit type. +// Valid values for unitType: Service, Socket, Target, Device, Mount, Automount, Snapshot, Timer, Swap, Path, Slice, Scope. +// Returns "dbus.Error: Unknown interface" error if the unitType is not the correct type of the unit. +func (c *Conn) GetUnitTypePropertiesContext(ctx context.Context, unit string, unitType string) (map[string]interface{}, error) { + path := unitPath(unit) + return c.getProperties(ctx, path, "org.freedesktop.systemd1."+unitType) +} + +// Deprecated: use SetUnitPropertiesContext instead. +func (c *Conn) SetUnitProperties(name string, runtime bool, properties ...Property) error { + return c.SetUnitPropertiesContext(context.Background(), name, runtime, properties...) +} + +// SetUnitPropertiesContext may be used to modify certain unit properties at runtime. +// Not all properties may be changed at runtime, but many resource management +// settings (primarily those in systemd.cgroup(5)) may. The changes are applied +// instantly, and stored on disk for future boots, unless runtime is true, in which +// case the settings only apply until the next reboot. name is the name of the unit +// to modify. properties are the settings to set, encoded as an array of property +// name and value pairs. +func (c *Conn) SetUnitPropertiesContext(ctx context.Context, name string, runtime bool, properties ...Property) error { + return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.SetUnitProperties", 0, name, runtime, properties).Store() +} + +// Deprecated: use GetUnitTypePropertyContext instead. +func (c *Conn) GetUnitTypeProperty(unit string, unitType string, propertyName string) (*Property, error) { + return c.GetUnitTypePropertyContext(context.Background(), unit, unitType, propertyName) +} + +// GetUnitTypePropertyContext takes a property name, a unit name, and a unit type, +// and returns a property value. For valid values of unitType, see GetUnitTypePropertiesContext. +func (c *Conn) GetUnitTypePropertyContext(ctx context.Context, unit string, unitType string, propertyName string) (*Property, error) { + return c.getProperty(ctx, unit, "org.freedesktop.systemd1."+unitType, propertyName) +} + +type UnitStatus struct { + Name string // The primary unit name as string + Description string // The human readable description string + LoadState string // The load state (i.e. whether the unit file has been loaded successfully) + ActiveState string // The active state (i.e. whether the unit is currently started or not) + SubState string // The sub state (a more fine-grained version of the active state that is specific to the unit type, which the active state is not) + Followed string // A unit that is being followed in its state by this unit, if there is any, otherwise the empty string. + Path dbus.ObjectPath // The unit object path + JobId uint32 // If there is a job queued for the job unit the numeric job id, 0 otherwise + JobType string // The job type as string + JobPath dbus.ObjectPath // The job object path +} + +type storeFunc func(retvalues ...interface{}) error + +func (c *Conn) listUnitsInternal(f storeFunc) ([]UnitStatus, error) { + result := make([][]interface{}, 0) + err := f(&result) + if err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + status := make([]UnitStatus, len(result)) + statusInterface := make([]interface{}, len(status)) + for i := range status { + statusInterface[i] = &status[i] + } + + err = dbus.Store(resultInterface, statusInterface...) + if err != nil { + return nil, err + } + + return status, nil +} + +// GetUnitByPID returns the unit object path of the unit a process ID +// belongs to. It takes a UNIX PID and returns the object path. The PID must +// refer to an existing system process +func (c *Conn) GetUnitByPID(ctx context.Context, pid uint32) (dbus.ObjectPath, error) { + var result dbus.ObjectPath + + err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.GetUnitByPID", 0, pid).Store(&result) + + return result, err +} + +// GetUnitNameByPID returns the name of the unit a process ID belongs to. It +// takes a UNIX PID and returns the object path. The PID must refer to an +// existing system process +func (c *Conn) GetUnitNameByPID(ctx context.Context, pid uint32) (string, error) { + path, err := c.GetUnitByPID(ctx, pid) + if err != nil { + return "", err + } + + return unitName(path), nil +} + +// Deprecated: use ListUnitsContext instead. +func (c *Conn) ListUnits() ([]UnitStatus, error) { + return c.ListUnitsContext(context.Background()) +} + +// ListUnitsContext returns an array with all currently loaded units. Note that +// units may be known by multiple names at the same time, and hence there might +// be more unit names loaded than actual units behind them. +// Also note that a unit is only loaded if it is active and/or enabled. +// Units that are both disabled and inactive will thus not be returned. +func (c *Conn) ListUnitsContext(ctx context.Context) ([]UnitStatus, error) { + return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnits", 0).Store) +} + +// Deprecated: use ListUnitsFilteredContext instead. +func (c *Conn) ListUnitsFiltered(states []string) ([]UnitStatus, error) { + return c.ListUnitsFilteredContext(context.Background(), states) +} + +// ListUnitsFilteredContext returns an array with units filtered by state. +// It takes a list of units' statuses to filter. +func (c *Conn) ListUnitsFilteredContext(ctx context.Context, states []string) ([]UnitStatus, error) { + return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsFiltered", 0, states).Store) +} + +// Deprecated: use ListUnitsByPatternsContext instead. +func (c *Conn) ListUnitsByPatterns(states []string, patterns []string) ([]UnitStatus, error) { + return c.ListUnitsByPatternsContext(context.Background(), states, patterns) +} + +// ListUnitsByPatternsContext returns an array with units. +// It takes a list of units' statuses and names to filter. +// Note that units may be known by multiple names at the same time, +// and hence there might be more unit names loaded than actual units behind them. +func (c *Conn) ListUnitsByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitStatus, error) { + return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByPatterns", 0, states, patterns).Store) +} + +// Deprecated: use ListUnitsByNamesContext instead. +func (c *Conn) ListUnitsByNames(units []string) ([]UnitStatus, error) { + return c.ListUnitsByNamesContext(context.Background(), units) +} + +// ListUnitsByNamesContext returns an array with units. It takes a list of units' +// names and returns an UnitStatus array. Comparing to ListUnitsByPatternsContext +// method, this method returns statuses even for inactive or non-existing +// units. Input array should contain exact unit names, but not patterns. +// +// Requires systemd v230 or higher. +func (c *Conn) ListUnitsByNamesContext(ctx context.Context, units []string) ([]UnitStatus, error) { + return c.listUnitsInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitsByNames", 0, units).Store) +} + +type UnitFile struct { + Path string + Type string +} + +func (c *Conn) listUnitFilesInternal(f storeFunc) ([]UnitFile, error) { + result := make([][]interface{}, 0) + err := f(&result) + if err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + files := make([]UnitFile, len(result)) + fileInterface := make([]interface{}, len(files)) + for i := range files { + fileInterface[i] = &files[i] + } + + err = dbus.Store(resultInterface, fileInterface...) + if err != nil { + return nil, err + } + + return files, nil +} + +// Deprecated: use ListUnitFilesContext instead. +func (c *Conn) ListUnitFiles() ([]UnitFile, error) { + return c.ListUnitFilesContext(context.Background()) +} + +// ListUnitFiles returns an array of all available units on disk. +func (c *Conn) ListUnitFilesContext(ctx context.Context) ([]UnitFile, error) { + return c.listUnitFilesInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFiles", 0).Store) +} + +// Deprecated: use ListUnitFilesByPatternsContext instead. +func (c *Conn) ListUnitFilesByPatterns(states []string, patterns []string) ([]UnitFile, error) { + return c.ListUnitFilesByPatternsContext(context.Background(), states, patterns) +} + +// ListUnitFilesByPatternsContext returns an array of all available units on disk matched the patterns. +func (c *Conn) ListUnitFilesByPatternsContext(ctx context.Context, states []string, patterns []string) ([]UnitFile, error) { + return c.listUnitFilesInternal(c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListUnitFilesByPatterns", 0, states, patterns).Store) +} + +type LinkUnitFileChange EnableUnitFileChange + +// Deprecated: use LinkUnitFilesContext instead. +func (c *Conn) LinkUnitFiles(files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) { + return c.LinkUnitFilesContext(context.Background(), files, runtime, force) +} + +// LinkUnitFilesContext links unit files (that are located outside of the +// usual unit search paths) into the unit search path. +// +// It takes a list of absolute paths to unit files to link and two +// booleans. +// +// The first boolean controls whether the unit shall be +// enabled for runtime only (true, /run), or persistently (false, +// /etc). +// +// The second controls whether symlinks pointing to other units shall +// be replaced if necessary. +// +// This call returns a list of the changes made. The list consists of +// structures with three strings: the type of the change (one of symlink +// or unlink), the file name of the symlink and the destination of the +// symlink. +func (c *Conn) LinkUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]LinkUnitFileChange, error) { + result := make([][]interface{}, 0) + err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.LinkUnitFiles", 0, files, runtime, force).Store(&result) + if err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + changes := make([]LinkUnitFileChange, len(result)) + changesInterface := make([]interface{}, len(changes)) + for i := range changes { + changesInterface[i] = &changes[i] + } + + err = dbus.Store(resultInterface, changesInterface...) + if err != nil { + return nil, err + } + + return changes, nil +} + +// Deprecated: use EnableUnitFilesContext instead. +func (c *Conn) EnableUnitFiles(files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) { + return c.EnableUnitFilesContext(context.Background(), files, runtime, force) +} + +// EnableUnitFilesContext may be used to enable one or more units in the system +// (by creating symlinks to them in /etc or /run). +// +// It takes a list of unit files to enable (either just file names or full +// absolute paths if the unit files are residing outside the usual unit +// search paths), and two booleans: the first controls whether the unit shall +// be enabled for runtime only (true, /run), or persistently (false, /etc). +// The second one controls whether symlinks pointing to other units shall +// be replaced if necessary. +// +// This call returns one boolean and an array with the changes made. The +// boolean signals whether the unit files contained any enablement +// information (i.e. an [Install]) section. The changes list consists of +// structures with three strings: the type of the change (one of symlink +// or unlink), the file name of the symlink and the destination of the +// symlink. +func (c *Conn) EnableUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) (bool, []EnableUnitFileChange, error) { + var carries_install_info bool + + result := make([][]interface{}, 0) + err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.EnableUnitFiles", 0, files, runtime, force).Store(&carries_install_info, &result) + if err != nil { + return false, nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + changes := make([]EnableUnitFileChange, len(result)) + changesInterface := make([]interface{}, len(changes)) + for i := range changes { + changesInterface[i] = &changes[i] + } + + err = dbus.Store(resultInterface, changesInterface...) + if err != nil { + return false, nil, err + } + + return carries_install_info, changes, nil +} + +type EnableUnitFileChange struct { + Type string // Type of the change (one of symlink or unlink) + Filename string // File name of the symlink + Destination string // Destination of the symlink +} + +// Deprecated: use DisableUnitFilesContext instead. +func (c *Conn) DisableUnitFiles(files []string, runtime bool) ([]DisableUnitFileChange, error) { + return c.DisableUnitFilesContext(context.Background(), files, runtime) +} + +// DisableUnitFilesContext may be used to disable one or more units in the +// system (by removing symlinks to them from /etc or /run). +// +// It takes a list of unit files to disable (either just file names or full +// absolute paths if the unit files are residing outside the usual unit +// search paths), and one boolean: whether the unit was enabled for runtime +// only (true, /run), or persistently (false, /etc). +// +// This call returns an array with the changes made. The changes list +// consists of structures with three strings: the type of the change (one of +// symlink or unlink), the file name of the symlink and the destination of the +// symlink. +func (c *Conn) DisableUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]DisableUnitFileChange, error) { + result := make([][]interface{}, 0) + err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.DisableUnitFiles", 0, files, runtime).Store(&result) + if err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + changes := make([]DisableUnitFileChange, len(result)) + changesInterface := make([]interface{}, len(changes)) + for i := range changes { + changesInterface[i] = &changes[i] + } + + err = dbus.Store(resultInterface, changesInterface...) + if err != nil { + return nil, err + } + + return changes, nil +} + +type DisableUnitFileChange struct { + Type string // Type of the change (one of symlink or unlink) + Filename string // File name of the symlink + Destination string // Destination of the symlink +} + +// Deprecated: use MaskUnitFilesContext instead. +func (c *Conn) MaskUnitFiles(files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) { + return c.MaskUnitFilesContext(context.Background(), files, runtime, force) +} + +// MaskUnitFilesContext masks one or more units in the system. +// +// The files argument contains a list of units to mask (either just file names +// or full absolute paths if the unit files are residing outside the usual unit +// search paths). +// +// The runtime argument is used to specify whether the unit was enabled for +// runtime only (true, /run/systemd/..), or persistently (false, +// /etc/systemd/..). +func (c *Conn) MaskUnitFilesContext(ctx context.Context, files []string, runtime bool, force bool) ([]MaskUnitFileChange, error) { + result := make([][]interface{}, 0) + err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.MaskUnitFiles", 0, files, runtime, force).Store(&result) + if err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + changes := make([]MaskUnitFileChange, len(result)) + changesInterface := make([]interface{}, len(changes)) + for i := range changes { + changesInterface[i] = &changes[i] + } + + err = dbus.Store(resultInterface, changesInterface...) + if err != nil { + return nil, err + } + + return changes, nil +} + +type MaskUnitFileChange struct { + Type string // Type of the change (one of symlink or unlink) + Filename string // File name of the symlink + Destination string // Destination of the symlink +} + +// Deprecated: use UnmaskUnitFilesContext instead. +func (c *Conn) UnmaskUnitFiles(files []string, runtime bool) ([]UnmaskUnitFileChange, error) { + return c.UnmaskUnitFilesContext(context.Background(), files, runtime) +} + +// UnmaskUnitFilesContext unmasks one or more units in the system. +// +// It takes the list of unit files to mask (either just file names or full +// absolute paths if the unit files are residing outside the usual unit search +// paths), and a boolean runtime flag to specify whether the unit was enabled +// for runtime only (true, /run/systemd/..), or persistently (false, +// /etc/systemd/..). +func (c *Conn) UnmaskUnitFilesContext(ctx context.Context, files []string, runtime bool) ([]UnmaskUnitFileChange, error) { + result := make([][]interface{}, 0) + err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.UnmaskUnitFiles", 0, files, runtime).Store(&result) + if err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + changes := make([]UnmaskUnitFileChange, len(result)) + changesInterface := make([]interface{}, len(changes)) + for i := range changes { + changesInterface[i] = &changes[i] + } + + err = dbus.Store(resultInterface, changesInterface...) + if err != nil { + return nil, err + } + + return changes, nil +} + +type UnmaskUnitFileChange struct { + Type string // Type of the change (one of symlink or unlink) + Filename string // File name of the symlink + Destination string // Destination of the symlink +} + +// Deprecated: use ReloadContext instead. +func (c *Conn) Reload() error { + return c.ReloadContext(context.Background()) +} + +// ReloadContext instructs systemd to scan for and reload unit files. This is +// an equivalent to systemctl daemon-reload. +func (c *Conn) ReloadContext(ctx context.Context) error { + return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.Reload", 0).Store() +} + +func unitPath(name string) dbus.ObjectPath { + return dbus.ObjectPath("/org/freedesktop/systemd1/unit/" + PathBusEscape(name)) +} + +// unitName returns the unescaped base element of the supplied escaped path. +func unitName(dpath dbus.ObjectPath) string { + return pathBusUnescape(path.Base(string(dpath))) +} + +// JobStatus holds a currently queued job definition. +type JobStatus struct { + Id uint32 // The numeric job id + Unit string // The primary unit name for this job + JobType string // The job type as string + Status string // The job state as string + JobPath dbus.ObjectPath // The job object path + UnitPath dbus.ObjectPath // The unit object path +} + +// Deprecated: use ListJobsContext instead. +func (c *Conn) ListJobs() ([]JobStatus, error) { + return c.ListJobsContext(context.Background()) +} + +// ListJobsContext returns an array with all currently queued jobs. +func (c *Conn) ListJobsContext(ctx context.Context) ([]JobStatus, error) { + return c.listJobsInternal(ctx) +} + +func (c *Conn) listJobsInternal(ctx context.Context) ([]JobStatus, error) { + result := make([][]interface{}, 0) + if err := c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ListJobs", 0).Store(&result); err != nil { + return nil, err + } + + resultInterface := make([]interface{}, len(result)) + for i := range result { + resultInterface[i] = result[i] + } + + status := make([]JobStatus, len(result)) + statusInterface := make([]interface{}, len(status)) + for i := range status { + statusInterface[i] = &status[i] + } + + if err := dbus.Store(resultInterface, statusInterface...); err != nil { + return nil, err + } + + return status, nil +} + +// Freeze the cgroup associated with the unit. +// Note that FreezeUnit and ThawUnit are only supported on systems running with cgroup v2. +func (c *Conn) FreezeUnit(ctx context.Context, unit string) error { + return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.FreezeUnit", 0, unit).Store() +} + +// Unfreeze the cgroup associated with the unit. +func (c *Conn) ThawUnit(ctx context.Context, unit string) error { + return c.sysobj.CallWithContext(ctx, "org.freedesktop.systemd1.Manager.ThawUnit", 0, unit).Store() +} diff --git a/vendor/github.com/coreos/go-systemd/dbus/properties.go b/vendor/github.com/coreos/go-systemd/v22/dbus/properties.go similarity index 99% rename from vendor/github.com/coreos/go-systemd/dbus/properties.go rename to vendor/github.com/coreos/go-systemd/v22/dbus/properties.go index 6c818958..fb42b627 100644 --- a/vendor/github.com/coreos/go-systemd/dbus/properties.go +++ b/vendor/github.com/coreos/go-systemd/v22/dbus/properties.go @@ -15,7 +15,7 @@ package dbus import ( - "github.com/godbus/dbus" + "github.com/godbus/dbus/v5" ) // From the systemd docs: @@ -56,7 +56,7 @@ type execStart struct { // http://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart= func PropExecStart(command []string, uncleanIsFailure bool) Property { execStarts := []execStart{ - execStart{ + { Path: command[0], Args: command, UncleanIsFailure: uncleanIsFailure, diff --git a/vendor/github.com/coreos/go-systemd/dbus/set.go b/vendor/github.com/coreos/go-systemd/v22/dbus/set.go similarity index 100% rename from vendor/github.com/coreos/go-systemd/dbus/set.go rename to vendor/github.com/coreos/go-systemd/v22/dbus/set.go diff --git a/vendor/github.com/coreos/go-systemd/dbus/subscription.go b/vendor/github.com/coreos/go-systemd/v22/dbus/subscription.go similarity index 99% rename from vendor/github.com/coreos/go-systemd/dbus/subscription.go rename to vendor/github.com/coreos/go-systemd/v22/dbus/subscription.go index f6d7a08a..7e370fea 100644 --- a/vendor/github.com/coreos/go-systemd/dbus/subscription.go +++ b/vendor/github.com/coreos/go-systemd/v22/dbus/subscription.go @@ -19,7 +19,7 @@ import ( "log" "time" - "github.com/godbus/dbus" + "github.com/godbus/dbus/v5" ) const ( diff --git a/vendor/github.com/coreos/go-systemd/dbus/subscription_set.go b/vendor/github.com/coreos/go-systemd/v22/dbus/subscription_set.go similarity index 100% rename from vendor/github.com/coreos/go-systemd/dbus/subscription_set.go rename to vendor/github.com/coreos/go-systemd/v22/dbus/subscription_set.go diff --git a/vendor/github.com/dennwc/btrfs/LICENSE b/vendor/github.com/dennwc/btrfs/LICENSE new file mode 100644 index 00000000..261eeb9e --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/dennwc/btrfs/README.md b/vendor/github.com/dennwc/btrfs/README.md new file mode 100644 index 00000000..7c8481c8 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/README.md @@ -0,0 +1,2 @@ +# btrfs +Btrfs library in a pure Go diff --git a/vendor/github.com/dennwc/btrfs/btrfs.go b/vendor/github.com/dennwc/btrfs/btrfs.go new file mode 100644 index 00000000..f7c1af32 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/btrfs.go @@ -0,0 +1,300 @@ +package btrfs + +import ( + "fmt" + "io" + "os" + "path/filepath" + "strconv" + "syscall" + + "github.com/dennwc/ioctl" +) + +const SuperMagic uint32 = 0x9123683E + +func CloneFile(dst, src *os.File) error { + return iocClone(dst, src) +} + +func Open(path string, ro bool) (*FS, error) { + if ok, err := IsSubVolume(path); err != nil { + return nil, err + } else if !ok { + return nil, ErrNotBtrfs{Path: path} + } + var ( + dir *os.File + err error + ) + if ro { + dir, err = os.OpenFile(path, os.O_RDONLY|syscall.O_NOATIME, 0644) + if err != nil { + // Try without O_NOATIME as it requires ownership of the file + // or other priviliges + dir, err = os.OpenFile(path, os.O_RDONLY, 0644) + } + } else { + dir, err = os.Open(path) + } + if err != nil { + return nil, err + } else if st, err := dir.Stat(); err != nil { + dir.Close() + return nil, err + } else if !st.IsDir() { + dir.Close() + return nil, fmt.Errorf("not a directory: %s", path) + } + return &FS{f: dir}, nil +} + +type FS struct { + f *os.File +} + +func (f *FS) Close() error { + return f.f.Close() +} + +type Info struct { + MaxID uint64 + NumDevices uint64 + FSID FSID + NodeSize uint32 + SectorSize uint32 + CloneAlignment uint32 +} + +func (f *FS) SubVolumeID() (uint64, error) { + id, err := getFileRootID(f.f) + if err != nil { + return 0, err + } + return uint64(id), nil +} + +func (f *FS) Info() (out Info, err error) { + var arg btrfs_ioctl_fs_info_args + arg, err = iocFsInfo(f.f) + if err == nil { + out = Info{ + MaxID: arg.max_id, + NumDevices: arg.num_devices, + FSID: arg.fsid, + NodeSize: arg.nodesize, + SectorSize: arg.sectorsize, + CloneAlignment: arg.clone_alignment, + } + } + return +} + +type DevInfo struct { + UUID UUID + BytesUsed uint64 + TotalBytes uint64 + Path string +} + +func (f *FS) GetDevInfo(id uint64) (out DevInfo, err error) { + var arg btrfs_ioctl_dev_info_args + arg.devid = id + + if err = ioctl.Do(f.f, _BTRFS_IOC_DEV_INFO, &arg); err != nil { + return + } + out.UUID = arg.uuid + out.BytesUsed = arg.bytes_used + out.TotalBytes = arg.total_bytes + out.Path = stringFromBytes(arg.path[:]) + + return +} + +type DevStats struct { + WriteErrs uint64 + ReadErrs uint64 + FlushErrs uint64 + // Checksum error, bytenr error or contents is illegal: this is an + // indication that the block was damaged during read or write, or written to + // wrong location or read from wrong location. + CorruptionErrs uint64 + // An indication that blocks have not been written. + GenerationErrs uint64 + Unknown []uint64 +} + +func (f *FS) GetDevStats(id uint64) (out DevStats, err error) { + var arg btrfs_ioctl_get_dev_stats + arg.devid = id + arg.nr_items = _BTRFS_DEV_STAT_VALUES_MAX + arg.flags = 0 + if err = ioctl.Do(f.f, _BTRFS_IOC_GET_DEV_STATS, &arg); err != nil { + return + } + i := 0 + out.WriteErrs = arg.values[i] + i++ + out.ReadErrs = arg.values[i] + i++ + out.FlushErrs = arg.values[i] + i++ + out.CorruptionErrs = arg.values[i] + i++ + out.GenerationErrs = arg.values[i] + i++ + if int(arg.nr_items) > i { + out.Unknown = arg.values[i:arg.nr_items] + } + return +} + +type FSFeatureFlags struct { + Compatible FeatureFlags + CompatibleRO FeatureFlags + Incompatible IncompatFeatures +} + +func (f *FS) GetFeatures() (out FSFeatureFlags, err error) { + var arg btrfs_ioctl_feature_flags + if err = ioctl.Do(f.f, _BTRFS_IOC_GET_FEATURES, &arg); err != nil { + return + } + out = FSFeatureFlags{ + Compatible: arg.compat_flags, + CompatibleRO: arg.compat_ro_flags, + Incompatible: arg.incompat_flags, + } + return +} + +func (f *FS) GetSupportedFeatures() (out FSFeatureFlags, err error) { + var arg [3]btrfs_ioctl_feature_flags + if err = ioctl.Do(f.f, _BTRFS_IOC_GET_SUPPORTED_FEATURES, &arg); err != nil { + return + } + out = FSFeatureFlags{ + Compatible: arg[0].compat_flags, + CompatibleRO: arg[0].compat_ro_flags, + Incompatible: arg[0].incompat_flags, + } + //for i, a := range arg { + // out[i] = FSFeatureFlags{ + // Compatible: a.compat_flags, + // CompatibleRO: a.compat_ro_flags, + // Incompatible: a.incompat_flags, + // } + //} + return +} + +func (f *FS) GetFlags() (SubvolFlags, error) { + return iocSubvolGetflags(f.f) +} + +func (f *FS) SetFlags(flags SubvolFlags) error { + return iocSubvolSetflags(f.f, flags) +} + +func (f *FS) Sync() (err error) { + if err = ioctl.Ioctl(f.f, _BTRFS_IOC_START_SYNC, 0); err != nil { + return + } + return ioctl.Ioctl(f.f, _BTRFS_IOC_WAIT_SYNC, 0) +} + +func (f *FS) CreateSubVolume(name string) error { + return CreateSubVolume(filepath.Join(f.f.Name(), name)) +} + +func (f *FS) DeleteSubVolume(name string) error { + return DeleteSubVolume(filepath.Join(f.f.Name(), name)) +} + +func (f *FS) Snapshot(dst string, ro bool) error { + return SnapshotSubVolume(f.f.Name(), filepath.Join(f.f.Name(), dst), ro) +} + +func (f *FS) SnapshotSubVolume(name string, dst string, ro bool) error { + return SnapshotSubVolume(filepath.Join(f.f.Name(), name), + filepath.Join(f.f.Name(), dst), ro) +} + +func (f *FS) Send(w io.Writer, parent string, subvols ...string) error { + if parent != "" { + parent = filepath.Join(f.f.Name(), parent) + } + sub := make([]string, 0, len(subvols)) + for _, s := range subvols { + sub = append(sub, filepath.Join(f.f.Name(), s)) + } + return Send(w, parent, sub...) +} + +func (f *FS) Receive(r io.Reader) error { + return Receive(r, f.f.Name()) +} + +func (f *FS) ReceiveTo(r io.Reader, mount string) error { + return Receive(r, filepath.Join(f.f.Name(), mount)) +} + +func (f *FS) ListSubvolumes(filter func(SubvolInfo) bool) ([]SubvolInfo, error) { + m, err := listSubVolumes(f.f, filter) + if err != nil { + return nil, err + } + out := make([]SubvolInfo, 0, len(m)) + for _, v := range m { + out = append(out, v) + } + return out, nil +} + +func (f *FS) SubvolumeByUUID(uuid UUID) (*SubvolInfo, error) { + id, err := lookupUUIDSubvolItem(f.f, uuid) + if err != nil { + return nil, err + } + return subvolSearchByRootID(f.f, id, "") +} + +func (f *FS) SubvolumeByReceivedUUID(uuid UUID) (*SubvolInfo, error) { + id, err := lookupUUIDReceivedSubvolItem(f.f, uuid) + if err != nil { + return nil, err + } + return subvolSearchByRootID(f.f, id, "") +} + +func (f *FS) SubvolumeByPath(path string) (*SubvolInfo, error) { + return subvolSearchByPath(f.f, path) +} + +func (f *FS) Usage() (UsageInfo, error) { return spaceUsage(f.f) } + +func (f *FS) Balance(flags BalanceFlags) (BalanceProgress, error) { + args := btrfs_ioctl_balance_args{flags: flags} + err := iocBalanceV2(f.f, &args) + return args.stat, err +} + +func (f *FS) Resize(size int64) error { + amount := strconv.FormatInt(size, 10) + args := &btrfs_ioctl_vol_args{} + args.SetName(amount) + if err := iocResize(f.f, args); err != nil { + return fmt.Errorf("resize failed: %v", err) + } + return nil +} + +func (f *FS) ResizeToMax() error { + args := &btrfs_ioctl_vol_args{} + args.SetName("max") + if err := iocResize(f.f, args); err != nil { + return fmt.Errorf("resize failed: %v", err) + } + return nil +} diff --git a/vendor/github.com/dennwc/btrfs/btrfs_h.go b/vendor/github.com/dennwc/btrfs/btrfs_h.go new file mode 100644 index 00000000..192af830 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/btrfs_h.go @@ -0,0 +1,73 @@ +package btrfs + +import "strings" + +const maxUint64 = 1<<64 - 1 + +const labelSize = 256 + +type FeatureFlags uint64 + +const ( + FeatureCompatROFreeSpaceTree = FeatureFlags(1 << 0) +) + +type IncompatFeatures uint64 + +func (f IncompatFeatures) String() string { + var s []string + for i, name := range incompatFeatureNames { + if uint64(f)&uint64(i) != 0 { + s = append(s, name) + } + } + return strings.Join(s, ",") +} + +var incompatFeatureNames = []string{ + "DefaultSubvol", + "MixedGroups", + "CompressLZO", + "CompressLZOv2", + "BigMetadata", + "ExtendedIRef", + "RAID56", + "SkinnyMetadata", + "NoHoles", +} + +const ( + FeatureIncompatMixedBackRef = IncompatFeatures(1 << 0) + FeatureIncompatDefaultSubvol = IncompatFeatures(1 << 1) + FeatureIncompatMixedGroups = IncompatFeatures(1 << 2) + FeatureIncompatCompressLZO = IncompatFeatures(1 << 3) + + // Some patches floated around with a second compression method + // lets save that incompat here for when they do get in. + // Note we don't actually support it, we're just reserving the number. + FeatureIncompatCompressLZOv2 = IncompatFeatures(1 << 4) + + // Older kernels tried to do bigger metadata blocks, but the + // code was pretty buggy. Lets not let them try anymore. + FeatureIncompatBigMetadata = IncompatFeatures(1 << 5) + + FeatureIncompatExtendedIRef = IncompatFeatures(1 << 6) + FeatureIncompatRAID56 = IncompatFeatures(1 << 7) + FeatureIncompatSkinnyMetadata = IncompatFeatures(1 << 8) + FeatureIncompatNoHoles = IncompatFeatures(1 << 9) +) + +// Flags definition for balance. +type BalanceFlags uint64 + +// Restriper's general type filter. +const ( + BalanceData = BalanceFlags(1 << 0) + BalanceSystem = BalanceFlags(1 << 1) + BalanceMetadata = BalanceFlags(1 << 2) + + BalanceMask = (BalanceData | BalanceSystem | BalanceMetadata) + + BalanceForce = BalanceFlags(1 << 3) + BalanceResume = BalanceFlags(1 << 4) +) diff --git a/vendor/github.com/dennwc/btrfs/btrfs_list.go b/vendor/github.com/dennwc/btrfs/btrfs_list.go new file mode 100644 index 00000000..4929fe60 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/btrfs_list.go @@ -0,0 +1,22 @@ +package btrfs + +import "os" + +func getFileRootID(file *os.File) (objectID, error) { + args := btrfs_ioctl_ino_lookup_args{ + objectid: firstFreeObjectid, + } + if err := iocInoLookup(file, &args); err != nil { + return 0, err + } + return args.treeid, nil +} + +func getPathRootID(path string) (objectID, error) { + fs, err := Open(path, true) + if err != nil { + return 0, err + } + defer fs.Close() + return getFileRootID(fs.f) +} diff --git a/vendor/github.com/dennwc/btrfs/btrfs_tree.go b/vendor/github.com/dennwc/btrfs/btrfs_tree.go new file mode 100644 index 00000000..514e8cdd --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/btrfs_tree.go @@ -0,0 +1,299 @@ +package btrfs + +import ( + "fmt" + "time" + "unsafe" +) + +const ( + _BTRFS_BLOCK_GROUP_TYPE_MASK = (blockGroupData | + blockGroupSystem | + blockGroupMetadata) + _BTRFS_BLOCK_GROUP_PROFILE_MASK = (blockGroupRaid0 | + blockGroupRaid1 | + blockGroupRaid5 | + blockGroupRaid6 | + blockGroupDup | + blockGroupRaid10) + _BTRFS_BLOCK_GROUP_MASK = _BTRFS_BLOCK_GROUP_TYPE_MASK | _BTRFS_BLOCK_GROUP_PROFILE_MASK +) + +type rootRef struct { + DirID objectID + Sequence uint64 + Name string +} + +func (rootRef) btrfsSize() int { return 18 } + +func asUint64(p []byte) uint64 { + return *(*uint64)(unsafe.Pointer(&p[0])) +} + +func asUint32(p []byte) uint32 { + return *(*uint32)(unsafe.Pointer(&p[0])) +} + +func asUint16(p []byte) uint16 { + return *(*uint16)(unsafe.Pointer(&p[0])) +} + +func asRootRef(p []byte) rootRef { + const sz = 18 + // assuming that it is highly unsafe to have sizeof(struct) > len(data) + // (*btrfs_root_ref)(unsafe.Pointer(&p[0])) and sizeof(btrfs_root_ref) == 24 + ref := rootRef{ + DirID: objectID(asUint64(p[0:])), + Sequence: asUint64(p[8:]), + } + if n := asUint16(p[16:]); n > 0 { + ref.Name = string(p[sz : sz+n : sz+n]) + } + return ref +} + +var treeKeyNames = map[treeKeyType]string{ + inodeItemKey: "inodeItem", + inodeRefKey: "inodeRef", + inodeExtrefKey: "inodeExtref", + xattrItemKey: "xattrItemKey", + orphanItemKey: "orphanItem", + dirLogItemKey: "dirLogItem", + dirLogIndexKey: "dirLogIndex", + dirItemKey: "dirItem", + dirIndexKey: "dirIndex", + extentDataKey: "extentData", + extentCsumKey: "extentCsum", + rootItemKey: "rootItem", + rootBackrefKey: "rootBackref", + rootRefKey: "rootRef", + extentItemKey: "extentItem", + metadataItemKey: "metadataItem", + treeBlockRefKey: "treeBlockRef", + extentDataRefKey: "extentDataRef", + extentRefV0Key: "extentRefV0", + sharedBlockRefKey: "sharedBlockRef", + sharedDataRefKey: "sharedDataRef", + blockGroupItemKey: "blockGroupItem", + freeSpaceInfoKey: "freeSpaceInfo", + freeSpaceExtentKey: "freeSpaceExtent", + freeSpaceBitmapKey: "freeSpaceBitmap", + devExtentKey: "devExtent", + devItemKey: "devItem", + chunkItemKey: "chunkItem", + qgroupStatusKey: "qgroupStatus", + qgroupInfoKey: "qgroupInfo", + qgroupLimitKey: "qgroupLimit", + qgroupRelationKey: "qgroupRelation", + temporaryItemKey: "temporaryItem", + persistentItemKey: "persistentItem", + devReplaceKey: "devReplace", + uuidKeySubvol: "uuidKeySubvol", + uuidKeyReceivedSubvol: "uuidKeyReceivedSubvol", + stringItemKey: "stringItem", +} + +func (t treeKeyType) String() string { + if name, ok := treeKeyNames[t]; ok { + return name + } + return fmt.Sprintf("%#x", int(t)) +} + +// btrfs_disk_key_raw is a raw bytes for btrfs_disk_key structure +type btrfs_disk_key_raw [17]byte + +func (p btrfs_disk_key_raw) Decode() diskKey { + return diskKey{ + ObjectID: asUint64(p[0:]), + Type: p[8], + Offset: asUint64(p[9:]), + } +} + +type diskKey struct { + ObjectID uint64 + Type byte + Offset uint64 +} + +// btrfs_timespec_raw is a raw bytes for btrfs_timespec structure. +type btrfs_timespec_raw [12]byte + +func (t btrfs_timespec_raw) Decode() time.Time { + sec, nsec := asUint64(t[0:]), asUint32(t[8:]) + return time.Unix(int64(sec), int64(nsec)) +} + +// timeBlock is a raw set of bytes for 4 time fields. +// It is used to keep correct alignment when accessing structures from btrfs. +type timeBlock [4]btrfs_timespec_raw + +type btrfs_inode_item_raw struct { + generation uint64 + transid uint64 + size uint64 + nbytes uint64 + block_group uint64 + nlink uint32 + uid uint32 + gid uint32 + mode uint32 + rdev uint64 + flags uint64 + sequence uint64 + _ [4]uint64 // reserved + // atime btrfs_timespec + // ctime btrfs_timespec + // mtime btrfs_timespec + // otime btrfs_timespec + times timeBlock +} + +func (v btrfs_inode_item_raw) Decode() inodeItem { + return inodeItem{ + Gen: v.generation, + TransID: v.transid, + Size: v.size, + NBytes: v.nbytes, + BlockGroup: v.block_group, + NLink: v.nlink, + UID: v.uid, + GID: v.gid, + Mode: v.mode, + RDev: v.rdev, + Flags: v.flags, + Sequence: v.sequence, + ATime: v.times[0].Decode(), + CTime: v.times[1].Decode(), + MTime: v.times[2].Decode(), + OTime: v.times[3].Decode(), + } +} + +type inodeItem struct { + Gen uint64 // nfs style generation number + TransID uint64 // transid that last touched this inode + Size uint64 + NBytes uint64 + BlockGroup uint64 + NLink uint32 + UID uint32 + GID uint32 + Mode uint32 + RDev uint64 + Flags uint64 + Sequence uint64 // modification sequence number for NFS + ATime time.Time + CTime time.Time + MTime time.Time + OTime time.Time +} + +func asRootItem(p []byte) *btrfs_root_item_raw { + return (*btrfs_root_item_raw)(unsafe.Pointer(&p[0])) +} + +type btrfs_root_item_raw [439]byte + +func (p btrfs_root_item_raw) Decode() rootItem { + const ( + off2 = unsafe.Sizeof(btrfs_root_item_raw_p1{}) + off3 = off2 + 23 + ) + p1 := (*btrfs_root_item_raw_p1)(unsafe.Pointer(&p[0])) + p2 := p[off2 : off2+23] + p2_k := (*btrfs_disk_key_raw)(unsafe.Pointer(&p[off2+4])) + p2_b := p2[4+17:] + p3 := (*btrfs_root_item_raw_p3)(unsafe.Pointer(&p[off3])) + return rootItem{ + Inode: p1.inode.Decode(), + Gen: p1.generation, + RootDirID: p1.root_dirid, + ByteNr: p1.bytenr, + ByteLimit: p1.byte_limit, + BytesUsed: p1.bytes_used, + LastSnapshot: p1.last_snapshot, + Flags: p1.flags, + // from here, Go structure become misaligned with C structure + Refs: asUint32(p2[0:]), + DropProgress: p2_k.Decode(), + DropLevel: p2_b[0], + Level: p2_b[1], + // these fields are still misaligned by 1 bytes + // TODO(dennwc): it's a copy of Gen to check structure version; hide it maybe? + GenV2: p3.generation_v2, + UUID: p3.uuid, + ParentUUID: p3.parent_uuid, + ReceivedUUID: p3.received_uuid, + CTransID: p3.ctransid, + OTransID: p3.otransid, + STransID: p3.stransid, + RTransID: p3.rtransid, + CTime: p3.times[0].Decode(), + OTime: p3.times[1].Decode(), + STime: p3.times[2].Decode(), + RTime: p3.times[3].Decode(), + } +} + +type rootItem struct { + Inode inodeItem + Gen uint64 + RootDirID uint64 + ByteNr uint64 + ByteLimit uint64 + BytesUsed uint64 + LastSnapshot uint64 + Flags uint64 + Refs uint32 + DropProgress diskKey + DropLevel uint8 + Level uint8 + GenV2 uint64 + UUID UUID + ParentUUID UUID + ReceivedUUID UUID + CTransID uint64 + OTransID uint64 + STransID uint64 + RTransID uint64 + CTime time.Time + OTime time.Time + STime time.Time + RTime time.Time +} + +type btrfs_root_item_raw_p1 struct { + inode btrfs_inode_item_raw + generation uint64 + root_dirid uint64 + bytenr uint64 + byte_limit uint64 + bytes_used uint64 + last_snapshot uint64 + flags uint64 +} +type btrfs_root_item_raw_p2 struct { + refs uint32 + drop_progress btrfs_disk_key_raw + drop_level uint8 + level uint8 +} +type btrfs_root_item_raw_p3 struct { + generation_v2 uint64 + uuid UUID + parent_uuid UUID + received_uuid UUID + ctransid uint64 + otransid uint64 + stransid uint64 + rtransid uint64 + // ctime btrfs_timespec + // otime btrfs_timespec + // stime btrfs_timespec + // rtime btrfs_timespec + times timeBlock + _ [8]uint64 // reserved +} diff --git a/vendor/github.com/dennwc/btrfs/btrfs_tree_h.go b/vendor/github.com/dennwc/btrfs/btrfs_tree_h.go new file mode 100644 index 00000000..d5ebd663 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/btrfs_tree_h.go @@ -0,0 +1,745 @@ +package btrfs + +/* + * This header contains the structure definitions and constants used + * by file system objects that can be retrieved using + * the _BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that + * is needed to describe a leaf node's key or item contents. + */ + +/* holds pointers to all of the tree roots */ + +/* stores information about which extents are in use, and reference counts */ + +/* + * chunk tree stores translations from logical -> physical block numbering + * the super block points to the chunk tree + */ + +/* + * stores information about which areas of a given device are in use. + * one per device. The tree of tree roots points to the device tree + */ + +/* one per subvolume, storing files and directories */ + +/* directory objectid inside the root tree */ + +/* holds checksums of all the data extents */ + +/* holds quota configuration and tracking */ + +/* for storing items that use the _BTRFS_UUID_KEY* types */ + +/* tracks free space in block groups. */ + +/* device stats in the device tree */ + +/* for storing balance parameters in the root tree */ + +/* orhpan objectid for tracking unlinked/truncated files */ + +/* does write ahead logging to speed up fsyncs */ + +/* for space balancing */ + +/* + * extent checksums all have this objectid + * this allows them to share the logging tree + * for fsyncs + */ + +/* For storing free space cache */ + +/* + * The inode number assigned to the special inode for storing + * free ino cache + */ + +/* dummy objectid represents multiple objectids */ + +/* + * All files have objectids in this range. + */ + +/* + * the device items go into the chunk tree. The key is in the form + * [ 1 _BTRFS_DEV_ITEM_KEY device_id ] + */ + +/* + * inode items have the data typically returned from stat and store other + * info about object characteristics. There is one for every file and dir in + * the FS + */ + +/* reserve 2-15 close to the inode for later flexibility */ + +/* + * dir items are the name -> inode pointers in a directory. There is one + * for every name in a directory. + */ + +/* + * extent data is for file data + */ + +/* + * extent csums are stored in a separate tree and hold csums for + * an entire extent on disk. + */ + +/* + * root items point to tree roots. They are typically in the root + * tree used by the super block to find all the other trees + */ + +/* + * root backrefs tie subvols and snapshots to the directory entries that + * reference them + */ + +/* + * root refs make a fast index for listing all of the snapshots and + * subvolumes referenced by a given root. They point directly to the + * directory item in the root that references the subvol + */ + +/* + * extent items are in the extent map tree. These record which blocks + * are used, and how many references there are to each block + */ + +/* + * The same as the _BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know + * the length, so we save the level in key->offset instead of the length. + */ + +/* + * block groups give us hints into the extent allocation trees. Which + * blocks are free etc etc + */ + +/* + * Every block group is represented in the free space tree by a free space info + * item, which stores some accounting information. It is keyed on + * (block_group_start, FREE_SPACE_INFO, block_group_length). + */ + +/* + * A free space extent tracks an extent of space that is free in a block group. + * It is keyed on (start, FREE_SPACE_EXTENT, length). + */ + +/* + * When a block group becomes very fragmented, we convert it to use bitmaps + * instead of extents. A free space bitmap is keyed on + * (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with + * (length / sectorsize) bits. + */ + +/* + * Records the overall state of the qgroups. + * There's only one instance of this key present, + * (0, _BTRFS_QGROUP_STATUS_KEY, 0) + */ + +/* + * Records the currently used space of the qgroup. + * One key per qgroup, (0, _BTRFS_QGROUP_INFO_KEY, qgroupid). + */ + +/* + * Contains the user configured limits for the qgroup. + * One key per qgroup, (0, _BTRFS_QGROUP_LIMIT_KEY, qgroupid). + */ + +/* + * Records the child-parent relationship of qgroups. For + * each relation, 2 keys are present: + * (childid, _BTRFS_QGROUP_RELATION_KEY, parentid) + * (parentid, _BTRFS_QGROUP_RELATION_KEY, childid) + */ + +/* + * Obsolete name, see _BTRFS_TEMPORARY_ITEM_KEY. + */ + +/* + * The key type for tree items that are stored persistently, but do not need to + * exist for extended period of time. The items can exist in any tree. + * + * [subtype, _BTRFS_TEMPORARY_ITEM_KEY, data] + * + * Existing items: + * + * - balance status item + * (_BTRFS_BALANCE_OBJECTID, _BTRFS_TEMPORARY_ITEM_KEY, 0) + */ + +/* + * Obsolete name, see _BTRFS_PERSISTENT_ITEM_KEY + */ + +/* + * The key type for tree items that are stored persistently and usually exist + * for a long period, eg. filesystem lifetime. The item kinds can be status + * information, stats or preference values. The item can exist in any tree. + * + * [subtype, _BTRFS_PERSISTENT_ITEM_KEY, data] + * + * Existing items: + * + * - device statistics, store IO stats in the device tree, one key for all + * stats + * (_BTRFS_DEV_STATS_OBJECTID, _BTRFS_DEV_STATS_KEY, 0) + */ + +/* + * Persistantly stores the device replace state in the device tree. + * The key is built like this: (0, _BTRFS_DEV_REPLACE_KEY, 0). + */ + +/* + * Stores items that allow to quickly map UUIDs to something else. + * These items are part of the filesystem UUID tree. + * The key is built like this: + * (UUID_upper_64_bits, _BTRFS_UUID_KEY*, UUID_lower_64_bits). + */ + +/* for UUIDs assigned to * received subvols */ + +/* + * string items are for debugging. They just store a short string of + * data in the FS + */ + +/* 32 bytes in various csum fields */ + +/* csum types */ + +/* + * flags definitions for directory entry item type + * + * Used by: + * struct btrfs_dir_item.type + */ + +/* + * The key defines the order in the tree, and so it also defines (optimal) + * block layout. + * + * objectid corresponds to the inode number. + * + * type tells us things about the object, and is a kind of stream selector. + * so for a given inode, keys with type of 1 might refer to the inode data, + * type of 2 may point to file data in the btree and type == 3 may point to + * extents. + * + * offset is the starting byte offset for this key in the stream. + * + * btrfs_disk_key is in disk byte order. struct btrfs_key is always + * in cpu native order. Otherwise they are identical and their sizes + * should be the same (ie both packed) + */ +type btrfs_disk_key struct { + objectid uint64 + type_ uint8 + offset uint64 +} + +type btrfs_key struct { + objectid uint64 + type_ uint8 + offset uint64 +} + +type btrfs_dev_item struct { + devid uint64 + total_bytes uint64 + bytes_used uint64 + io_align uint32 + io_width uint32 + sector_size uint32 + type_ uint64 + generation uint64 + start_offset uint64 + dev_group uint32 + seek_speed uint8 + bandwidth uint8 + uuid UUID + fsid FSID +} + +type btrfs_stripe struct { + devid uint64 + offset uint64 + dev_uuid UUID +} + +type btrfs_chunk struct { + length uint64 + owner uint64 + stripe_len uint64 + type_ uint64 + io_align uint32 + io_width uint32 + sector_size uint32 + num_stripes uint16 + sub_stripes uint16 + stripe struct { + devid uint64 + offset uint64 + dev_uuid UUID + } +} + +/* additional stripes go here */ +type btrfs_free_space_entry struct { + offset uint64 + bytes uint64 + type_ uint8 +} + +type btrfs_free_space_header struct { + location struct { + objectid uint64 + type_ uint8 + offset uint64 + } + generation uint64 + num_entries uint64 + num_bitmaps uint64 +} + +/* Super block flags */ +/* Errors detected */ + +/* + * items in the extent btree are used to record the objectid of the + * owner of the block and the number of references + */ +type btrfs_extent_item struct { + refs uint64 + generation uint64 + flags uint64 +} + +type btrfs_extent_item_v0 struct { + refs uint32 +} + +/* following flags only apply to tree blocks */ + +/* use full backrefs for extent pointers in the block */ + +/* + * this flag is only used internally by scrub and may be changed at any time + * it is only declared here to avoid collisions + */ +type btrfs_tree_block_info struct { + key struct { + objectid uint64 + type_ uint8 + offset uint64 + } + level uint8 +} + +type btrfs_extent_data_ref struct { + root uint64 + objectid uint64 + offset uint64 + count uint32 +} + +type btrfs_shared_data_ref struct { + count uint32 +} + +type btrfs_extent_inline_ref struct { + type_ uint8 + offset uint64 +} + +/* old style backrefs item */ +type btrfs_extent_ref_v0 struct { + root uint64 + generation uint64 + objectid uint64 + count uint32 +} + +/* dev extents record free space on individual devices. The owner + * field points back to the chunk allocation mapping tree that allocated + * the extent. The chunk tree uuid field is a way to double check the owner + */ +type btrfs_dev_extent struct { + chunk_tree uint64 + chunk_objectid uint64 + chunk_offset uint64 + length uint64 + chunk_tree_uuid UUID +} + +type btrfs_inode_ref struct { + index uint64 + name_len uint16 +} + +/* name goes here */ +type btrfs_inode_extref struct { + parent_objectid uint64 + index uint64 + name_len uint16 + //name [0]uint8 +} + +/* name goes here */ +type btrfs_timespec struct { + sec uint64 + nsec uint32 +} + +type btrfs_inode_item struct { + generation uint64 + transid uint64 + size uint64 + nbytes uint64 + block_group uint64 + nlink uint32 + uid uint32 + gid uint32 + mode uint32 + rdev uint64 + flags uint64 + sequence uint64 + reserved [4]uint64 + atime struct { + sec uint64 + nsec uint32 + } + ctime struct { + sec uint64 + nsec uint32 + } + mtime struct { + sec uint64 + nsec uint32 + } + otime struct { + sec uint64 + nsec uint32 + } +} + +type btrfs_dir_log_item struct { + end uint64 +} + +type btrfs_dir_item struct { + location struct { + objectid uint64 + type_ uint8 + offset uint64 + } + transid uint64 + data_len uint16 + name_len uint16 + type_ uint8 +} + +/* + * Internal in-memory flag that a subvolume has been marked for deletion but + * still visible as a directory + */ +type btrfs_root_item struct { + inode struct { + generation uint64 + transid uint64 + size uint64 + nbytes uint64 + block_group uint64 + nlink uint32 + uid uint32 + gid uint32 + mode uint32 + rdev uint64 + flags uint64 + sequence uint64 + reserved [4]uint64 + atime struct { + sec uint64 + nsec uint32 + } + ctime struct { + sec uint64 + nsec uint32 + } + mtime struct { + sec uint64 + nsec uint32 + } + otime struct { + sec uint64 + nsec uint32 + } + } + generation uint64 + root_dirid uint64 + bytenr uint64 + byte_limit uint64 + bytes_used uint64 + last_snapshot uint64 + flags uint64 + refs uint32 + drop_progress struct { + objectid uint64 + type_ uint8 + offset uint64 + } + drop_level uint8 + level uint8 + generation_v2 uint64 + uuid UUID + parent_uuid UUID + received_uuid UUID + ctransid uint64 + otransid uint64 + stransid uint64 + rtransid uint64 + ctime struct { + sec uint64 + nsec uint32 + } + otime struct { + sec uint64 + nsec uint32 + } + stime struct { + sec uint64 + nsec uint32 + } + rtime struct { + sec uint64 + nsec uint32 + } + reserved [8]uint64 +} + +/* + * this is used for both forward and backward root refs + */ +type btrfs_root_ref struct { + dirid uint64 + sequence uint64 + name_len uint16 +} + +type btrfs_disk_balance_args struct { + profiles uint64 + usage uint64 + usage_min uint32 + usage_max uint32 + devid uint64 + pstart uint64 + pend uint64 + vstart uint64 + vend uint64 + target uint64 + flags uint64 + limit uint64 + limit_min uint32 + limit_max uint32 + stripes_min uint32 + stripes_max uint32 + unused [6]uint64 +} + +/* + * store balance parameters to disk so that balance can be properly + * resumed after crash or unmount + */ +type btrfs_balance_item struct { + flags uint64 + data struct { + profiles uint64 + usage uint64 + usage_min uint32 + usage_max uint32 + devid uint64 + pstart uint64 + pend uint64 + vstart uint64 + vend uint64 + target uint64 + flags uint64 + limit uint64 + limit_min uint32 + limit_max uint32 + stripes_min uint32 + stripes_max uint32 + unused [6]uint64 + } + meta struct { + profiles uint64 + usage uint64 + usage_min uint32 + usage_max uint32 + devid uint64 + pstart uint64 + pend uint64 + vstart uint64 + vend uint64 + target uint64 + flags uint64 + limit uint64 + limit_min uint32 + limit_max uint32 + stripes_min uint32 + stripes_max uint32 + unused [6]uint64 + } + sys struct { + profiles uint64 + usage uint64 + usage_min uint32 + usage_max uint32 + devid uint64 + pstart uint64 + pend uint64 + vstart uint64 + vend uint64 + target uint64 + flags uint64 + limit uint64 + limit_min uint32 + limit_max uint32 + stripes_min uint32 + stripes_max uint32 + unused [6]uint64 + } + unused [4]uint64 +} + +type btrfs_file_extent_item struct { + generation uint64 + ram_bytes uint64 + compression uint8 + encryption uint8 + other_encoding uint16 + type_ uint8 + disk_bytenr uint64 + disk_num_bytes uint64 + offset uint64 + num_bytes uint64 +} + +type btrfs_csum_item struct { + csum uint8 +} + +type btrfs_dev_stats_item struct { + values [_BTRFS_DEV_STAT_VALUES_MAX]uint64 +} + +type btrfs_dev_replace_item struct { + src_devid uint64 + cursor_left uint64 + cursor_right uint64 + cont_reading_from_srcdev_mode uint64 + replace_state uint64 + time_started uint64 + time_stopped uint64 + num_write_errors uint64 + num_uncorrectable_read_errors uint64 +} + +/* different types of block groups (and chunks) */ +const ( + _BTRFS_RAID_RAID10 = iota + _BTRFS_RAID_RAID1 + _BTRFS_RAID_DUP + _BTRFS_RAID_RAID0 + _BTRFS_RAID_SINGLE + _BTRFS_RAID_RAID5 + _BTRFS_RAID_RAID6 + _BTRFS_NR_RAID_TYPES +) + +/* + * We need a bit for restriper to be able to tell when chunks of type + * SINGLE are available. This "extended" profile format is used in + * fs_info->avail_*_alloc_bits (in-memory) and balance item fields + * (on-disk). The corresponding on-disk bit in chunk.type is reserved + * to avoid remappings between two formats in future. + */ + +/* + * A fake block group type that is used to communicate global block reserve + * size to userspace via the SPACE_INFO ioctl. + */ +func chunk_to_extended(flags uint64) uint64 { + if flags&uint64(_BTRFS_BLOCK_GROUP_PROFILE_MASK) == 0 { + flags |= uint64(availAllocBitSingle) + } + + return flags +} + +func extended_to_chunk(flags uint64) uint64 { + return flags &^ uint64(availAllocBitSingle) +} + +type btrfs_block_group_item struct { + used uint64 + chunk_objectid uint64 + flags uint64 +} + +type btrfs_free_space_info struct { + extent_count uint32 + flags uint32 +} + +func btrfs_qgroup_level(qgroupid uint64) uint64 { + return qgroupid >> uint32(qgroupLevelShift) +} + +/* + * is subvolume quota turned on? + */ + +/* + * RESCAN is set during the initialization phase + */ + +/* + * Some qgroup entries are known to be out of date, + * either because the configuration has changed in a way that + * makes a rescan necessary, or because the fs has been mounted + * with a non-qgroup-aware version. + * Turning qouta off and on again makes it inconsistent, too. + */ +type btrfs_qgroup_status_item struct { + version uint64 + generation uint64 + flags uint64 + rescan uint64 +} + +type btrfs_qgroup_info_item struct { + generation uint64 + rfer uint64 + rfer_cmpr uint64 + excl uint64 + excl_cmpr uint64 +} + +type btrfs_qgroup_limit_item struct { + flags uint64 + max_rfer uint64 + max_excl uint64 + rsv_rfer uint64 + rsv_excl uint64 +} diff --git a/vendor/github.com/dennwc/btrfs/btrfs_tree_hc.go b/vendor/github.com/dennwc/btrfs/btrfs_tree_hc.go new file mode 100644 index 00000000..fd799329 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/btrfs_tree_hc.go @@ -0,0 +1,502 @@ +package btrfs + +// This code was auto-generated; DO NOT EDIT! + +type treeKeyType uint32 + +type objectID uint64 + +type fileType int + +type fileExtentType int + +type devReplaceItemState int + +type blockGroup uint64 + +// This header contains the structure definitions and constants used +// by file system objects that can be retrieved using +// the BTRFS_IOC_SEARCH_TREE ioctl. That means basically anything that +// is needed to describe a leaf node's key or item contents. + +const ( + // Holds pointers to all of the tree roots + rootTreeObjectid objectID = 1 + + // Stores information about which extents are in use, and reference counts + extentTreeObjectid objectID = 2 + + // Chunk tree stores translations from logical -> physical block numbering + // the super block points to the chunk tree + chunkTreeObjectid objectID = 3 + + // Stores information about which areas of a given device are in use. + // one per device. The tree of tree roots points to the device tree + devTreeObjectid objectID = 4 + + // One per subvolume, storing files and directories + fsTreeObjectid objectID = 5 + + // Directory objectid inside the root tree + rootTreeDirObjectid objectID = 6 + + // Holds checksums of all the data extents + csumTreeObjectid objectID = 7 + + // Holds quota configuration and tracking + quotaTreeObjectid objectID = 8 + + // For storing items that use the BTRFS_UUID_KEY* types + uuidTreeObjectid objectID = 9 + + // Tracks free space in block groups. + freeSpaceTreeObjectid objectID = 10 + + // Device stats in the device tree + devStatsObjectid objectID = 0 + + // For storing balance parameters in the root tree + balanceObjectid objectID = (1<<64 - 4) + + // Orhpan objectid for tracking unlinked/truncated files + orphanObjectid objectID = (1<<64 - 5) + + // Does write ahead logging to speed up fsyncs + treeLogObjectid objectID = (1<<64 - 6) + treeLogFixupObjectid objectID = (1<<64 - 7) + + // For space balancing + treeRelocObjectid objectID = (1<<64 - 8) + dataRelocTreeObjectid objectID = (1<<64 - 9) + + // Extent checksums all have this objectid + // this allows them to share the logging tree + // for fsyncs + extentCsumObjectid objectID = (1<<64 - 10) + + // For storing free space cache + freeSpaceObjectid objectID = (1<<64 - 11) + + // The inode number assigned to the special inode for storing + // free ino cache + freeInoObjectid objectID = (1<<64 - 12) + + // Dummy objectid represents multiple objectids + multipleObjectids = (1<<64 - 255) + + // All files have objectids in this range. + firstFreeObjectid objectID = 256 + lastFreeObjectid objectID = (1<<64 - 256) + firstChunkTreeObjectid objectID = 256 + + // The device items go into the chunk tree. The key is in the form + // [ 1 BTRFS_DEV_ITEM_KEY device_id ] + devItemsObjectid objectID = 1 + + btreeInodeObjectid objectID = 1 + + emptySubvolDirObjectid objectID = 2 + + devReplaceDevid = 0 + + // Inode items have the data typically returned from stat and store other + // info about object characteristics. There is one for every file and dir in + // the FS + inodeItemKey treeKeyType = 1 + inodeRefKey treeKeyType = 12 + inodeExtrefKey treeKeyType = 13 + xattrItemKey treeKeyType = 24 + orphanItemKey treeKeyType = 48 + // Reserve 2-15 close to the inode for later flexibility + + // Dir items are the name -> inode pointers in a directory. There is one + // for every name in a directory. + dirLogItemKey treeKeyType = 60 + dirLogIndexKey treeKeyType = 72 + dirItemKey treeKeyType = 84 + dirIndexKey treeKeyType = 96 + // Extent data is for file data + extentDataKey treeKeyType = 108 + + // Extent csums are stored in a separate tree and hold csums for + // an entire extent on disk. + extentCsumKey treeKeyType = 128 + + // Root items point to tree roots. They are typically in the root + // tree used by the super block to find all the other trees + rootItemKey treeKeyType = 132 + + // Root backrefs tie subvols and snapshots to the directory entries that + // reference them + rootBackrefKey treeKeyType = 144 + + // Root refs make a fast index for listing all of the snapshots and + // subvolumes referenced by a given root. They point directly to the + // directory item in the root that references the subvol + rootRefKey treeKeyType = 156 + + // Extent items are in the extent map tree. These record which blocks + // are used, and how many references there are to each block + extentItemKey treeKeyType = 168 + + // The same as the BTRFS_EXTENT_ITEM_KEY, except it's metadata we already know + // the length, so we save the level in key->offset instead of the length. + metadataItemKey treeKeyType = 169 + + treeBlockRefKey treeKeyType = 176 + + extentDataRefKey treeKeyType = 178 + + extentRefV0Key treeKeyType = 180 + + sharedBlockRefKey treeKeyType = 182 + + sharedDataRefKey treeKeyType = 184 + + // Block groups give us hints into the extent allocation trees. Which + // blocks are free etc etc + blockGroupItemKey treeKeyType = 192 + + // Every block group is represented in the free space tree by a free space info + // item, which stores some accounting information. It is keyed on + // (block_group_start, FREE_SPACE_INFO, block_group_length). + freeSpaceInfoKey treeKeyType = 198 + + // A free space extent tracks an extent of space that is free in a block group. + // It is keyed on (start, FREE_SPACE_EXTENT, length). + freeSpaceExtentKey treeKeyType = 199 + + // When a block group becomes very fragmented, we convert it to use bitmaps + // instead of extents. A free space bitmap is keyed on + // (start, FREE_SPACE_BITMAP, length); the corresponding item is a bitmap with + // (length / sectorsize) bits. + freeSpaceBitmapKey treeKeyType = 200 + + devExtentKey treeKeyType = 204 + devItemKey treeKeyType = 216 + chunkItemKey treeKeyType = 228 + + // Records the overall state of the qgroups. + // There's only one instance of this key present, + // (0, BTRFS_QGROUP_STATUS_KEY, 0) + qgroupStatusKey treeKeyType = 240 + // Records the currently used space of the qgroup. + // One key per qgroup, (0, BTRFS_QGROUP_INFO_KEY, qgroupid). + qgroupInfoKey treeKeyType = 242 + // Contains the user configured limits for the qgroup. + // One key per qgroup, (0, BTRFS_QGROUP_LIMIT_KEY, qgroupid). + qgroupLimitKey treeKeyType = 244 + // Records the child-parent relationship of qgroups. For + // each relation, 2 keys are present: + // (childid, BTRFS_QGROUP_RELATION_KEY, parentid) + // (parentid, BTRFS_QGROUP_RELATION_KEY, childid) + qgroupRelationKey treeKeyType = 246 + + // Obsolete name, see BTRFS_TEMPORARY_ITEM_KEY. + balanceItemKey treeKeyType = 248 + + // The key type for tree items that are stored persistently, but do not need to + // exist for extended period of time. The items can exist in any tree. + // [subtype, BTRFS_TEMPORARY_ITEM_KEY, data] + // Existing items: + // - balance status item + // (BTRFS_BALANCE_OBJECTID, BTRFS_TEMPORARY_ITEM_KEY, 0) + temporaryItemKey treeKeyType = 248 + + // Obsolete name, see BTRFS_PERSISTENT_ITEM_KEY + devStatsKey treeKeyType = 249 + + // The key type for tree items that are stored persistently and usually exist + // for a long period, eg. filesystem lifetime. The item kinds can be status + // information, stats or preference values. The item can exist in any tree. + // [subtype, BTRFS_PERSISTENT_ITEM_KEY, data] + // Existing items: + // - device statistics, store IO stats in the device tree, one key for all + // stats + // (BTRFS_DEV_STATS_OBJECTID, BTRFS_DEV_STATS_KEY, 0) + persistentItemKey treeKeyType = 249 + + // Persistantly stores the device replace state in the device tree. + // The key is built like this: (0, BTRFS_DEV_REPLACE_KEY, 0). + devReplaceKey treeKeyType = 250 + + // Stores items that allow to quickly map UUIDs to something else. + // These items are part of the filesystem UUID tree. + // The key is built like this: + // (UUID_upper_64_bits, BTRFS_UUID_KEY*, UUID_lower_64_bits). + uuidKeySubvol = 251 + uuidKeyReceivedSubvol = 252 + + // String items are for debugging. They just store a short string of + // data in the FS + stringItemKey treeKeyType = 253 + + // 32 bytes in various csum fields + csumSize = 32 + + // Csum types + csumTypeCrc32 = 0 + + // Flags definitions for directory entry item type + // Used by: + // struct btrfs_dir_item.type + ftUnknown fileType = 0 + ftRegFile fileType = 1 + ftDir fileType = 2 + ftChrdev fileType = 3 + ftBlkdev fileType = 4 + ftFifo fileType = 5 + ftSock fileType = 6 + ftSymlink fileType = 7 + ftXattr fileType = 8 + ftMax fileType = 9 + + // The key defines the order in the tree, and so it also defines (optimal) + // block layout. + // objectid corresponds to the inode number. + // type tells us things about the object, and is a kind of stream selector. + // so for a given inode, keys with type of 1 might refer to the inode data, + // type of 2 may point to file data in the btree and type == 3 may point to + // extents. + // offset is the starting byte offset for this key in the stream. + // btrfs_disk_key is in disk byte order. struct btrfs_key is always + // in cpu native order. Otherwise they are identical and their sizes + // should be the same (ie both packed) + + // The internal btrfs device id + + // Size of the device + + // Bytes used + + // Optimal io alignment for this device + + // Optimal io width for this device + + // Minimal io size for this device + + // Type and info about this device + + // Expected generation for this device + + // Starting byte of this partition on the device, + // to allow for stripe alignment in the future + + // Grouping information for allocation decisions + + // Seek speed 0-100 where 100 is fastest + + // Bandwidth 0-100 where 100 is fastest + + // Btrfs generated uuid for this device + + // Uuid of FS who owns this device + + // Size of this chunk in bytes + + // Objectid of the root referencing this chunk + + // Optimal io alignment for this chunk + + // Optimal io width for this chunk + + // Minimal io size for this chunk + + // 2^16 stripes is quite a lot, a second limit is the size of a single + // item in the btree + + // Sub stripes only matter for raid10 + // Additional stripes go here + + freeSpaceExtent = 1 + freeSpaceBitmap = 2 + + headerFlagWritten = (1 << 0) + headerFlagReloc = (1 << 1) + + // Super block flags + // Errors detected + superFlagError = (1 << 2) + + superFlagSeeding = (1 << 32) + superFlagMetadump = (1 << 33) + + // Items in the extent btree are used to record the objectid of the + // owner of the block and the number of references + + extentFlagData = (1 << 0) + extentFlagTreeBlock = (1 << 1) + + // Following flags only apply to tree blocks + + // Use full backrefs for extent pointers in the block + blockFlagFullBackref = (1 << 8) + + // This flag is only used internally by scrub and may be changed at any time + // it is only declared here to avoid collisions + extentFlagSuper = (1 << 48) + + // Old style backrefs item + + // Dev extents record free space on individual devices. The owner + // field points back to the chunk allocation mapping tree that allocated + // the extent. The chunk tree uuid field is a way to double check the owner + + // Name goes here + + // Name goes here + + // Nfs style generation number + // Transid that last touched this inode + + // Modification sequence number for NFS + + // A little future expansion, for more than this we can + // just grow the inode item and version it + + rootSubvolRdonly = (1 << 0) + + // Internal in-memory flag that a subvolume has been marked for deletion but + // still visible as a directory + rootSubvolDead = (1 << 48) + + // The following fields appear after subvol_uuids+subvol_times + // were introduced. + + // This generation number is used to test if the new fields are valid + // and up to date while reading the root item. Every time the root item + // is written out, the "generation" field is copied into this field. If + // anyone ever mounted the fs with an older kernel, we will have + // mismatching generation values here and thus must invalidate the + // new fields. See btrfs_update_root and btrfs_find_last_root for + // details. + // the offset of generation_v2 is also used as the start for the memset + // when invalidating the fields. + + // This is used for both forward and backward root refs + + // Profiles to operate on, single is denoted by + // BTRFS_AVAIL_ALLOC_BIT_SINGLE + + // Usage filter + // BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' + // BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max + + // Devid filter + + // Devid subset filter [pstart..pend) + + // Btrfs virtual address space subset filter [vstart..vend) + + // Profile to convert to, single is denoted by + // BTRFS_AVAIL_ALLOC_BIT_SINGLE + + // BTRFS_BALANCE_ARGS_* + + // BTRFS_BALANCE_ARGS_LIMIT with value 'limit' + // BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum + // and maximum + + // Process chunks that cross stripes_min..stripes_max devices, + // BTRFS_BALANCE_ARGS_STRIPES_RANGE + + // Store balance parameters to disk so that balance can be properly + // resumed after crash or unmount + // BTRFS_BALANCE_* + + fileExtentInline fileExtentType = 0 + fileExtentReg fileExtentType = 1 + fileExtentPrealloc fileExtentType = 2 + + // Transaction id that created this extent + // Max number of bytes to hold this extent in ram + // when we split a compressed extent we can't know how big + // each of the resulting pieces will be. So, this is + // an upper limit on the size of the extent in ram instead of + // an exact limit. + + // 32 bits for the various ways we might encode the data, + // including compression and encryption. If any of these + // are set to something a given disk format doesn't understand + // it is treated like an incompat flag for reading and writing, + // but not for stat. + + // Are we inline data or a real extent? + + // Disk space consumed by the extent, checksum blocks are included + // in these numbers + // At this offset in the structure, the inline extent data start. + // The logical offset in file blocks (no csums) + // this extent record is for. This allows a file extent to point + // into the middle of an existing extent on disk, sharing it + // between two snapshots (useful if some bytes in the middle of the + // extent have changed + // The logical number of file blocks (no csums included). This + // always reflects the size uncompressed and without encoding. + + // Grow this item struct at the end for future enhancements and keep + // the existing values unchanged + + devReplaceItemContReadingFromSrcdevModeAlways = 0 + devReplaceItemContReadingFromSrcdevModeAvoid = 1 + devReplaceItemStateNeverStarted devReplaceItemState = 0 + devReplaceItemStateStarted devReplaceItemState = 1 + devReplaceItemStateSuspended devReplaceItemState = 2 + devReplaceItemStateFinished devReplaceItemState = 3 + devReplaceItemStateCanceled devReplaceItemState = 4 + + // Grow this item struct at the end for future enhancements and keep + // the existing values unchanged + + // Different types of block groups (and chunks) + blockGroupData blockGroup = (1 << 0) + blockGroupSystem blockGroup = (1 << 1) + blockGroupMetadata blockGroup = (1 << 2) + blockGroupRaid0 blockGroup = (1 << 3) + blockGroupRaid1 blockGroup = (1 << 4) + blockGroupDup blockGroup = (1 << 5) + blockGroupRaid10 blockGroup = (1 << 6) + blockGroupRaid5 blockGroup = (1 << 7) + blockGroupRaid6 blockGroup = (1 << 8) + + // We need a bit for restriper to be able to tell when chunks of type + // SINGLE are available. This "extended" profile format is used in + // fs_info->avail_*_alloc_bits (in-memory) and balance item fields + // (on-disk). The corresponding on-disk bit in chunk.type is reserved + // to avoid remappings between two formats in future. + availAllocBitSingle = (1 << 48) + + // A fake block group type that is used to communicate global block reserve + // size to userspace via the SPACE_INFO ioctl. + spaceInfoGlobalRsv = (1 << 49) + + freeSpaceUsingBitmaps = (1 << 0) + + qgroupLevelShift = 48 + + // Is subvolume quota turned on? + qgroupStatusFlagOn = (1 << 0) + // RESCAN is set during the initialization phase + qgroupStatusFlagRescan = (1 << 1) + // Some qgroup entries are known to be out of date, + // either because the configuration has changed in a way that + // makes a rescan necessary, or because the fs has been mounted + // with a non-qgroup-aware version. + // Turning qouta off and on again makes it inconsistent, too. + qgroupStatusFlagInconsistent = (1 << 2) + + qgroupStatusVersion = 1 + + // The generation is updated during every commit. As older + // versions of btrfs are not aware of qgroups, it will be + // possible to detect inconsistencies by checking the + // generation on mount time + + // Flag definitions see above + + // Only used during scanning to record the progress + // of the scan. It contains a logical address + + // Only updated when any of the other values change + +) diff --git a/vendor/github.com/dennwc/btrfs/errors.go b/vendor/github.com/dennwc/btrfs/errors.go new file mode 100644 index 00000000..b852bcfd --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/errors.go @@ -0,0 +1,52 @@ +package btrfs + +import ( + "errors" + "fmt" +) + +type ErrNotBtrfs struct { + Path string +} + +func (e ErrNotBtrfs) Error() string { + return fmt.Sprintf("not a btrfs filesystem: %s", e.Path) +} + +// Error codes as returned by the kernel +type ErrCode int + +func (e ErrCode) Error() string { + s, ok := errorString[e] + if ok { + return s + } + return fmt.Sprintf("error %d", int(e)) +} + +const ( + ErrDevRAID1MinNotMet = ErrCode(iota + 1) + ErrDevRAID10MinNotMet + ErrDevRAID5MinNotMet + ErrDevRAID6MinNotMet + ErrDevTargetReplace + ErrDevMissingNotFound + ErrDevOnlyWritable + ErrDevExclRunInProgress +) + +var errorString = map[ErrCode]string{ + ErrDevRAID1MinNotMet: "unable to go below two devices on raid1", + ErrDevRAID10MinNotMet: "unable to go below four devices on raid10", + ErrDevRAID5MinNotMet: "unable to go below two devices on raid5", + ErrDevRAID6MinNotMet: "unable to go below three devices on raid6", + ErrDevTargetReplace: "unable to remove the dev_replace target dev", + ErrDevMissingNotFound: "no missing devices found to remove", + ErrDevOnlyWritable: "unable to remove the only writeable device", + ErrDevExclRunInProgress: "add/delete/balance/replace/resize operation in progress", +} + +var ( + ErrNotFound = errors.New("not found") + errNotImplemented = errors.New("not implemented") +) diff --git a/vendor/github.com/dennwc/btrfs/headers.go b/vendor/github.com/dennwc/btrfs/headers.go new file mode 100644 index 00000000..2ff5713a --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/headers.go @@ -0,0 +1,4 @@ +package btrfs + +//go:generate go run ./cmd/hgen.go -u -g -t BTRFS_ -p btrfs -cs=treeKeyType:uint32=_KEY,objectID:uint64=_OBJECTID -cp=fileType=FT_,fileExtentType=FILE_EXTENT_,devReplaceItemState=DEV_REPLACE_ITEM_STATE_,blockGroup:uint64=BLOCK_GROUP_ -o btrfs_tree_hc.go btrfs_tree.h +//go:generate gofmt -l -w btrfs_tree_hc.go diff --git a/vendor/github.com/dennwc/btrfs/ioctl_h.go b/vendor/github.com/dennwc/btrfs/ioctl_h.go new file mode 100644 index 00000000..769689bc --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/ioctl_h.go @@ -0,0 +1,876 @@ +package btrfs + +import ( + "encoding/binary" + "encoding/hex" + "github.com/dennwc/ioctl" + "os" + "strconv" + "strings" + "unsafe" +) + +var order = binary.LittleEndian + +const ioctlMagic = 0x94 + +const devicePathNameMax = 1024 + +const ( + FSIDSize = 16 + UUIDSize = 16 +) + +var zeroUUID UUID + +type UUID [UUIDSize]byte + +func (id UUID) IsZero() bool { return id == zeroUUID } +func (id UUID) String() string { + if id.IsZero() { + return "" + } + buf := make([]byte, UUIDSize*2+4) + i := 0 + i += hex.Encode(buf[i:], id[:4]) + buf[i] = '-' + i++ + i += hex.Encode(buf[i:], id[4:6]) + buf[i] = '-' + i++ + i += hex.Encode(buf[i:], id[6:8]) + buf[i] = '-' + i++ + i += hex.Encode(buf[i:], id[8:10]) + buf[i] = '-' + i++ + i += hex.Encode(buf[i:], id[10:]) + return string(buf) +} + +type FSID [FSIDSize]byte + +func (id FSID) String() string { return hex.EncodeToString(id[:]) } + +const volNameMax = 4087 + +// this should be 4k +type btrfs_ioctl_vol_args struct { + fd int64 + name [volNameMax + 1]byte +} + +func (arg *btrfs_ioctl_vol_args) SetName(name string) { + n := copy(arg.name[:], name) + arg.name[n] = 0 +} + +type btrfs_qgroup_limit struct { + flags uint64 + max_referenced uint64 + max_exclusive uint64 + rsv_referenced uint64 + rsv_exclusive uint64 +} + +type btrfs_qgroup_inherit struct { + flags uint64 + num_qgroups uint64 + num_ref_copies uint64 + num_excl_copies uint64 + lim btrfs_qgroup_limit + //qgroups [0]uint64 +} + +type btrfs_ioctl_qgroup_limit_args struct { + qgroupid uint64 + lim btrfs_qgroup_limit +} + +type btrfs_ioctl_vol_args_v2_u1 struct { + size uint64 + qgroup_inherit *btrfs_qgroup_inherit +} + +const subvolNameMax = 4039 + +type SubvolFlags uint64 + +func (f SubvolFlags) ReadOnly() bool { + return f&SubvolReadOnly != 0 +} +func (f SubvolFlags) String() string { + if f == 0 { + return "" + } + var out []string + if f&SubvolReadOnly != 0 { + out = append(out, "RO") + f = f & (^SubvolReadOnly) + } + if f != 0 { + out = append(out, "0x"+strconv.FormatInt(int64(f), 16)) + } + return strings.Join(out, "|") +} + +// flags for subvolumes +// +// Used by: +// struct btrfs_ioctl_vol_args_v2.flags +// +// BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls: +// - BTRFS_IOC_SUBVOL_GETFLAGS +// - BTRFS_IOC_SUBVOL_SETFLAGS +const ( + subvolCreateAsync = SubvolFlags(1 << 0) + SubvolReadOnly = SubvolFlags(1 << 1) + subvolQGroupInherit = SubvolFlags(1 << 2) +) + +type btrfs_ioctl_vol_args_v2 struct { + fd int64 + transid uint64 + flags SubvolFlags + btrfs_ioctl_vol_args_v2_u1 + unused [2]uint64 + name [subvolNameMax + 1]byte +} + +// structure to report errors and progress to userspace, either as a +// result of a finished scrub, a canceled scrub or a progress inquiry +type btrfs_scrub_progress struct { + data_extents_scrubbed uint64 // # of data extents scrubbed + tree_extents_scrubbed uint64 // # of tree extents scrubbed + data_bytes_scrubbed uint64 // # of data bytes scrubbed + tree_bytes_scrubbed uint64 // # of tree bytes scrubbed + read_errors uint64 // # of read errors encountered (EIO) + csum_errors uint64 // # of failed csum checks + // # of occurences, where the metadata of a tree block did not match the expected values, like generation or logical + verify_errors uint64 + // # of 4k data block for which no csum is present, probably the result of data written with nodatasum + no_csum uint64 + csum_discards uint64 // # of csum for which no data was found in the extent tree. + super_errors uint64 // # of bad super blocks encountered + malloc_errors uint64 // # of internal kmalloc errors. These will likely cause an incomplete scrub + uncorrectable_errors uint64 // # of errors where either no intact copy was found or the writeback failed + corrected_errors uint64 // # of errors corrected + // last physical address scrubbed. In case a scrub was aborted, this can be used to restart the scrub + last_physical uint64 + // # of occurences where a read for a full (64k) bio failed, but the re- + // check succeeded for each 4k piece. Intermittent error. + unverified_errors uint64 +} + +type btrfs_ioctl_scrub_args struct { + devid uint64 // in + start uint64 // in + end uint64 // in + flags uint64 // in + progress btrfs_scrub_progress // out + // pad to 1k + _ [1024 - 4*8 - unsafe.Sizeof(btrfs_scrub_progress{})]byte +} + +type contReadingFromSrcdevMode uint64 + +const ( + _BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS contReadingFromSrcdevMode = 0 + _BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID contReadingFromSrcdevMode = 1 +) + +type btrfs_ioctl_dev_replace_start_params struct { + srcdevid uint64 // in, if 0, use srcdev_name instead + cont_reading_from_srcdev_mode contReadingFromSrcdevMode // in + srcdev_name [devicePathNameMax + 1]byte // in + tgtdev_name [devicePathNameMax + 1]byte // in +} + +type devReplaceState uint64 + +const ( + _BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED devReplaceState = 0 + _BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED devReplaceState = 1 + _BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED devReplaceState = 2 + _BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED devReplaceState = 3 + _BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED devReplaceState = 4 +) + +type btrfs_ioctl_dev_replace_status_params struct { + replace_state devReplaceState // out + progress_1000 uint64 // out, 0 <= x <= 1000 + time_started uint64 // out, seconds since 1-Jan-1970 + time_stopped uint64 // out, seconds since 1-Jan-1970 + num_write_errors uint64 // out + num_uncorrectable_read_errors uint64 // out +} + +type btrfs_ioctl_dev_replace_args_u1 struct { + cmd uint64 // in + result uint64 // out + start btrfs_ioctl_dev_replace_start_params // in + spare [64]uint64 +} + +type btrfs_ioctl_dev_replace_args_u2 struct { + cmd uint64 // in + result uint64 // out + status btrfs_ioctl_dev_replace_status_params // out + _ [unsafe.Sizeof(btrfs_ioctl_dev_replace_start_params{}) - unsafe.Sizeof(btrfs_ioctl_dev_replace_status_params{})]byte + spare [64]uint64 +} + +type btrfs_ioctl_dev_info_args struct { + devid uint64 // in/out + uuid UUID // in/out + bytes_used uint64 // out + total_bytes uint64 // out + _ [379]uint64 // pad to 4k + path [devicePathNameMax]byte // out +} + +type btrfs_ioctl_fs_info_args struct { + max_id uint64 // out + num_devices uint64 // out + fsid FSID // out + nodesize uint32 // out + sectorsize uint32 // out + clone_alignment uint32 // out + _ [122*8 + 4]byte // pad to 1k +} + +type btrfs_ioctl_feature_flags struct { + compat_flags FeatureFlags + compat_ro_flags FeatureFlags + incompat_flags IncompatFeatures +} + +type argRange [8]byte + +func (u argRange) asN() uint64 { + return order.Uint64(u[:]) +} +func (u argRange) asMinMax() (min, max uint32) { + return order.Uint32(u[:4]), order.Uint32(u[4:]) +} + +// balance control ioctl modes +//#define BTRFS_BALANCE_CTL_PAUSE 1 +//#define BTRFS_BALANCE_CTL_CANCEL 2 +//#define BTRFS_BALANCE_CTL_RESUME 3 + +// this is packed, because it should be exactly the same as its disk +// byte order counterpart (struct btrfs_disk_balance_args) +type btrfs_balance_args struct { + profiles uint64 + // usage filter + // BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' + // BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max + usage argRange + devid uint64 + pstart uint64 + pend uint64 + vstart uint64 + vend uint64 + target uint64 + flags uint64 + // BTRFS_BALANCE_ARGS_LIMIT with value 'limit' (limit number of processed chunks) + // BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum and maximum + limit argRange + stripes_min uint32 + stripes_max uint32 + _ [48]byte +} + +// Report balance progress to userspace. +// +// btrfs_balance_progress +type BalanceProgress struct { + Expected uint64 // estimated # of chunks that will be relocated to fulfill the request + Considered uint64 // # of chunks we have considered so far + Completed uint64 // # of chunks relocated so far +} + +type BalanceState uint64 + +const ( + BalanceStateRunning BalanceState = (1 << 0) + BalanceStatePauseReq BalanceState = (1 << 1) + BalanceStateCancelReq BalanceState = (1 << 2) +) + +type btrfs_ioctl_balance_args struct { + flags BalanceFlags // in/out + state BalanceState // out + data btrfs_balance_args // in/out + meta btrfs_balance_args // in/out + sys btrfs_balance_args // in/out + stat BalanceProgress // out + _ [72 * 8]byte // pad to 1k +} + +const _BTRFS_INO_LOOKUP_PATH_MAX = 4080 + +type btrfs_ioctl_ino_lookup_args struct { + treeid objectID + objectid objectID + name [_BTRFS_INO_LOOKUP_PATH_MAX]byte +} + +func (arg *btrfs_ioctl_ino_lookup_args) Name() string { + n := 0 + for i, b := range arg.name { + if b == '\x00' { + n = i + break + } + } + return string(arg.name[:n]) +} + +type btrfs_ioctl_search_key struct { + tree_id objectID // which root are we searching. 0 is the tree of tree roots + // keys returned will be >= min and <= max + min_objectid objectID + max_objectid objectID + // keys returned will be >= min and <= max + min_offset uint64 + max_offset uint64 + // max and min transids to search for + min_transid uint64 + max_transid uint64 + // keys returned will be >= min and <= max + min_type treeKeyType + max_type treeKeyType + // how many items did userland ask for, and how many are we returning + nr_items uint32 + _ [36]byte +} + +type btrfs_ioctl_search_header struct { + transid uint64 + objectid objectID + offset uint64 + typ treeKeyType + len uint32 +} + +const _BTRFS_SEARCH_ARGS_BUFSIZE = (4096 - unsafe.Sizeof(btrfs_ioctl_search_key{})) + +// the buf is an array of search headers where +// each header is followed by the actual item +// the type field is expanded to 32 bits for alignment +type btrfs_ioctl_search_args struct { + key btrfs_ioctl_search_key + buf [_BTRFS_SEARCH_ARGS_BUFSIZE]byte +} + +// Extended version of TREE_SEARCH ioctl that can return more than 4k of bytes. +// The allocated size of the buffer is set in buf_size. +type btrfs_ioctl_search_args_v2 struct { + key btrfs_ioctl_search_key // in/out - search parameters + buf_size uint64 // in - size of buffer; out - on EOVERFLOW: needed size to store item + //buf [0]uint64 // out - found items +} + +// With a @src_length of zero, the range from @src_offset->EOF is cloned! +type btrfs_ioctl_clone_range_args struct { + src_fd int64 + src_offset uint64 + src_length uint64 + dest_offset uint64 +} + +// flags for the defrag range ioctl +type defragRange uint64 + +const ( + _BTRFS_DEFRAG_RANGE_COMPRESS defragRange = 1 + _BTRFS_DEFRAG_RANGE_START_IO defragRange = 2 +) + +const _BTRFS_SAME_DATA_DIFFERS = 1 + +// For extent-same ioctl +type btrfs_ioctl_same_extent_info struct { + fd int64 // in - destination file + logical_offset uint64 // in - start of extent in destination + bytes_deduped uint64 // out - total # of bytes we were able to dedupe from this file + // out; status of this dedupe operation: + // 0 if dedup succeeds + // < 0 for error + // == BTRFS_SAME_DATA_DIFFERS if data differs + status int32 + reserved uint32 +} + +type btrfs_ioctl_same_args struct { + logical_offset uint64 // in - start of extent in source + length uint64 // in - length of extent + dest_count uint16 // in - total elements in info array + _ [6]byte + //info [0]btrfs_ioctl_same_extent_info +} + +type btrfs_ioctl_defrag_range_args struct { + start uint64 // start of the defrag operation + len uint64 // number of bytes to defrag, use (u64)-1 to say all + // flags for the operation, which can include turning + // on compression for this one defrag + flags uint64 + // any extent bigger than this will be considered + // already defragged. Use 0 to take the kernel default + // Use 1 to say every single extent must be rewritten + extent_thresh uint32 + // which compression method to use if turning on compression + // for this defrag operation. If unspecified, zlib will be used + compress_type uint32 + _ [16]byte // spare for later +} + +type btrfs_ioctl_space_info struct { + flags uint64 + total_bytes uint64 + used_bytes uint64 +} + +type btrfs_ioctl_space_args struct { + space_slots uint64 + total_spaces uint64 + //spaces [0]btrfs_ioctl_space_info +} + +type btrfs_data_container struct { + bytes_left uint32 // out -- bytes not needed to deliver output + bytes_missing uint32 // out -- additional bytes needed for result + elem_cnt uint32 // out + elem_missed uint32 // out + //val [0]uint64 +} + +type btrfs_ioctl_ino_path_args struct { + inum uint64 // in + size uint64 // in + _ [32]byte + // struct btrfs_data_container *fspath; out + fspath uint64 // out +} + +type btrfs_ioctl_logical_ino_args struct { + logical uint64 // in + size uint64 // in + _ [32]byte + // struct btrfs_data_container *inodes; out + inodes uint64 +} + +// disk I/O failure stats +const ( + _BTRFS_DEV_STAT_WRITE_ERRS = iota // EIO or EREMOTEIO from lower layers + _BTRFS_DEV_STAT_READ_ERRS // EIO or EREMOTEIO from lower layers + _BTRFS_DEV_STAT_FLUSH_ERRS // EIO or EREMOTEIO from lower layers + + // stats for indirect indications for I/O failures + + // checksum error, bytenr error or contents is illegal: this is an + // indication that the block was damaged during read or write, or written to + // wrong location or read from wrong location + _BTRFS_DEV_STAT_CORRUPTION_ERRS + _BTRFS_DEV_STAT_GENERATION_ERRS // an indication that blocks have not been written + + _BTRFS_DEV_STAT_VALUES_MAX +) + +// Reset statistics after reading; needs SYS_ADMIN capability +const _BTRFS_DEV_STATS_RESET = (1 << 0) + +type btrfs_ioctl_get_dev_stats struct { + devid uint64 // in + nr_items uint64 // in/out + flags uint64 // in/out + values [_BTRFS_DEV_STAT_VALUES_MAX]uint64 // out values + _ [128 - 2 - _BTRFS_DEV_STAT_VALUES_MAX]uint64 // pad to 1k +} + +const ( + _BTRFS_QUOTA_CTL_ENABLE = 1 + _BTRFS_QUOTA_CTL_DISABLE = 2 + // 3 has formerly been reserved for BTRFS_QUOTA_CTL_RESCAN +) + +type btrfs_ioctl_quota_ctl_args struct { + cmd uint64 + status uint64 +} + +type btrfs_ioctl_quota_rescan_args struct { + flags uint64 + progress uint64 + _ [6]uint64 +} + +type btrfs_ioctl_qgroup_assign_args struct { + assign uint64 + src uint64 + dst uint64 +} + +type btrfs_ioctl_qgroup_create_args struct { + create uint64 + qgroupid uint64 +} + +type btrfs_ioctl_timespec struct { + sec uint64 + nsec uint32 +} + +type btrfs_ioctl_received_subvol_args struct { + uuid UUID // in + stransid uint64 // in + rtransid uint64 // out + stime btrfs_ioctl_timespec // in + rtime btrfs_ioctl_timespec // out + flags uint64 // in + _ [16]uint64 // in +} + +const ( + // Caller doesn't want file data in the send stream, even if the + // search of clone sources doesn't find an extent. UPDATE_EXTENT + // commands will be sent instead of WRITE commands. + _BTRFS_SEND_FLAG_NO_FILE_DATA = 0x1 + // Do not add the leading stream header. Used when multiple snapshots + // are sent back to back. + _BTRFS_SEND_FLAG_OMIT_STREAM_HEADER = 0x2 + // Omit the command at the end of the stream that indicated the end + // of the stream. This option is used when multiple snapshots are + // sent back to back. + _BTRFS_SEND_FLAG_OMIT_END_CMD = 0x4 + + _BTRFS_SEND_FLAG_MASK = _BTRFS_SEND_FLAG_NO_FILE_DATA | + _BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | + _BTRFS_SEND_FLAG_OMIT_END_CMD +) + +type btrfs_ioctl_send_args struct { + send_fd int64 // in + clone_sources_count uint64 // in + clone_sources *objectID // in + parent_root objectID // in + flags uint64 // in + _ [4]uint64 // in +} + +var ( + _BTRFS_IOC_SNAP_CREATE = ioctl.IOW(ioctlMagic, 1, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_DEFRAG = ioctl.IOW(ioctlMagic, 2, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_RESIZE = ioctl.IOW(ioctlMagic, 3, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_SCAN_DEV = ioctl.IOW(ioctlMagic, 4, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_TRANS_START = ioctl.IO(ioctlMagic, 6) + _BTRFS_IOC_TRANS_END = ioctl.IO(ioctlMagic, 7) + _BTRFS_IOC_SYNC = ioctl.IO(ioctlMagic, 8) + _BTRFS_IOC_CLONE = ioctl.IOW(ioctlMagic, 9, 4) // int32 + _BTRFS_IOC_ADD_DEV = ioctl.IOW(ioctlMagic, 10, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_RM_DEV = ioctl.IOW(ioctlMagic, 11, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_BALANCE = ioctl.IOW(ioctlMagic, 12, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_CLONE_RANGE = ioctl.IOW(ioctlMagic, 13, unsafe.Sizeof(btrfs_ioctl_clone_range_args{})) + _BTRFS_IOC_SUBVOL_CREATE = ioctl.IOW(ioctlMagic, 14, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_SNAP_DESTROY = ioctl.IOW(ioctlMagic, 15, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_DEFRAG_RANGE = ioctl.IOW(ioctlMagic, 16, unsafe.Sizeof(btrfs_ioctl_defrag_range_args{})) + _BTRFS_IOC_TREE_SEARCH = ioctl.IOWR(ioctlMagic, 17, unsafe.Sizeof(btrfs_ioctl_search_args{})) + _BTRFS_IOC_INO_LOOKUP = ioctl.IOWR(ioctlMagic, 18, unsafe.Sizeof(btrfs_ioctl_ino_lookup_args{})) + _BTRFS_IOC_DEFAULT_SUBVOL = ioctl.IOW(ioctlMagic, 19, 8) // uint64 + _BTRFS_IOC_SPACE_INFO = ioctl.IOWR(ioctlMagic, 20, unsafe.Sizeof(btrfs_ioctl_space_args{})) + _BTRFS_IOC_START_SYNC = ioctl.IOR(ioctlMagic, 24, 8) // uint64 + _BTRFS_IOC_WAIT_SYNC = ioctl.IOW(ioctlMagic, 22, 8) // uint64 + _BTRFS_IOC_SNAP_CREATE_V2 = ioctl.IOW(ioctlMagic, 23, unsafe.Sizeof(btrfs_ioctl_vol_args_v2{})) + _BTRFS_IOC_SUBVOL_CREATE_V2 = ioctl.IOW(ioctlMagic, 24, unsafe.Sizeof(btrfs_ioctl_vol_args_v2{})) + _BTRFS_IOC_SUBVOL_GETFLAGS = ioctl.IOR(ioctlMagic, 25, 8) // uint64 + _BTRFS_IOC_SUBVOL_SETFLAGS = ioctl.IOW(ioctlMagic, 26, 8) // uint64 + _BTRFS_IOC_SCRUB = ioctl.IOWR(ioctlMagic, 27, unsafe.Sizeof(btrfs_ioctl_scrub_args{})) + _BTRFS_IOC_SCRUB_CANCEL = ioctl.IO(ioctlMagic, 28) + _BTRFS_IOC_SCRUB_PROGRESS = ioctl.IOWR(ioctlMagic, 29, unsafe.Sizeof(btrfs_ioctl_scrub_args{})) + _BTRFS_IOC_DEV_INFO = ioctl.IOWR(ioctlMagic, 30, unsafe.Sizeof(btrfs_ioctl_dev_info_args{})) + _BTRFS_IOC_FS_INFO = ioctl.IOR(ioctlMagic, 31, unsafe.Sizeof(btrfs_ioctl_fs_info_args{})) + _BTRFS_IOC_BALANCE_V2 = ioctl.IOWR(ioctlMagic, 32, unsafe.Sizeof(btrfs_ioctl_balance_args{})) + _BTRFS_IOC_BALANCE_CTL = ioctl.IOW(ioctlMagic, 33, 4) // int32 + _BTRFS_IOC_BALANCE_PROGRESS = ioctl.IOR(ioctlMagic, 34, unsafe.Sizeof(btrfs_ioctl_balance_args{})) + _BTRFS_IOC_INO_PATHS = ioctl.IOWR(ioctlMagic, 35, unsafe.Sizeof(btrfs_ioctl_ino_path_args{})) + _BTRFS_IOC_LOGICAL_INO = ioctl.IOWR(ioctlMagic, 36, unsafe.Sizeof(btrfs_ioctl_ino_path_args{})) + _BTRFS_IOC_SET_RECEIVED_SUBVOL = ioctl.IOWR(ioctlMagic, 37, unsafe.Sizeof(btrfs_ioctl_received_subvol_args{})) + _BTRFS_IOC_SEND = ioctl.IOW(ioctlMagic, 38, unsafe.Sizeof(btrfs_ioctl_send_args{})) + _BTRFS_IOC_DEVICES_READY = ioctl.IOR(ioctlMagic, 39, unsafe.Sizeof(btrfs_ioctl_vol_args{})) + _BTRFS_IOC_QUOTA_CTL = ioctl.IOWR(ioctlMagic, 40, unsafe.Sizeof(btrfs_ioctl_quota_ctl_args{})) + _BTRFS_IOC_QGROUP_ASSIGN = ioctl.IOW(ioctlMagic, 41, unsafe.Sizeof(btrfs_ioctl_qgroup_assign_args{})) + _BTRFS_IOC_QGROUP_CREATE = ioctl.IOW(ioctlMagic, 42, unsafe.Sizeof(btrfs_ioctl_qgroup_create_args{})) + _BTRFS_IOC_QGROUP_LIMIT = ioctl.IOR(ioctlMagic, 43, unsafe.Sizeof(btrfs_ioctl_qgroup_limit_args{})) + _BTRFS_IOC_QUOTA_RESCAN = ioctl.IOW(ioctlMagic, 44, unsafe.Sizeof(btrfs_ioctl_quota_rescan_args{})) + _BTRFS_IOC_QUOTA_RESCAN_STATUS = ioctl.IOR(ioctlMagic, 45, unsafe.Sizeof(btrfs_ioctl_quota_rescan_args{})) + _BTRFS_IOC_QUOTA_RESCAN_WAIT = ioctl.IO(ioctlMagic, 46) + _BTRFS_IOC_GET_FSLABEL = ioctl.IOR(ioctlMagic, 49, labelSize) + _BTRFS_IOC_SET_FSLABEL = ioctl.IOW(ioctlMagic, 50, labelSize) + _BTRFS_IOC_GET_DEV_STATS = ioctl.IOWR(ioctlMagic, 52, unsafe.Sizeof(btrfs_ioctl_get_dev_stats{})) + _BTRFS_IOC_DEV_REPLACE = ioctl.IOWR(ioctlMagic, 53, unsafe.Sizeof(btrfs_ioctl_dev_replace_args_u1{})) + _BTRFS_IOC_FILE_EXTENT_SAME = ioctl.IOWR(ioctlMagic, 54, unsafe.Sizeof(btrfs_ioctl_same_args{})) + _BTRFS_IOC_GET_FEATURES = ioctl.IOR(ioctlMagic, 57, unsafe.Sizeof(btrfs_ioctl_feature_flags{})) + _BTRFS_IOC_SET_FEATURES = ioctl.IOW(ioctlMagic, 57, unsafe.Sizeof([2]btrfs_ioctl_feature_flags{})) + _BTRFS_IOC_GET_SUPPORTED_FEATURES = ioctl.IOR(ioctlMagic, 57, unsafe.Sizeof([3]btrfs_ioctl_feature_flags{})) +) + +func iocSnapCreate(f *os.File, in *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_SNAP_CREATE, in) +} + +func iocSnapCreateV2(f *os.File, in *btrfs_ioctl_vol_args_v2) error { + return ioctl.Do(f, _BTRFS_IOC_SNAP_CREATE_V2, in) +} + +func iocDefrag(f *os.File, out *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_DEFRAG, out) +} + +func iocResize(f *os.File, in *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_RESIZE, in) +} + +func iocScanDev(f *os.File, out *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_SCAN_DEV, out) +} + +func iocTransStart(f *os.File) error { + return ioctl.Do(f, _BTRFS_IOC_TRANS_START, nil) +} + +func iocTransEnd(f *os.File) error { + return ioctl.Do(f, _BTRFS_IOC_TRANS_END, nil) +} + +func iocSync(f *os.File) error { + return ioctl.Do(f, _BTRFS_IOC_SYNC, nil) +} + +func iocClone(dst, src *os.File) error { + return ioctl.Ioctl(dst, _BTRFS_IOC_CLONE, src.Fd()) +} + +func iocAddDev(f *os.File, out *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_ADD_DEV, out) +} + +func iocRmDev(f *os.File, out *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_RM_DEV, out) +} + +func iocBalance(f *os.File, out *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_BALANCE, out) +} + +func iocCloneRange(f *os.File, out *btrfs_ioctl_clone_range_args) error { + return ioctl.Do(f, _BTRFS_IOC_CLONE_RANGE, out) +} + +func iocSubvolCreate(f *os.File, in *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_SUBVOL_CREATE, in) +} + +func iocSubvolCreateV2(f *os.File, in *btrfs_ioctl_vol_args_v2) error { + return ioctl.Do(f, _BTRFS_IOC_SUBVOL_CREATE, in) +} + +func iocSnapDestroy(f *os.File, in *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_SNAP_DESTROY, in) +} + +func iocDefragRange(f *os.File, out *btrfs_ioctl_defrag_range_args) error { + return ioctl.Do(f, _BTRFS_IOC_DEFRAG_RANGE, out) +} + +func iocTreeSearch(f *os.File, out *btrfs_ioctl_search_args) error { + return ioctl.Do(f, _BTRFS_IOC_TREE_SEARCH, out) +} + +func iocInoLookup(f *os.File, out *btrfs_ioctl_ino_lookup_args) error { + return ioctl.Do(f, _BTRFS_IOC_INO_LOOKUP, out) +} + +func iocDefaultSubvol(f *os.File, out *uint64) error { + return ioctl.Do(f, _BTRFS_IOC_DEFAULT_SUBVOL, out) +} + +type spaceFlags uint64 + +func (f spaceFlags) BlockGroup() blockGroup { + return blockGroup(f) & _BTRFS_BLOCK_GROUP_MASK +} + +type spaceInfo struct { + Flags spaceFlags + TotalBytes uint64 + UsedBytes uint64 +} + +func iocSpaceInfo(f *os.File) ([]spaceInfo, error) { + arg := &btrfs_ioctl_space_args{} + if err := ioctl.Do(f, _BTRFS_IOC_SPACE_INFO, arg); err != nil { + return nil, err + } + n := arg.total_spaces + if n == 0 { + return nil, nil + } + const ( + argSize = unsafe.Sizeof(btrfs_ioctl_space_args{}) + infoSize = unsafe.Sizeof(btrfs_ioctl_space_info{}) + ) + buf := make([]byte, argSize+uintptr(n)*infoSize) + basePtr := unsafe.Pointer(&buf[0]) + arg = (*btrfs_ioctl_space_args)(basePtr) + arg.space_slots = n + if err := ioctl.Do(f, _BTRFS_IOC_SPACE_INFO, arg); err != nil { + return nil, err + } else if arg.total_spaces == 0 { + return nil, nil + } + if n > arg.total_spaces { + n = arg.total_spaces + } + out := make([]spaceInfo, n) + ptr := uintptr(basePtr) + argSize + for i := 0; i < int(n); i++ { + info := (*btrfs_ioctl_space_info)(unsafe.Pointer(ptr)) + out[i] = spaceInfo{ + Flags: spaceFlags(info.flags), + TotalBytes: info.total_bytes, + UsedBytes: info.used_bytes, + } + ptr += infoSize + } + return out, nil +} + +func iocStartSync(f *os.File, out *uint64) error { + return ioctl.Do(f, _BTRFS_IOC_START_SYNC, out) +} + +func iocWaitSync(f *os.File, out *uint64) error { + return ioctl.Do(f, _BTRFS_IOC_WAIT_SYNC, out) +} + +func iocSubvolGetflags(f *os.File) (out SubvolFlags, err error) { + err = ioctl.Do(f, _BTRFS_IOC_SUBVOL_GETFLAGS, &out) + return +} + +func iocSubvolSetflags(f *os.File, flags SubvolFlags) error { + v := uint64(flags) + return ioctl.Do(f, _BTRFS_IOC_SUBVOL_SETFLAGS, &v) +} + +func iocScrub(f *os.File, out *btrfs_ioctl_scrub_args) error { + return ioctl.Do(f, _BTRFS_IOC_SCRUB, out) +} + +func iocScrubCancel(f *os.File) error { + return ioctl.Do(f, _BTRFS_IOC_SCRUB_CANCEL, nil) +} + +func iocScrubProgress(f *os.File, out *btrfs_ioctl_scrub_args) error { + return ioctl.Do(f, _BTRFS_IOC_SCRUB_PROGRESS, out) +} + +func iocFsInfo(f *os.File) (out btrfs_ioctl_fs_info_args, err error) { + err = ioctl.Do(f, _BTRFS_IOC_FS_INFO, &out) + return +} + +func iocDevInfo(f *os.File, devid uint64, uuid UUID) (out btrfs_ioctl_dev_info_args, err error) { + out.devid = devid + out.uuid = uuid + err = ioctl.Do(f, _BTRFS_IOC_DEV_INFO, &out) + return +} + +func iocBalanceV2(f *os.File, out *btrfs_ioctl_balance_args) error { + return ioctl.Do(f, _BTRFS_IOC_BALANCE_V2, out) +} + +func iocBalanceCtl(f *os.File, out *int32) error { + return ioctl.Do(f, _BTRFS_IOC_BALANCE_CTL, out) +} + +func iocBalanceProgress(f *os.File, out *btrfs_ioctl_balance_args) error { + return ioctl.Do(f, _BTRFS_IOC_BALANCE_PROGRESS, out) +} + +func iocInoPaths(f *os.File, out *btrfs_ioctl_ino_path_args) error { + return ioctl.Do(f, _BTRFS_IOC_INO_PATHS, out) +} + +func iocLogicalIno(f *os.File, out *btrfs_ioctl_ino_path_args) error { + return ioctl.Do(f, _BTRFS_IOC_LOGICAL_INO, out) +} + +func iocSetReceivedSubvol(f *os.File, out *btrfs_ioctl_received_subvol_args) error { + return ioctl.Do(f, _BTRFS_IOC_SET_RECEIVED_SUBVOL, out) +} + +func iocSend(f *os.File, in *btrfs_ioctl_send_args) error { + return ioctl.Do(f, _BTRFS_IOC_SEND, in) +} + +func iocDevicesReady(f *os.File, out *btrfs_ioctl_vol_args) error { + return ioctl.Do(f, _BTRFS_IOC_DEVICES_READY, out) +} + +func iocQuotaCtl(f *os.File, out *btrfs_ioctl_quota_ctl_args) error { + return ioctl.Do(f, _BTRFS_IOC_QUOTA_CTL, out) +} + +func iocQgroupAssign(f *os.File, out *btrfs_ioctl_qgroup_assign_args) error { + return ioctl.Do(f, _BTRFS_IOC_QGROUP_ASSIGN, out) +} + +func iocQgroupCreate(f *os.File, out *btrfs_ioctl_qgroup_create_args) error { + return ioctl.Do(f, _BTRFS_IOC_QGROUP_CREATE, out) +} + +func iocQgroupLimit(f *os.File, out *btrfs_ioctl_qgroup_limit_args) error { + return ioctl.Do(f, _BTRFS_IOC_QGROUP_LIMIT, out) +} + +func iocQuotaRescan(f *os.File, out *btrfs_ioctl_quota_rescan_args) error { + return ioctl.Do(f, _BTRFS_IOC_QUOTA_RESCAN, out) +} + +func iocQuotaRescanStatus(f *os.File, out *btrfs_ioctl_quota_rescan_args) error { + return ioctl.Do(f, _BTRFS_IOC_QUOTA_RESCAN_STATUS, out) +} + +func iocQuotaRescanWait(f *os.File) error { + return ioctl.Do(f, _BTRFS_IOC_QUOTA_RESCAN_WAIT, nil) +} + +func iocGetFslabel(f *os.File, out *[labelSize]byte) error { + return ioctl.Do(f, _BTRFS_IOC_GET_FSLABEL, out) +} + +func iocSetFslabel(f *os.File, out *[labelSize]byte) error { + return ioctl.Do(f, _BTRFS_IOC_SET_FSLABEL, out) +} + +func iocGetDevStats(f *os.File, out *btrfs_ioctl_get_dev_stats) error { + return ioctl.Do(f, _BTRFS_IOC_GET_DEV_STATS, out) +} + +//func iocDevReplace(f *os.File, out *btrfs_ioctl_dev_replace_args) error { +// return ioctl.Do(f, _BTRFS_IOC_DEV_REPLACE, out) +//} + +func iocFileExtentSame(f *os.File, out *btrfs_ioctl_same_args) error { + return ioctl.Do(f, _BTRFS_IOC_FILE_EXTENT_SAME, out) +} + +func iocSetFeatures(f *os.File, out *[2]btrfs_ioctl_feature_flags) error { + return ioctl.Do(f, _BTRFS_IOC_SET_FEATURES, out) +} diff --git a/vendor/github.com/dennwc/btrfs/mtab/mtab.go b/vendor/github.com/dennwc/btrfs/mtab/mtab.go new file mode 100644 index 00000000..e1651ed1 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/mtab/mtab.go @@ -0,0 +1,43 @@ +// Package mtab contains tools to work with /etc/mtab file. +package mtab + +import ( + "bufio" + "io" + "os" + "strings" +) + +type MountPoint struct { + Dev string + Mount string + Type string + Opts string +} + +// Mounts returns a list of mount point from /etc/mtab. +func Mounts() ([]MountPoint, error) { + file, err := os.Open("/etc/mtab") + if err != nil { + return nil, err + } + defer file.Close() + r := bufio.NewReader(file) + var out []MountPoint + for { + line, err := r.ReadString('\n') + if err == io.EOF { + break + } else if err != nil { + return nil, err + } + fields := strings.Fields(line) + out = append(out, MountPoint{ + Dev: fields[0], + Mount: fields[1], + Type: fields[2], + Opts: fields[3], + }) + } + return out, nil +} diff --git a/vendor/github.com/dennwc/btrfs/receive.go b/vendor/github.com/dennwc/btrfs/receive.go new file mode 100644 index 00000000..015714aa --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/receive.go @@ -0,0 +1,58 @@ +package btrfs + +import ( + "bytes" + "errors" + "io" + "os" + "os/exec" + "path/filepath" + "syscall" +) + +const nativeReceive = false + +func Receive(r io.Reader, dstDir string) error { + if !nativeReceive { + buf := bytes.NewBuffer(nil) + cmd := exec.Command("btrfs", "receive", dstDir) + cmd.Stdin = r + cmd.Stderr = buf + if err := cmd.Run(); err != nil { + if buf.Len() != 0 { + return errors.New(buf.String()) + } + return err + } + return nil + } + var err error + dstDir, err = filepath.Abs(dstDir) + if err != nil { + return err + } + realMnt, err := findMountRoot(dstDir) + if err != nil { + return err + } + dir, err := os.OpenFile(dstDir, os.O_RDONLY|syscall.O_NOATIME, 0755) + if err != nil { + return err + } + mnt, err := os.OpenFile(realMnt, os.O_RDONLY|syscall.O_NOATIME, 0755) + if err != nil { + return err + } + // We want to resolve the path to the subvolume we're sitting in + // so that we can adjust the paths of any subvols we want to receive in. + subvolID, err := getFileRootID(mnt) + if err != nil { + return err + } + //sr, err := send.NewStreamReader(r) + //if err != nil { + // return err + //} + _, _ = dir, subvolID + panic("not implemented") +} diff --git a/vendor/github.com/dennwc/btrfs/send.go b/vendor/github.com/dennwc/btrfs/send.go new file mode 100644 index 00000000..0f324bba --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/send.go @@ -0,0 +1,245 @@ +package btrfs + +import ( + "fmt" + "io" + "os" + "path/filepath" + "unsafe" +) + +func Send(w io.Writer, parent string, subvols ...string) error { + if len(subvols) == 0 { + return nil + } + // use first send subvol to determine mount_root + subvol, err := filepath.Abs(subvols[0]) + if err != nil { + return err + } + mountRoot, err := findMountRoot(subvol) + if err == os.ErrNotExist { + return fmt.Errorf("cannot find a mountpoint for %s", subvol) + } else if err != nil { + return err + } + var ( + cloneSrc []objectID + parentID objectID + ) + if parent != "" { + parent, err = filepath.Abs(parent) + if err != nil { + return err + } + id, err := getPathRootID(parent) + if err != nil { + return fmt.Errorf("cannot get parent root id: %v", err) + } + parentID = id + cloneSrc = append(cloneSrc, id) + } + // check all subvolumes + paths := make([]string, 0, len(subvols)) + for _, sub := range subvols { + sub, err = filepath.Abs(sub) + if err != nil { + return err + } + paths = append(paths, sub) + mount, err := findMountRoot(sub) + if err != nil { + return fmt.Errorf("cannot find mount root for %v: %v", sub, err) + } else if mount != mountRoot { + return fmt.Errorf("all subvolumes must be from the same filesystem (%s is not)", sub) + } + ok, err := IsReadOnly(sub) + if err != nil { + return err + } else if !ok { + return fmt.Errorf("subvolume %s is not read-only", sub) + } + } + mfs, err := Open(mountRoot, true) + if err != nil { + return err + } + defer mfs.Close() + full := len(cloneSrc) == 0 + for i, sub := range paths { + var rootID objectID + if !full && parent != "" { + rel, err := filepath.Rel(mountRoot, sub) + if err != nil { + return err + } + si, err := subvolSearchByPath(mfs.f, rel) + if err != nil { + return fmt.Errorf("cannot find subvolume %s: %v", rel, err) + } + rootID = objectID(si.RootID) + parentID, err = findGoodParent(mfs.f, rootID, cloneSrc) + if err != nil { + return fmt.Errorf("cannot find good parent for %v: %v", rel, err) + } + } + fs, err := Open(sub, true) + if err != nil { + return err + } + var flags uint64 + if i != 0 { // not first + flags |= _BTRFS_SEND_FLAG_OMIT_STREAM_HEADER + } + if i < len(paths)-1 { // not last + flags |= _BTRFS_SEND_FLAG_OMIT_END_CMD + } + err = send(w, fs.f, parentID, cloneSrc, flags) + fs.Close() + if err != nil { + return fmt.Errorf("error sending %s: %v", sub, err) + } + if !full && parent != "" { + cloneSrc = append(cloneSrc, rootID) + } + } + return nil +} + +func send(w io.Writer, subvol *os.File, parent objectID, sources []objectID, flags uint64) error { + pr, pw, err := os.Pipe() + if err != nil { + return err + } + errc := make(chan error, 1) + go func() { + defer pr.Close() + _, err := io.Copy(w, pr) + errc <- err + }() + fd := pw.Fd() + wait := func() error { + pw.Close() + return <-errc + } + args := &btrfs_ioctl_send_args{ + send_fd: int64(fd), + parent_root: parent, + flags: flags, + } + if len(sources) != 0 { + args.clone_sources = &sources[0] + args.clone_sources_count = uint64(len(sources)) + } + if err := iocSend(subvol, args); err != nil { + wait() + return err + } + return wait() +} + +// readRootItem reads a root item from the tree. +// +// TODO(dennwc): support older kernels: +// In case we detect a root item smaller then sizeof(root_item), +// we know it's an old version of the root structure and initialize all new fields to zero. +// The same happens if we detect mismatching generation numbers as then we know the root was +// once mounted with an older kernel that was not aware of the root item structure change. +func readRootItem(mnt *os.File, rootID objectID) (*rootItem, error) { + sk := btrfs_ioctl_search_key{ + tree_id: rootTreeObjectid, + // There may be more than one ROOT_ITEM key if there are + // snapshots pending deletion, we have to loop through them. + min_objectid: rootID, + max_objectid: rootID, + min_type: rootItemKey, + max_type: rootItemKey, + max_offset: maxUint64, + max_transid: maxUint64, + nr_items: 4096, + } + for ; sk.min_offset < maxUint64; sk.min_offset++ { + results, err := treeSearchRaw(mnt, sk) + if err != nil { + return nil, err + } else if len(results) == 0 { + break + } + for _, r := range results { + sk.min_objectid = r.ObjectID + sk.min_type = r.Type + sk.min_offset = r.Offset + if r.ObjectID > rootID { + break + } + if r.ObjectID == rootID && r.Type == rootItemKey { + const sz = int(unsafe.Sizeof(btrfs_root_item_raw{})) + if len(r.Data) > sz { + return nil, fmt.Errorf("btrfs_root_item is larger than expected; kernel is newer than the library") + } else if len(r.Data) < sz { // TODO + return nil, fmt.Errorf("btrfs_root_item is smaller then expected; kernel version is too old") + } + p := asRootItem(r.Data).Decode() + return &p, nil + } + } + results = nil + if sk.min_type != rootItemKey || sk.min_objectid != rootID { + break + } + } + return nil, ErrNotFound +} + +func getParent(mnt *os.File, rootID objectID) (*SubvolInfo, error) { + st, err := subvolSearchByRootID(mnt, rootID, "") + if err != nil { + return nil, fmt.Errorf("cannot find subvolume %d to determine parent: %v", rootID, err) + } + return subvolSearchByUUID(mnt, st.ParentUUID) +} + +func findGoodParent(mnt *os.File, rootID objectID, cloneSrc []objectID) (objectID, error) { + parent, err := getParent(mnt, rootID) + if err != nil { + return 0, fmt.Errorf("get parent failed: %v", err) + } + for _, id := range cloneSrc { + if id == objectID(parent.RootID) { + return objectID(parent.RootID), nil + } + } + var ( + bestParent *SubvolInfo + bestDiff uint64 = maxUint64 + ) + for _, id := range cloneSrc { + parent2, err := getParent(mnt, id) + if err == ErrNotFound { + continue + } else if err != nil { + return 0, err + } + if parent2.RootID != parent.RootID { + continue + } + parent2, err = subvolSearchByRootID(mnt, id, "") + if err != nil { + return 0, err + } + diff := int64(parent2.CTransID - parent.CTransID) + if diff < 0 { + diff = -diff + } + if uint64(diff) < bestDiff { + bestParent, bestDiff = parent2, uint64(diff) + } + } + if bestParent != nil { + return objectID(bestParent.RootID), nil + } + if !parent.ParentUUID.IsZero() { + return findGoodParent(mnt, objectID(parent.RootID), cloneSrc) + } + return 0, ErrNotFound +} diff --git a/vendor/github.com/dennwc/btrfs/subvolume.go b/vendor/github.com/dennwc/btrfs/subvolume.go new file mode 100644 index 00000000..0d2d808f --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/subvolume.go @@ -0,0 +1,379 @@ +package btrfs + +import ( + "fmt" + "os" + "path/filepath" + "strings" + "syscall" + "time" +) + +func checkSubVolumeName(name string) bool { + return name != "" && name[0] != 0 && !strings.ContainsRune(name, '/') && + name != "." && name != ".." +} + +func IsSubVolume(path string) (bool, error) { + var st syscall.Stat_t + if err := syscall.Stat(path, &st); err != nil { + return false, &os.PathError{Op: "stat", Path: path, Err: err} + } + if objectID(st.Ino) != firstFreeObjectid || + st.Mode&syscall.S_IFMT != syscall.S_IFDIR { + return false, nil + } + return isBtrfs(path) +} + +func CreateSubVolume(path string) error { + var inherit *btrfs_qgroup_inherit // TODO + + cpath, err := filepath.Abs(path) + if err != nil { + return err + } + newName := filepath.Base(cpath) + dstDir := filepath.Dir(cpath) + if !checkSubVolumeName(newName) { + return fmt.Errorf("invalid subvolume name: %s", newName) + } else if len(newName) >= volNameMax { + return fmt.Errorf("subvolume name too long: %s", newName) + } + dst, err := openDir(dstDir) + if err != nil { + return err + } + defer dst.Close() + if inherit != nil { + panic("not implemented") // TODO + args := btrfs_ioctl_vol_args_v2{ + flags: subvolQGroupInherit, + btrfs_ioctl_vol_args_v2_u1: btrfs_ioctl_vol_args_v2_u1{ + //size: qgroup_inherit_size(inherit), + qgroup_inherit: inherit, + }, + } + copy(args.name[:], newName) + return iocSubvolCreateV2(dst, &args) + } + var args btrfs_ioctl_vol_args + copy(args.name[:], newName) + return iocSubvolCreate(dst, &args) +} + +func DeleteSubVolume(path string) error { + if ok, err := IsSubVolume(path); err != nil { + return err + } else if !ok { + return fmt.Errorf("not a subvolume: %s", path) + } + cpath, err := filepath.Abs(path) + if err != nil { + return err + } + dname := filepath.Dir(cpath) + vname := filepath.Base(cpath) + + dir, err := openDir(dname) + if err != nil { + return err + } + defer dir.Close() + var args btrfs_ioctl_vol_args + copy(args.name[:], vname) + return iocSnapDestroy(dir, &args) +} + +func SnapshotSubVolume(subvol, dst string, ro bool) error { + if ok, err := IsSubVolume(subvol); err != nil { + return err + } else if !ok { + return fmt.Errorf("not a subvolume: %s", subvol) + } + exists := false + if st, err := os.Stat(dst); err != nil && !os.IsNotExist(err) { + return err + } else if err == nil { + if !st.IsDir() { + return fmt.Errorf("'%s' exists and it is not a directory", dst) + } + exists = true + } + var ( + newName string + dstDir string + ) + if exists { + newName = filepath.Base(subvol) + dstDir = dst + } else { + newName = filepath.Base(dst) + dstDir = filepath.Dir(dst) + } + if !checkSubVolumeName(newName) { + return fmt.Errorf("invalid snapshot name '%s'", newName) + } else if len(newName) >= volNameMax { + return fmt.Errorf("snapshot name too long '%s'", newName) + } + fdst, err := openDir(dstDir) + if err != nil { + return err + } + defer fdst.Close() + // TODO: make SnapshotSubVolume a method on FS to use existing fd + f, err := openDir(subvol) + if err != nil { + return fmt.Errorf("cannot open dest dir: %v", err) + } + defer f.Close() + args := btrfs_ioctl_vol_args_v2{ + fd: int64(f.Fd()), + } + if ro { + args.flags |= SubvolReadOnly + } + // TODO + //if inherit != nil { + // args.flags |= subvolQGroupInherit + // args.size = qgroup_inherit_size(inherit) + // args.qgroup_inherit = inherit + //} + copy(args.name[:], newName) + if err := iocSnapCreateV2(fdst, &args); err != nil { + return fmt.Errorf("snapshot create failed: %v", err) + } + return nil +} + +func IsReadOnly(path string) (bool, error) { + f, err := GetFlags(path) + if err != nil { + return false, err + } + return f.ReadOnly(), nil +} + +func GetFlags(path string) (SubvolFlags, error) { + fs, err := Open(path, true) + if err != nil { + return 0, err + } + defer fs.Close() + return fs.GetFlags() +} + +func listSubVolumes(f *os.File, filter func(SubvolInfo) bool) (map[objectID]SubvolInfo, error) { + sk := btrfs_ioctl_search_key{ + // search in the tree of tree roots + tree_id: rootTreeObjectid, + + // Set the min and max to backref keys. The search will + // only send back this type of key now. + min_type: rootItemKey, + max_type: rootBackrefKey, + + min_objectid: firstFreeObjectid, + + // Set all the other params to the max, we'll take any objectid + // and any trans. + max_objectid: lastFreeObjectid, + max_offset: maxUint64, + max_transid: maxUint64, + + nr_items: 4096, // just a big number, doesn't matter much + } + m := make(map[objectID]SubvolInfo) + for { + out, err := treeSearchRaw(f, sk) + if err != nil { + return nil, err + } else if len(out) == 0 { + break + } + for _, obj := range out { + switch obj.Type { + //case rootBackrefKey: + // ref := asRootRef(obj.Data) + // o := m[obj.ObjectID] + // o.TransID = obj.TransID + // o.ObjectID = obj.ObjectID + // o.RefTree = obj.Offset + // o.DirID = ref.DirID + // o.Name = ref.Name + // m[obj.ObjectID] = o + case rootItemKey: + o := m[obj.ObjectID] + o.RootID = uint64(obj.ObjectID) + robj := asRootItem(obj.Data).Decode() + o.fillFromItem(&robj) + m[obj.ObjectID] = o + } + } + // record the mins in key so we can make sure the + // next search doesn't repeat this root + last := out[len(out)-1] + sk.min_objectid = last.ObjectID + sk.min_type = last.Type + sk.min_offset = last.Offset + 1 + if sk.min_offset == 0 { // overflow + sk.min_type++ + } else { + continue + } + if sk.min_type > rootBackrefKey { + sk.min_type = rootItemKey + sk.min_objectid++ + } else { + continue + } + if sk.min_objectid > sk.max_objectid { + break + } + } + // resolve paths + for id, v := range m { + if path, err := subvolidResolve(f, id); err == ErrNotFound { + delete(m, id) + continue + } else if err != nil { + return m, fmt.Errorf("cannot resolve path for %v: %v", id, err) + } else { + v.Path = path + m[id] = v + } + if filter != nil && !filter(v) { + delete(m, id) + } + } + + return m, nil +} + +type SubvolInfo struct { + RootID uint64 + + UUID UUID + ParentUUID UUID + ReceivedUUID UUID + + CTime time.Time + OTime time.Time + STime time.Time + RTime time.Time + + CTransID uint64 + OTransID uint64 + STransID uint64 + RTransID uint64 + + Path string +} + +func (s *SubvolInfo) fillFromItem(it *rootItem) { + s.UUID = it.UUID + s.ReceivedUUID = it.ReceivedUUID + s.ParentUUID = it.ParentUUID + + s.CTime = it.CTime + s.OTime = it.OTime + s.STime = it.STime + s.RTime = it.RTime + + s.CTransID = it.CTransID + s.OTransID = it.OTransID + s.STransID = it.STransID + s.RTransID = it.RTransID +} + +func subvolSearchByUUID(mnt *os.File, uuid UUID) (*SubvolInfo, error) { + id, err := lookupUUIDSubvolItem(mnt, uuid) + if err != nil { + return nil, err + } + return subvolSearchByRootID(mnt, id, "") +} + +func subvolSearchByReceivedUUID(mnt *os.File, uuid UUID) (*SubvolInfo, error) { + id, err := lookupUUIDReceivedSubvolItem(mnt, uuid) + if err != nil { + return nil, err + } + return subvolSearchByRootID(mnt, id, "") +} + +func subvolSearchByPath(mnt *os.File, path string) (*SubvolInfo, error) { + if !filepath.IsAbs(path) { + path = filepath.Join(mnt.Name(), path) + } + id, err := getPathRootID(path) + if err != nil { + return nil, err + } + return subvolSearchByRootID(mnt, id, path) +} + +func subvolidResolve(mnt *os.File, subvolID objectID) (string, error) { + return subvolidResolveSub(mnt, "", subvolID) +} + +func subvolidResolveSub(mnt *os.File, path string, subvolID objectID) (string, error) { + if subvolID == fsTreeObjectid { + return "", nil + } + sk := btrfs_ioctl_search_key{ + tree_id: rootTreeObjectid, + min_objectid: subvolID, + max_objectid: subvolID, + min_type: rootBackrefKey, + max_type: rootBackrefKey, + max_offset: maxUint64, + max_transid: maxUint64, + nr_items: 1, + } + results, err := treeSearchRaw(mnt, sk) + if err != nil { + return "", err + } else if len(results) < 1 { + return "", ErrNotFound + } + res := results[0] + if objectID(res.Offset) != fsTreeObjectid { + spath, err := subvolidResolveSub(mnt, path, objectID(res.Offset)) + if err != nil { + return "", err + } + path = spath + "/" + } + backRef := asRootRef(res.Data) + if backRef.DirID != firstFreeObjectid { + arg := btrfs_ioctl_ino_lookup_args{ + treeid: objectID(res.Offset), + objectid: backRef.DirID, + } + if err := iocInoLookup(mnt, &arg); err != nil { + return "", err + } + path += arg.Name() + } + return path + backRef.Name, nil +} + +// subvolSearchByRootID +// +// Path is optional, and will be resolved automatically if not set. +func subvolSearchByRootID(mnt *os.File, rootID objectID, path string) (*SubvolInfo, error) { + robj, err := readRootItem(mnt, rootID) + if err != nil { + return nil, err + } + info := &SubvolInfo{ + RootID: uint64(rootID), + Path: path, + } + info.fillFromItem(robj) + if path == "" { + info.Path, err = subvolidResolve(mnt, objectID(info.RootID)) + } + return info, err +} diff --git a/vendor/github.com/dennwc/btrfs/usage.go b/vendor/github.com/dennwc/btrfs/usage.go new file mode 100644 index 00000000..792ea869 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/usage.go @@ -0,0 +1,176 @@ +package btrfs + +import ( + "os" + "sort" + "syscall" +) + +func cmpChunkBlockGroup(f1, f2 blockGroup) int { + var mask blockGroup + + if (f1 & _BTRFS_BLOCK_GROUP_TYPE_MASK) == + (f2 & _BTRFS_BLOCK_GROUP_TYPE_MASK) { + mask = _BTRFS_BLOCK_GROUP_PROFILE_MASK + } else if f2&blockGroupSystem != 0 { + return -1 + } else if f1&blockGroupSystem != 0 { + return +1 + } else { + mask = _BTRFS_BLOCK_GROUP_TYPE_MASK + } + + if (f1 & mask) > (f2 & mask) { + return +1 + } else if (f1 & mask) < (f2 & mask) { + return -1 + } else { + return 0 + } +} + +type spaceInfoByBlockGroup []spaceInfo + +func (a spaceInfoByBlockGroup) Len() int { return len(a) } +func (a spaceInfoByBlockGroup) Swap(i, j int) { a[i], a[j] = a[j], a[i] } +func (a spaceInfoByBlockGroup) Less(i, j int) bool { + return cmpChunkBlockGroup(blockGroup(a[i].Flags), blockGroup(a[j].Flags)) < 0 +} + +type UsageInfo struct { + Total uint64 + TotalUnused uint64 + TotalUsed uint64 + TotalChunks uint64 + + FreeEstimated uint64 + FreeMin uint64 + + LogicalDataChunks uint64 + RawDataChunks uint64 + RawDataUsed uint64 + + LogicalMetaChunks uint64 + RawMetaChunks uint64 + RawMetaUsed uint64 + + SystemUsed uint64 + SystemChunks uint64 + + DataRatio float64 + MetadataRatio float64 + + GlobalReserve uint64 + GlobalReserveUsed uint64 +} + +const minUnallocatedThreshold = 16 * 1024 * 1024 + +func spaceUsage(f *os.File) (UsageInfo, error) { + info, err := iocFsInfo(f) + if err != nil { + return UsageInfo{}, err + } + var u UsageInfo + for i := uint64(0); i <= info.max_id; i++ { + dev, err := iocDevInfo(f, i, UUID{}) + if err == syscall.ENODEV { + continue + } else if err != nil { + return UsageInfo{}, err + } + u.Total += dev.total_bytes + } + + spaces, err := iocSpaceInfo(f) + if err != nil { + return UsageInfo{}, err + } + sort.Sort(spaceInfoByBlockGroup(spaces)) + var ( + maxDataRatio int = 1 + mixed bool + ) + for _, s := range spaces { + ratio := 1 + bg := s.Flags.BlockGroup() + switch { + case bg&blockGroupRaid0 != 0: + ratio = 1 + case bg&blockGroupRaid1 != 0: + ratio = 2 + case bg&blockGroupRaid5 != 0: + ratio = 0 + case bg&blockGroupRaid6 != 0: + ratio = 0 + case bg&blockGroupDup != 0: + ratio = 2 + case bg&blockGroupRaid10 != 0: + ratio = 2 + } + if ratio > maxDataRatio { + maxDataRatio = ratio + } + if bg&spaceInfoGlobalRsv != 0 { + u.GlobalReserve = s.TotalBytes + u.GlobalReserveUsed = s.UsedBytes + } + if bg&(blockGroupData|blockGroupMetadata) == (blockGroupData | blockGroupMetadata) { + mixed = true + } + if bg&blockGroupData != 0 { + u.RawDataUsed += s.UsedBytes * uint64(ratio) + u.RawDataChunks += s.TotalBytes * uint64(ratio) + u.LogicalDataChunks += s.TotalBytes + } + if bg&blockGroupMetadata != 0 { + u.RawMetaUsed += s.UsedBytes * uint64(ratio) + u.RawMetaChunks += s.TotalBytes * uint64(ratio) + u.LogicalMetaChunks += s.TotalBytes + } + if bg&blockGroupSystem != 0 { + u.SystemUsed += s.UsedBytes * uint64(ratio) + u.SystemChunks += s.TotalBytes * uint64(ratio) + } + } + u.TotalChunks = u.RawDataChunks + u.SystemChunks + u.TotalUsed = u.RawDataUsed + u.SystemUsed + if !mixed { + u.TotalChunks += u.RawMetaChunks + u.TotalUsed += u.RawMetaUsed + } + u.TotalUnused = u.Total - u.TotalChunks + + u.DataRatio = float64(u.RawDataChunks) / float64(u.LogicalDataChunks) + if mixed { + u.MetadataRatio = u.DataRatio + } else { + u.MetadataRatio = float64(u.RawMetaChunks) / float64(u.LogicalMetaChunks) + } + + // We're able to fill at least DATA for the unused space + // + // With mixed raid levels, this gives a rough estimate but more + // accurate than just counting the logical free space + // (l_data_chunks - l_data_used) + // + // In non-mixed case there's no difference. + u.FreeEstimated = uint64(float64(u.RawDataChunks-u.RawDataUsed) / u.DataRatio) + + // For mixed-bg the metadata are left out in calculations thus global + // reserve would be lost. Part of it could be permanently allocated, + // we have to subtract the used bytes so we don't go under zero free. + if mixed { + u.FreeEstimated -= u.GlobalReserve - u.GlobalReserveUsed + } + u.FreeMin = u.FreeEstimated + + // Chop unallocatable space + // FIXME: must be applied per device + if u.TotalUnused >= minUnallocatedThreshold { + u.FreeEstimated += uint64(float64(u.TotalUnused) / u.DataRatio) + // Match the calculation of 'df', use the highest raid ratio + u.FreeMin += u.TotalUnused / uint64(maxDataRatio) + } + return u, nil +} diff --git a/vendor/github.com/dennwc/btrfs/utils.go b/vendor/github.com/dennwc/btrfs/utils.go new file mode 100644 index 00000000..bbf96e3a --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/utils.go @@ -0,0 +1,107 @@ +package btrfs + +import ( + "bytes" + "fmt" + "os" + "path/filepath" + "strings" + "syscall" + "unsafe" + + "github.com/dennwc/btrfs/mtab" +) + +func isBtrfs(path string) (bool, error) { + var stfs syscall.Statfs_t + if err := syscall.Statfs(path, &stfs); err != nil { + return false, &os.PathError{Op: "statfs", Path: path, Err: err} + } + fsType := uint32(stfs.Type) + return fsType == SuperMagic, nil +} + +func findMountRoot(path string) (string, error) { + mounts, err := mtab.Mounts() + if err != nil { + return "", err + } + longest := "" + isBtrfs := false + for _, m := range mounts { + if !strings.HasPrefix(path, m.Mount) { + continue + } + if len(longest) < len(m.Mount) { + longest = m.Mount + isBtrfs = m.Type == "btrfs" + } + } + if longest == "" { + return "", os.ErrNotExist + } else if !isBtrfs { + return "", ErrNotBtrfs{Path: longest} + } + return filepath.Abs(longest) +} + +// openDir does the following checks before calling Open: +// 1: path is in a btrfs filesystem +// 2: path is a directory +func openDir(path string) (*os.File, error) { + if ok, err := isBtrfs(path); err != nil { + return nil, err + } else if !ok { + return nil, ErrNotBtrfs{Path: path} + } + file, err := os.Open(path) + if err != nil { + return nil, err + } else if st, err := file.Stat(); err != nil { + file.Close() + return nil, err + } else if !st.IsDir() { + file.Close() + return nil, fmt.Errorf("not a directory: %s", path) + } + return file, nil +} + +type searchResult struct { + TransID uint64 + ObjectID objectID + Type treeKeyType + Offset uint64 + Data []byte +} + +func treeSearchRaw(mnt *os.File, key btrfs_ioctl_search_key) (out []searchResult, _ error) { + args := btrfs_ioctl_search_args{ + key: key, + } + if err := iocTreeSearch(mnt, &args); err != nil { + return nil, err + } + out = make([]searchResult, 0, args.key.nr_items) + buf := args.buf[:] + for i := 0; i < int(args.key.nr_items); i++ { + h := (*btrfs_ioctl_search_header)(unsafe.Pointer(&buf[0])) + buf = buf[unsafe.Sizeof(btrfs_ioctl_search_header{}):] + out = append(out, searchResult{ + TransID: h.transid, + ObjectID: h.objectid, + Offset: h.offset, + Type: h.typ, + Data: buf[:h.len:h.len], // TODO: reallocate? + }) + buf = buf[h.len:] + } + return out, nil +} + +func stringFromBytes(input []byte) string { + if i := bytes.IndexByte(input, 0); i >= 0 { + input = input[:i] + } + return string(input) +} diff --git a/vendor/github.com/dennwc/btrfs/uuid_tree.go b/vendor/github.com/dennwc/btrfs/uuid_tree.go new file mode 100644 index 00000000..4906ad02 --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/uuid_tree.go @@ -0,0 +1,49 @@ +package btrfs + +import ( + "encoding/binary" + "fmt" + "os" +) + +func lookupUUIDSubvolItem(f *os.File, uuid UUID) (objectID, error) { + return uuidTreeLookupAny(f, uuid, uuidKeySubvol) +} + +func lookupUUIDReceivedSubvolItem(f *os.File, uuid UUID) (objectID, error) { + return uuidTreeLookupAny(f, uuid, uuidKeyReceivedSubvol) +} + +func (id UUID) toKey() (objID objectID, off uint64) { + objID = objectID(binary.LittleEndian.Uint64(id[:8])) + off = binary.LittleEndian.Uint64(id[8:16]) + return +} + +// uuidTreeLookupAny searches uuid tree for a given uuid in specified field. +// It returns ErrNotFound if object was not found. +func uuidTreeLookupAny(f *os.File, uuid UUID, typ treeKeyType) (objectID, error) { + objId, off := uuid.toKey() + args := btrfs_ioctl_search_key{ + tree_id: uuidTreeObjectid, + min_objectid: objId, + max_objectid: objId, + min_type: typ, + max_type: typ, + min_offset: off, + max_offset: off, + max_transid: maxUint64, + nr_items: 1, + } + res, err := treeSearchRaw(f, args) + if err != nil { + return 0, err + } else if len(res) < 1 { + return 0, ErrNotFound + } + out := res[0] + if len(out.Data) != 8 { + return 0, fmt.Errorf("btrfs: uuid item with illegal size %d", len(out.Data)) + } + return objectID(binary.LittleEndian.Uint64(out.Data)), nil +} diff --git a/vendor/github.com/dennwc/btrfs/xattr.go b/vendor/github.com/dennwc/btrfs/xattr.go new file mode 100644 index 00000000..ae4b7d2a --- /dev/null +++ b/vendor/github.com/dennwc/btrfs/xattr.go @@ -0,0 +1,66 @@ +package btrfs + +import ( + "bytes" + "os" + "syscall" +) + +const ( + xattrPrefix = "btrfs." + xattrCompression = xattrPrefix + "compression" +) + +type Compression string + +const ( + CompressionNone = Compression("") + LZO = Compression("lzo") + ZLIB = Compression("zlib") +) + +func SetCompression(path string, v Compression) error { + var value []byte + if v != CompressionNone { + var err error + value, err = syscall.ByteSliceFromString(string(v)) + if err != nil { + return err + } + } + err := syscall.Setxattr(path, xattrCompression, value, 0) + if err != nil { + return &os.PathError{Op: "setxattr", Path: path, Err: err} + } + return nil +} + +func GetCompression(path string) (Compression, error) { + var buf []byte + for { + sz, err := syscall.Getxattr(path, xattrCompression, nil) + if err == syscall.ENODATA || sz == 0 { + return CompressionNone, nil + } else if err != nil { + return CompressionNone, &os.PathError{Op: "getxattr", Path: path, Err: err} + } + if cap(buf) < sz { + buf = make([]byte, sz) + } else { + buf = buf[:sz] + } + sz, err = syscall.Getxattr(path, xattrCompression, buf) + if err == syscall.ENODATA { + return CompressionNone, nil + } else if err == syscall.ERANGE { + // xattr changed by someone else, and is larger than our current buffer + continue + } else if err != nil { + return CompressionNone, &os.PathError{Op: "getxattr", Path: path, Err: err} + } + buf = buf[:sz] + break + } + buf = bytes.TrimSuffix(buf, []byte{0}) + return Compression(buf), nil +} diff --git a/vendor/github.com/dennwc/ioctl/ioctl.go b/vendor/github.com/dennwc/ioctl/ioctl.go new file mode 100644 index 00000000..9f851fb0 --- /dev/null +++ b/vendor/github.com/dennwc/ioctl/ioctl.go @@ -0,0 +1,82 @@ +package ioctl + +import ( + "fmt" + "os" + "reflect" + "syscall" +) + +const ( + nrBits = 8 + typeBits = 8 + sizeBits = 14 + dirBits = 2 +) + +const ( + nrMask = (1 << nrBits) - 1 + typeMask = (1 << typeBits) - 1 + sizeMask = (1 << sizeBits) - 1 + dirMask = (1 << dirBits) - 1 +) + +const ( + nrShift = 0 + typeShift = nrShift + nrBits + sizeShift = typeShift + typeBits + dirShift = sizeShift + sizeBits +) + +const ( + None = 0 + Write = 1 + Read = 2 +) + +func IOC(dir, typ, nr, size uintptr) uintptr { + return (dir << dirShift) | + (typ << typeShift) | + (nr << nrShift) | + (size << sizeShift) +} + +func IO(typ, nr uintptr) uintptr { + return IOC(None, typ, nr, 0) +} + +func IOR(typ, nr, size uintptr) uintptr { + return IOC(Read, typ, nr, size) +} + +func IOW(typ, nr, size uintptr) uintptr { + return IOC(Write, typ, nr, size) +} + +func IOWR(typ, nr, size uintptr) uintptr { + return IOC(Read|Write, typ, nr, size) +} + +func Ioctl(f *os.File, ioc uintptr, addr uintptr) error { + _, _, e := syscall.Syscall(syscall.SYS_IOCTL, f.Fd(), ioc, addr) + if e != 0 { + return e + } + return nil +} + +func Do(f *os.File, ioc uintptr, arg interface{}) error { + var addr uintptr + if arg != nil { + v := reflect.ValueOf(arg) + switch v.Kind() { + case reflect.Ptr: + addr = v.Elem().UnsafeAddr() + case reflect.Slice: + addr = v.Index(0).UnsafeAddr() + default: + return fmt.Errorf("expected ptr or slice, got %T", arg) + } + } + return Ioctl(f, ioc, addr) +} diff --git a/vendor/github.com/ema/qdisc/Makefile b/vendor/github.com/ema/qdisc/Makefile index b313b082..0bb1422e 100644 --- a/vendor/github.com/ema/qdisc/Makefile +++ b/vendor/github.com/ema/qdisc/Makefile @@ -2,7 +2,7 @@ build: go fmt go build go vet - staticcheck + #staticcheck #golint -set_exit_status go test -v -race -tags=integration diff --git a/vendor/github.com/ema/qdisc/README.md b/vendor/github.com/ema/qdisc/README.md index 9fe5dde5..08de2506 100644 --- a/vendor/github.com/ema/qdisc/README.md +++ b/vendor/github.com/ema/qdisc/README.md @@ -1,7 +1,7 @@ -qdisc [![Build Status](https://travis-ci.org/ema/qdisc.svg?branch=master)](https://travis-ci.org/ema/qdisc) +qdisc [![Build Status](https://github.com/ema/qdisc/actions/workflows/makefile.yml/badge.svg)](https://github.com/ema/qdisc/actions/) ===== -Package `qdisc` allows to get queuing discipline information via netlink, +Package `qdisc` allows getting queuing discipline information via netlink, similarly to what `tc -s qdisc show` does. Example usage diff --git a/vendor/github.com/ema/qdisc/get.go b/vendor/github.com/ema/qdisc/get.go index 9191594b..c467fd76 100644 --- a/vendor/github.com/ema/qdisc/get.go +++ b/vendor/github.com/ema/qdisc/get.go @@ -1,9 +1,11 @@ package qdisc import ( + "errors" "fmt" "math" "net" + "syscall" "github.com/mdlayher/netlink" "github.com/mdlayher/netlink/nlenc" @@ -86,6 +88,8 @@ type QdiscInfo struct { GcFlows uint64 Throttled uint64 FlowsPlimit uint64 + Qlen uint32 + Backlog uint32 } func parseTCAStats(attr netlink.Attribute) TC_Stats { @@ -173,7 +177,7 @@ func getQdiscMsgs(c *netlink.Conn) ([]netlink.Message, error) { } // See https://tools.ietf.org/html/rfc3549#section-3.1.3 -func parseMessage(msg netlink.Message) (QdiscInfo, error) { +func parseMessage(msg netlink.Message, ifaceNamesByID map[int]string) (QdiscInfo, error) { var m QdiscInfo var s TC_Stats var s2 TC_Stats2 @@ -237,6 +241,8 @@ func parseMessage(msg netlink.Message) (QdiscInfo, error) { // requeues only available in TCA_STATS2, not in TCA_STATS m.Requeues = s2.Requeues m.Overlimits = s2.Overlimits + m.Qlen = s2.Qlen + m.Backlog = s2.Backlog case TCA_STATS: // Legacy s = parseTCAStats(attr) @@ -244,18 +250,30 @@ func parseMessage(msg netlink.Message) (QdiscInfo, error) { m.Packets = s.Packets m.Drops = s.Drops m.Overlimits = s.Overlimits + m.Qlen = s.Qlen + m.Backlog = s.Backlog default: // TODO: TCA_OPTIONS and TCA_XSTATS } } - iface, err := net.InterfaceByIndex(int(ifaceIdx)) + m.IfaceName = ifaceNamesByID[int(ifaceIdx)] - if err == nil { - m.IfaceName = iface.Name + return m, err +} + +func getInterfaceNames() (map[int]string, error) { + ifas, err := net.Interfaces() + if err != nil { + return nil, err } - return m, err + ifNamesByID := make(map[int]string) + for _, ifa := range ifas { + ifNamesByID[ifa.Index] = ifa.Name + } + + return ifNamesByID, nil } func getAndParse(c *netlink.Conn) ([]QdiscInfo, error) { @@ -267,8 +285,13 @@ func getAndParse(c *netlink.Conn) ([]QdiscInfo, error) { return nil, err } + ifNamesByID, err := getInterfaceNames() + if err != nil { + return nil, err + } + for _, msg := range msgs { - m, err := parseMessage(msg) + m, err := parseMessage(msg, ifNamesByID) if err != nil { return nil, err @@ -287,6 +310,14 @@ func Get() ([]QdiscInfo, error) { if err != nil { return nil, fmt.Errorf("failed to dial netlink: %v", err) } + + if err := c.SetOption(netlink.GetStrictCheck, true); err != nil { + // silently accept ENOPROTOOPT errors when kernel is not > 4.20 + if !errors.Is(err, syscall.ENOPROTOOPT) { + return nil, fmt.Errorf("unexpected error trying to set option NETLINK_GET_STRICT_CHK: %v", err) + } + } + defer c.Close() return getAndParse(c) diff --git a/vendor/github.com/go-kit/kit/log/README.md b/vendor/github.com/go-kit/kit/log/README.md index a201a3d9..5492dd94 100644 --- a/vendor/github.com/go-kit/kit/log/README.md +++ b/vendor/github.com/go-kit/kit/log/README.md @@ -1,5 +1,14 @@ # package log +**Deprecation notice:** The core Go kit log packages (log, log/level, log/term, and +log/syslog) have been moved to their own repository at github.com/go-kit/log. +The corresponding packages in this directory remain for backwards compatibility. +Their types alias the types and their functions call the functions provided by +the new repository. Using either import path should be equivalent. Prefer the +new import path when practical. + +______ + `package log` provides a minimal interface for structured logging in services. It may be wrapped to encode conventions, enforce type-safety, provide leveled logging, and so on. It can be used for both typical application log events, diff --git a/vendor/github.com/go-kit/kit/log/doc.go b/vendor/github.com/go-kit/kit/log/doc.go index 918c0af4..c9873f4b 100644 --- a/vendor/github.com/go-kit/kit/log/doc.go +++ b/vendor/github.com/go-kit/kit/log/doc.go @@ -1,5 +1,7 @@ // Package log provides a structured logger. // +// Deprecated: Use github.com/go-kit/log instead. +// // Structured logging produces logs easily consumed later by humans or // machines. Humans might be interested in debugging errors, or tracing // specific requests. Machines might be interested in counting interesting @@ -39,8 +41,8 @@ // // A contextual logger stores keyvals that it includes in all log events. // Building appropriate contextual loggers reduces repetition and aids -// consistency in the resulting log output. With and WithPrefix add context to -// a logger. We can use With to improve the RunTask example. +// consistency in the resulting log output. With, WithPrefix, and WithSuffix +// add context to a logger. We can use With to improve the RunTask example. // // func RunTask(task Task, logger log.Logger) string { // logger = log.With(logger, "taskID", task.ID) diff --git a/vendor/github.com/go-kit/kit/log/json_logger.go b/vendor/github.com/go-kit/kit/log/json_logger.go index 0cedbf82..edfde2f4 100644 --- a/vendor/github.com/go-kit/kit/log/json_logger.go +++ b/vendor/github.com/go-kit/kit/log/json_logger.go @@ -1,91 +1,15 @@ package log import ( - "encoding" - "encoding/json" - "fmt" "io" - "reflect" -) -type jsonLogger struct { - io.Writer -} + "github.com/go-kit/log" +) // NewJSONLogger returns a Logger that encodes keyvals to the Writer as a // single JSON object. Each log event produces no more than one call to // w.Write. The passed Writer must be safe for concurrent use by multiple // goroutines if the returned Logger will be used concurrently. func NewJSONLogger(w io.Writer) Logger { - return &jsonLogger{w} -} - -func (l *jsonLogger) Log(keyvals ...interface{}) error { - n := (len(keyvals) + 1) / 2 // +1 to handle case when len is odd - m := make(map[string]interface{}, n) - for i := 0; i < len(keyvals); i += 2 { - k := keyvals[i] - var v interface{} = ErrMissingValue - if i+1 < len(keyvals) { - v = keyvals[i+1] - } - merge(m, k, v) - } - enc := json.NewEncoder(l.Writer) - enc.SetEscapeHTML(false) - return enc.Encode(m) -} - -func merge(dst map[string]interface{}, k, v interface{}) { - var key string - switch x := k.(type) { - case string: - key = x - case fmt.Stringer: - key = safeString(x) - default: - key = fmt.Sprint(x) - } - - // We want json.Marshaler and encoding.TextMarshaller to take priority over - // err.Error() and v.String(). But json.Marshall (called later) does that by - // default so we force a no-op if it's one of those 2 case. - switch x := v.(type) { - case json.Marshaler: - case encoding.TextMarshaler: - case error: - v = safeError(x) - case fmt.Stringer: - v = safeString(x) - } - - dst[key] = v -} - -func safeString(str fmt.Stringer) (s string) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(str); v.Kind() == reflect.Ptr && v.IsNil() { - s = "NULL" - } else { - panic(panicVal) - } - } - }() - s = str.String() - return -} - -func safeError(err error) (s interface{}) { - defer func() { - if panicVal := recover(); panicVal != nil { - if v := reflect.ValueOf(err); v.Kind() == reflect.Ptr && v.IsNil() { - s = nil - } else { - panic(panicVal) - } - } - }() - s = err.Error() - return + return log.NewJSONLogger(w) } diff --git a/vendor/github.com/go-kit/kit/log/log.go b/vendor/github.com/go-kit/kit/log/log.go index 66a9e2fd..164a4f94 100644 --- a/vendor/github.com/go-kit/kit/log/log.go +++ b/vendor/github.com/go-kit/kit/log/log.go @@ -1,135 +1,51 @@ package log -import "errors" +import ( + "github.com/go-kit/log" +) // Logger is the fundamental interface for all log operations. Log creates a // log event from keyvals, a variadic sequence of alternating keys and values. // Implementations must be safe for concurrent use by multiple goroutines. In // particular, any implementation of Logger that appends to keyvals or // modifies or retains any of its elements must make a copy first. -type Logger interface { - Log(keyvals ...interface{}) error -} +type Logger = log.Logger // ErrMissingValue is appended to keyvals slices with odd length to substitute // the missing value. -var ErrMissingValue = errors.New("(MISSING)") +var ErrMissingValue = log.ErrMissingValue // With returns a new contextual logger with keyvals prepended to those passed -// to calls to Log. If logger is also a contextual logger created by With or -// WithPrefix, keyvals is appended to the existing context. +// to calls to Log. If logger is also a contextual logger created by With, +// WithPrefix, or WithSuffix, keyvals is appended to the existing context. // // The returned Logger replaces all value elements (odd indexes) containing a // Valuer with their generated value for each call to its Log method. func With(logger Logger, keyvals ...interface{}) Logger { - if len(keyvals) == 0 { - return logger - } - l := newContext(logger) - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - return &context{ - logger: l.logger, - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - keyvals: kvs[:len(kvs):len(kvs)], - hasValuer: l.hasValuer || containsValuer(keyvals), - } + return log.With(logger, keyvals...) } // WithPrefix returns a new contextual logger with keyvals prepended to those // passed to calls to Log. If logger is also a contextual logger created by -// With or WithPrefix, keyvals is prepended to the existing context. +// With, WithPrefix, or WithSuffix, keyvals is prepended to the existing context. // // The returned Logger replaces all value elements (odd indexes) containing a // Valuer with their generated value for each call to its Log method. func WithPrefix(logger Logger, keyvals ...interface{}) Logger { - if len(keyvals) == 0 { - return logger - } - l := newContext(logger) - // Limiting the capacity of the stored keyvals ensures that a new - // backing array is created if the slice must grow in Log or With. - // Using the extra capacity without copying risks a data race that - // would violate the Logger interface contract. - n := len(l.keyvals) + len(keyvals) - if len(keyvals)%2 != 0 { - n++ - } - kvs := make([]interface{}, 0, n) - kvs = append(kvs, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - kvs = append(kvs, l.keyvals...) - return &context{ - logger: l.logger, - keyvals: kvs, - hasValuer: l.hasValuer || containsValuer(keyvals), - } + return log.WithPrefix(logger, keyvals...) } -// context is the Logger implementation returned by With and WithPrefix. It -// wraps a Logger and holds keyvals that it includes in all log events. Its -// Log method calls bindValues to generate values for each Valuer in the -// context keyvals. -// -// A context must always have the same number of stack frames between calls to -// its Log method and the eventual binding of Valuers to their value. This -// requirement comes from the functional requirement to allow a context to -// resolve application call site information for a Caller stored in the -// context. To do this we must be able to predict the number of logging -// functions on the stack when bindValues is called. -// -// Two implementation details provide the needed stack depth consistency. +// WithSuffix returns a new contextual logger with keyvals appended to those +// passed to calls to Log. If logger is also a contextual logger created by +// With, WithPrefix, or WithSuffix, keyvals is appended to the existing context. // -// 1. newContext avoids introducing an additional layer when asked to -// wrap another context. -// 2. With and WithPrefix avoid introducing an additional layer by -// returning a newly constructed context with a merged keyvals rather -// than simply wrapping the existing context. -type context struct { - logger Logger - keyvals []interface{} - hasValuer bool -} - -func newContext(logger Logger) *context { - if c, ok := logger.(*context); ok { - return c - } - return &context{logger: logger} -} - -// Log replaces all value elements (odd indexes) containing a Valuer in the -// stored context with their generated value, appends keyvals, and passes the -// result to the wrapped Logger. -func (l *context) Log(keyvals ...interface{}) error { - kvs := append(l.keyvals, keyvals...) - if len(kvs)%2 != 0 { - kvs = append(kvs, ErrMissingValue) - } - if l.hasValuer { - // If no keyvals were appended above then we must copy l.keyvals so - // that future log events will reevaluate the stored Valuers. - if len(keyvals) == 0 { - kvs = append([]interface{}{}, l.keyvals...) - } - bindValues(kvs[:len(l.keyvals)]) - } - return l.logger.Log(kvs...) +// The returned Logger replaces all value elements (odd indexes) containing a +// Valuer with their generated value for each call to its Log method. +func WithSuffix(logger Logger, keyvals ...interface{}) Logger { + return log.WithSuffix(logger, keyvals...) } // LoggerFunc is an adapter to allow use of ordinary functions as Loggers. If // f is a function with the appropriate signature, LoggerFunc(f) is a Logger // object that calls f. -type LoggerFunc func(...interface{}) error - -// Log implements Logger by calling f(keyvals...). -func (f LoggerFunc) Log(keyvals ...interface{}) error { - return f(keyvals...) -} +type LoggerFunc = log.LoggerFunc diff --git a/vendor/github.com/go-kit/kit/log/logfmt_logger.go b/vendor/github.com/go-kit/kit/log/logfmt_logger.go index a0030529..51cde2c5 100644 --- a/vendor/github.com/go-kit/kit/log/logfmt_logger.go +++ b/vendor/github.com/go-kit/kit/log/logfmt_logger.go @@ -1,62 +1,15 @@ package log import ( - "bytes" "io" - "sync" - "github.com/go-logfmt/logfmt" + "github.com/go-kit/log" ) -type logfmtEncoder struct { - *logfmt.Encoder - buf bytes.Buffer -} - -func (l *logfmtEncoder) Reset() { - l.Encoder.Reset() - l.buf.Reset() -} - -var logfmtEncoderPool = sync.Pool{ - New: func() interface{} { - var enc logfmtEncoder - enc.Encoder = logfmt.NewEncoder(&enc.buf) - return &enc - }, -} - -type logfmtLogger struct { - w io.Writer -} - // NewLogfmtLogger returns a logger that encodes keyvals to the Writer in // logfmt format. Each log event produces no more than one call to w.Write. // The passed Writer must be safe for concurrent use by multiple goroutines if // the returned Logger will be used concurrently. func NewLogfmtLogger(w io.Writer) Logger { - return &logfmtLogger{w} -} - -func (l logfmtLogger) Log(keyvals ...interface{}) error { - enc := logfmtEncoderPool.Get().(*logfmtEncoder) - enc.Reset() - defer logfmtEncoderPool.Put(enc) - - if err := enc.EncodeKeyvals(keyvals...); err != nil { - return err - } - - // Add newline to the end of the buffer - if err := enc.EndRecord(); err != nil { - return err - } - - // The Logger interface requires implementations to be safe for concurrent - // use by multiple goroutines. For this implementation that means making - // only one call to l.w.Write() for each call to Log. - if _, err := l.w.Write(enc.buf.Bytes()); err != nil { - return err - } - return nil + return log.NewLogfmtLogger(w) } diff --git a/vendor/github.com/go-kit/kit/log/nop_logger.go b/vendor/github.com/go-kit/kit/log/nop_logger.go index 1047d626..b02c6860 100644 --- a/vendor/github.com/go-kit/kit/log/nop_logger.go +++ b/vendor/github.com/go-kit/kit/log/nop_logger.go @@ -1,8 +1,8 @@ package log -type nopLogger struct{} +import "github.com/go-kit/log" // NewNopLogger returns a logger that doesn't do anything. -func NewNopLogger() Logger { return nopLogger{} } - -func (nopLogger) Log(...interface{}) error { return nil } +func NewNopLogger() Logger { + return log.NewNopLogger() +} diff --git a/vendor/github.com/go-kit/kit/log/stdlib.go b/vendor/github.com/go-kit/kit/log/stdlib.go index ff96b5de..cb604a7a 100644 --- a/vendor/github.com/go-kit/kit/log/stdlib.go +++ b/vendor/github.com/go-kit/kit/log/stdlib.go @@ -2,9 +2,8 @@ package log import ( "io" - "log" - "regexp" - "strings" + + "github.com/go-kit/log" ) // StdlibWriter implements io.Writer by invoking the stdlib log.Print. It's @@ -13,104 +12,43 @@ import ( // // If you have any choice in the matter, you shouldn't use this. Prefer to // redirect the stdlib log to the Go kit logger via NewStdlibAdapter. -type StdlibWriter struct{} - -// Write implements io.Writer. -func (w StdlibWriter) Write(p []byte) (int, error) { - log.Print(strings.TrimSpace(string(p))) - return len(p), nil -} +type StdlibWriter = log.StdlibWriter // StdlibAdapter wraps a Logger and allows it to be passed to the stdlib // logger's SetOutput. It will extract date/timestamps, filenames, and // messages, and place them under relevant keys. -type StdlibAdapter struct { - Logger - timestampKey string - fileKey string - messageKey string -} +type StdlibAdapter = log.StdlibAdapter // StdlibAdapterOption sets a parameter for the StdlibAdapter. -type StdlibAdapterOption func(*StdlibAdapter) +type StdlibAdapterOption = log.StdlibAdapterOption // TimestampKey sets the key for the timestamp field. By default, it's "ts". func TimestampKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.timestampKey = key } + return log.TimestampKey(key) } // FileKey sets the key for the file and line field. By default, it's "caller". func FileKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.fileKey = key } + return log.FileKey(key) } // MessageKey sets the key for the actual log message. By default, it's "msg". func MessageKey(key string) StdlibAdapterOption { - return func(a *StdlibAdapter) { a.messageKey = key } + return log.MessageKey(key) +} + +// Prefix configures the adapter to parse a prefix from stdlib log events. If +// you provide a non-empty prefix to the stdlib logger, then your should provide +// that same prefix to the adapter via this option. +// +// By default, the prefix isn't included in the msg key. Set joinPrefixToMsg to +// true if you want to include the parsed prefix in the msg. +func Prefix(prefix string, joinPrefixToMsg bool) StdlibAdapterOption { + return log.Prefix(prefix, joinPrefixToMsg) } // NewStdlibAdapter returns a new StdlibAdapter wrapper around the passed // logger. It's designed to be passed to log.SetOutput. func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { - a := StdlibAdapter{ - Logger: logger, - timestampKey: "ts", - fileKey: "caller", - messageKey: "msg", - } - for _, option := range options { - option(&a) - } - return a -} - -func (a StdlibAdapter) Write(p []byte) (int, error) { - result := subexps(p) - keyvals := []interface{}{} - var timestamp string - if date, ok := result["date"]; ok && date != "" { - timestamp = date - } - if time, ok := result["time"]; ok && time != "" { - if timestamp != "" { - timestamp += " " - } - timestamp += time - } - if timestamp != "" { - keyvals = append(keyvals, a.timestampKey, timestamp) - } - if file, ok := result["file"]; ok && file != "" { - keyvals = append(keyvals, a.fileKey, file) - } - if msg, ok := result["msg"]; ok { - keyvals = append(keyvals, a.messageKey, msg) - } - if err := a.Logger.Log(keyvals...); err != nil { - return 0, err - } - return len(p), nil -} - -const ( - logRegexpDate = `(?P[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` - logRegexpTime = `(?P