本文整理汇总了Golang中mig/client.Client.PostInvestigator方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.PostInvestigator方法的具体用法?Golang Client.PostInvestigator怎么用?Golang Client.PostInvestigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig/client.Client
的用法示例。
在下文中一共展示了Client.PostInvestigator方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: investigatorCreator
// investigatorCreator prompt the user for a name and the path to an armored
// public key and calls the API to create a new investigator
func investigatorCreator(cli client.Client) (err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("investigatorCreator() -> %v", e)
}
}()
var (
name string
pubkey []byte
)
fmt.Println("Entering investigator creation mode. Please provide the full name\n" +
"and the public key of the new investigator.")
name, err = readline.String("name> ")
if err != nil {
panic(err)
}
if len(name) < 3 {
panic("input name too short")
}
fmt.Printf("Name: '%s'\n", name)
fmt.Println("Please provide a public key. You can either provide a local path to the\n" +
"armored public key file, or a full length PGP fingerprint.\n" +
"example:\npubkey> 0x716CFA6BA8EBB21E860AE231645090E64367737B")
input, err := readline.String("pubkey> ")
if err != nil {
panic(err)
}
re := regexp.MustCompile(`^0x[ABCDEF0-9]{8,64}$`)
if re.MatchString(input) {
var keyserver string
if cli.Conf.GPG.Keyserver == "" {
keyserver = "http://gpg.mozilla.org"
}
fmt.Println("retrieving public key from", keyserver)
pubkey, err = pgp.GetArmoredKeyFromKeyServer(input, keyserver)
if err != nil {
panic(err)
}
} else {
fmt.Println("retrieving public key from", input)
pubkey, err = ioutil.ReadFile(input)
if err != nil {
panic(err)
}
}
fmt.Printf("%s\n", pubkey)
input, err = readline.String("create investigator? (y/n)> ")
if err != nil {
panic(err)
}
if input != "y" {
fmt.Println("abort")
return
}
inv, err := cli.PostInvestigator(name, pubkey)
if err != nil {
panic(err)
}
fmt.Printf("Investigator '%s' successfully created with ID %.0f\n",
inv.Name, inv.ID)
return
}