Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Go 导入vault/builtin/credential/aws会将测试标志添加到命令行应用程序中_Go_Command Line Interface_Hashicorp Vault - Fatal编程技术网

Go 导入vault/builtin/credential/aws会将测试标志添加到命令行应用程序中

Go 导入vault/builtin/credential/aws会将测试标志添加到命令行应用程序中,go,command-line-interface,hashicorp-vault,Go,Command Line Interface,Hashicorp Vault,我正在创建一个快速而肮脏的Go应用程序,从Vault中提取应用程序机密,并使用Vault代码本身进行身份验证。作为其中的一部分,我将从github.com/hashicorp/vault/builtin/credential/aws导入aws凭证模块。这一切都很好 但是,当运行我的应用程序时,我注意到Go“testing”模块的命令行标志出现在标志中 可以通过编译和运行以下示例脚本来复制此脚本: package main import ( "flag" _ "github.co

我正在创建一个快速而肮脏的Go应用程序,从Vault中提取应用程序机密,并使用Vault代码本身进行身份验证。作为其中的一部分,我将从github.com/hashicorp/vault/builtin/credential/aws导入aws凭证模块。这一切都很好

但是,当运行我的应用程序时,我注意到Go“testing”模块的命令行标志出现在标志中

可以通过编译和运行以下示例脚本来复制此脚本:

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 ...]
我是一个新手,所以完全有可能我正在做一些我不应该在这里做的事情,但乍一看,将此模块导入命令行工具似乎是合理的

就我所见,模块中没有任何东西使用测试库(除了backend_test.go),因此我对这些标志是如何显示的有点困惑,特别是因为它们没有显示在Vault命令行界面本身中


是否可以在不包含这些标志的情况下导入和使用Vault的凭证/aws模块?或者在定义我自己的之前以某种方式清除测试标志?

这是因为即使您使用
来屏蔽
github.com/hashicorp/vault/builtin/credential/aws
,导入实际上还是发生了。以及导入的包
testing
,它生成所有这些标志

通过使用新的标志集,您可以摆脱
测试
标志

func main() {
    f:=flag.NewFlagSet("Your app name",flag.ExitOnError)
    f.StringVar(
        &myFlag, "myFlag", "", "Test flag",
    )
    f.Parse(os.Args)
    f.Usage()
}

游乐场:

抱歉,我可能不清楚,此脚本是为了演示问题,而不是我的实际代码。我需要使用aws模块,并且它是导入的,这是正确的,但是我不希望测试模块的标志出现在我的应用程序中。仅供参考,hashicorp喜欢在
testing.go
文件中定义测试帮助程序,而不是
\u test.go
文件,这样就可以导入帮助程序并供其他软件包使用。对于
aws
软件包,其一些非测试文件导入
框架
软件包,该软件包具有一个
测试.go
文件,该文件从std库导入
测试
软件包。所以,在使用hashicorp libs时,请准备好让测试标志污染您的标志空间。谢谢,很高兴知道这一点。看起来使用一个单独的标志空间是最好的选择。