本文整理汇总了Golang中mig/ninja/mig.ManifestParameters.AgentIdentifier方法的典型用法代码示例。如果您正苦于以下问题:Golang ManifestParameters.AgentIdentifier方法的具体用法?Golang ManifestParameters.AgentIdentifier怎么用?Golang ManifestParameters.AgentIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig/ninja/mig.ManifestParameters
的用法示例。
在下文中一共展示了ManifestParameters.AgentIdentifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: fetchFile
func fetchFile(n string) (ret []byte, err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("fetchFile() -> %v", e)
}
}()
murl := APIURL + "manifest/fetch/"
logInfo("fetching file from %v", murl)
mparam := mig.ManifestParameters{}
mparam.AgentIdentifier = ctx.AgentIdentifier
mparam.Object = n
buf, err := json.Marshal(mparam)
if err != nil {
panic(err)
}
mstring := string(buf)
data := url.Values{"parameters": {mstring}}
r, err := http.NewRequest("POST", murl, strings.NewReader(data.Encode()))
if err != nil {
panic(err)
}
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
r.Header.Add("X-LOADERKEY", ctx.LoaderKey)
client := http.Client{}
resp, err := client.Do(r)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var resource *cljs.Resource
err = json.Unmarshal(body, &resource)
if err != nil {
panic(err)
}
// Extract fetch response.
fetchresp, err := valueToFetchResponse(resource.Collection.Items[0].Data[0].Value)
if err != nil {
panic(err)
}
// Decompress the returned file and return it as a byte slice.
b := bytes.NewBuffer(fetchresp.Data)
gz, err := gzip.NewReader(b)
if err != nil {
panic(err)
}
ret, err = ioutil.ReadAll(gz)
if err != nil {
panic(err)
}
return
}
示例2: requestManifest
func requestManifest() (err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("requestManifest() -> %v", e)
}
}()
murl := APIURL + "manifest/agent/"
logInfo("requesting manifest from %v", murl)
mparam := mig.ManifestParameters{}
mparam.AgentIdentifier = ctx.AgentIdentifier
buf, err := json.Marshal(mparam)
if err != nil {
panic(err)
}
mstring := string(buf)
data := url.Values{"parameters": {mstring}}
r, err := http.NewRequest("POST", murl, strings.NewReader(data.Encode()))
if err != nil {
panic(err)
}
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
r.Header.Add("X-LOADERKEY", ctx.LoaderKey)
client := http.Client{}
resp, err := client.Do(r)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
var resource *cljs.Resource
err = json.Unmarshal(body, &resource)
if err != nil {
panic(err)
}
if resp.StatusCode != http.StatusOK {
err = fmt.Errorf("HTTP %v, API call failed with error '%v' (code %s)", resp.StatusCode,
resource.Collection.Error.Message, resource.Collection.Error.Code)
panic(err)
}
// Extract our manifest from the response.
manifest, err := valueToManifest(resource.Collection.Items[0].Data[0].Value)
if err != nil {
panic(err)
}
apiManifest = &manifest
err = apiManifest.Validate()
if err != nil {
panic(err)
}
return checkManifestSignature(apiManifest)
}