- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在创建一个快速而肮脏的 Go 应用程序,以从 Vault 中提取应用程序 secret ,并使用 Vault 代码本身进行身份验证。作为其中的一部分,我从 github.com/hashicorp/vault/builtin/credential/aws
导入 aws 凭证模块。这一切都运作良好。
但是,在运行我的应用程序时,我注意到来自 Go“测试”模块的命令行标志出现在标志中。
这可以通过编译和运行以下示例脚本来重现:
package main
import (
"flag"
_ "github.com/hashicorp/vault/builtin/credential/aws"
// Note: this import is masked only to make this demo script compile.
// In my actual code I need to use it, and it is not masked.
)
var myFlag string
func main() {
flag.StringVar(
&myFlag, "myFlag", "", "Test flag",
)
flag.Parse()
flag.Usage()
}
调用二进制文件时标志如下所示:
Usage of poc:
-myFlag string
Test flag
-test.bench regexp
run only benchmarks matching regexp
-test.benchmem
print memory allocations for benchmarks
-test.benchtime d
run each benchmark for duration d (default 1s)
-test.blockprofile file
write a goroutine blocking profile to file
-test.blockprofilerate rate
set blocking profile rate (see runtime.SetBlockProfileRate) (default 1)
-test.count n
run tests and benchmarks n times (default 1)
[... more flags from the go testing module ...]
我是 Go 的新手,所以我完全有可能正在做一些我不应该在这里做的事情,但乍一看,为命令行工具导入这个模块似乎是合理的。
据我所知,模块中没有任何内容使用测试库(除了 backend_test.go),所以我对这些标志的出现方式感到有点困惑,尤其是因为它们没有出现在Vault 命令行界面本身。
是否可以在不包含这些标志的情况下导入和使用 Vault 的凭证/aws 模块?或者在定义我自己的之前以某种方式清除测试标志?
最佳答案
那是因为即使您使用 _
来屏蔽 github.com/hashicorp/vault/builtin/credential/aws
,导入也确实发生了。并且该包导入了 testing
,它生成了所有这些标志。
您可以使用新的 FlagSet 摆脱 testing
标志。
func main() {
f:=flag.NewFlagSet("Your app name",flag.ExitOnError)
f.StringVar(
&myFlag, "myFlag", "", "Test flag",
)
f.Parse(os.Args)
f.Usage()
}
Playground :https://play.golang.org/p/O8ibPn77L46
关于go - 导入 vault/builtin/credential/aws 将测试标志添加到命令行应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48062633/
我收到以下警告,没有提及它发生的行: warning: integer overflows when converted from 'Builtin.Int32' to 'Builtin.Int8'
我不小心删除了我的一个 GAE 项目(用 Go 编写)中的 ah-builtin-datastoreservice 和 ah-builtin-python-bundle 这两个版本。这意味着我的自动备
使用 pig 将数据转换为日期时间时出现问题。导入以下数据集,制表符分隔,我添加了\t 来说明。 5000001 \t 1133938 \t 1273719 \t 2008-06-01 00:03:
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topi
我试图配置预提交挂接,在运行预提交运行--所有文件时,我收到以下错误:。我已尝试升级pip以解决此问题pip安装--升级pip,但我收到另一个错误:。我尝试检查PIP和PIP3的版本,但现在我也收到了
所以我正在阅读Hacking the Art of Exploitation,在书中,他们在 C 代码中使用了 strcpy() 函数: 1 #include 2 #include 3
为什么下面的代码会产生语法错误? >>> import builtins >>> dir(builtins) ['ArithmeticError', 'AssertionError', 'Attrib
我把这个想法放在了How to make a cross-module variable?在 python3 中。并且懒得使用变量 __builtins__ 而不是模块 builtins。这应该没有什
numpy 的 all 中出现这种怪异现象的原因是什么? >>> import numpy as np >>> np.all(xrange(10)) False >>> np.all(i for i
猫测试.go package main import "builtin" func main() { return } 去运行test.go can't find import: "built
我正在尝试使用 py2exe 将我的 .py 脚本转换为可执行文件。到目前为止,我遇到了许多问题,这些问题在很大程度上已通过下面安装文件中的“选项”得到解决。但是现在我遇到了一个我无法找到解决方案的问
我正在尝试使用原子实现旋转线程屏障,特别是 __sync_fetch_and_add。 https://gcc.gnu.org/onlinedocs/gcc-4.4.5/gcc/Atomic-Buil
在我的单元测试中,我在测试中有 2 个提示。我正在尝试使用 2 @patch("builtins.input") , 但它似乎只取返回值中的 1 个。 @patch("builtins.input")
我正在调试我的程序,然后发生了最后一行,我该如何解决?我使用 -fno-builtin 查看了 strcpy() 但它显示正在调用 __strcpy_sse2_unaligned。 root@19:~
This document说: Not all operations are supported by all target processors. 有人知道哪个处理器支持哪个操作吗? 最佳答案 不是
我刚刚开始使用 Rcpp。我有一个简单的程序,它接受两个数值 vector ,计算它们的并集并返回一个数值 vector 。该 list 粘贴在下方 (test.cpp)。 #include #in
在 python 3 中, >>> import keyword >>> keyword.kwlist 和 >>> import builtins >>> dir(builtins) 是两个不同的列表
昨天我的 Mac 决定将 Xcode 11 自动更新到 12,但是哎呀,我仍然需要 Xcode 11。所以我直接从 https://developer.apple.com/download/more/
在使用 Python 并行编程一书中的示例时,我在使用多处理队列的代码中遇到了以下错误: File "C:\pyDev\multiproc\queue-test.py", line 4, in
我正在尝试使用 HttpClient 在 Flutter 应用程序中执行 SSL 证书固定.我之前已经成功地在原生 Android 应用程序中执行了固定。这是我收到的错误消息: E/flutter (
我是一名优秀的程序员,十分优秀!