本文整理汇总了Golang中github.com/openshift/geard/jobs.Response.SuccessWithData方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.SuccessWithData方法的具体用法?Golang Response.SuccessWithData怎么用?Golang Response.SuccessWithData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/openshift/geard/jobs.Response
的用法示例。
在下文中一共展示了Response.SuccessWithData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Execute
func (j *ListContainersRequest) Execute(resp jobs.Response) {
r := &ListContainersResponse{make(ContainerUnitResponses, 0)}
if err := unitsMatching(reContainerUnits, func(name string, unit *dbus.UnitStatus) {
if unit.LoadState == "not-found" || unit.LoadState == "masked" {
return
}
r.Containers = append(r.Containers, ContainerUnitResponse{
UnitResponse{
name,
unit.ActiveState,
unit.SubState,
},
unit.LoadState,
unit.JobType,
"",
})
}); err != nil {
log.Printf("list_units: Unable to list units from systemd: %v", err)
resp.Failure(ErrListContainersFailed)
return
}
r.Sort()
resp.SuccessWithData(jobs.ResponseOk, r)
}
示例2: Execute
func (j *ContainerPortsRequest) Execute(resp jobs.Response) {
portPairs, err := containers.GetExistingPorts(j.Id)
if err != nil {
log.Printf("job_container_ports_log: Unable to find unit: %s\n", err.Error())
resp.Failure(ErrContainerNotFound)
return
}
resp.SuccessWithData(jobs.ResponseAccepted, ContainerPortsResponse{portPairs})
}
示例3: Execute
func (j GetRoutesRequest) Execute(resp jobs.Response) {
// router.ReadRoutes()
var out string
if j.Frontend == "*" {
out = router.PrintRoutes()
} else {
out = router.PrintFrontendRoutes(j.Frontend)
}
fmt.Println(out)
resp.SuccessWithData(jobs.ResponseOk, &out)
// fmt.Fprintf(w, out)
}
示例4: ExecuteRemote
func (h *HttpTransport) ExecuteRemote(baseUrl *url.URL, job RemoteExecutable, res jobs.Response) error {
reader, writer := io.Pipe()
httpreq, errn := http.NewRequest(job.HttpMethod(), baseUrl.String(), reader)
if errn != nil {
return errn
}
id := job.MarshalRequestIdentifier()
if len(id) == 0 {
id = jobs.NewRequestIdentifier()
}
query := &url.Values{}
job.MarshalUrlQuery(query)
req := httpreq
req.Header.Set("X-Request-Id", id.String())
req.Header.Set("If-Match", "api="+ApiVersion())
req.Header.Set("Content-Type", "application/json")
//TODO: introduce API version per job
//TODO: content request signing for GETs
req.URL.Path = job.HttpPath()
req.URL.RawQuery = query.Encode()
go func() {
if err := job.MarshalHttpRequestBody(writer); err != nil {
log.Printf("http_remote: Error when writing to http: %v", err)
writer.CloseWithError(err)
} else {
writer.Close()
}
}()
resp, err := h.client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
isJson := resp.Header.Get("Content-Type") == "application/json"
switch code := resp.StatusCode; {
case code == 202:
if isJson {
return errors.New("Decoding of streaming JSON has not been implemented")
}
data, err := job.UnmarshalHttpResponse(resp.Header, nil, ResponseTable)
if err != nil {
return err
}
if pending, ok := data.(map[string]interface{}); ok {
for k := range pending {
res.WritePendingSuccess(k, pending[k])
}
}
w := res.SuccessWithWrite(jobs.ResponseOk, false, false)
if _, err := io.Copy(w, resp.Body); err != nil {
return err
}
case code == 204:
data, err := job.UnmarshalHttpResponse(resp.Header, nil, ResponseTable)
if err != nil {
return err
}
if pending, ok := data.(map[string]interface{}); ok {
for k := range pending {
res.WritePendingSuccess(k, pending[k])
}
}
res.Success(jobs.ResponseOk)
case code >= 200 && code < 300:
if !isJson {
return errors.New(fmt.Sprintf("remote: Response with %d status code had content type %s (should be application/json)", code, resp.Header.Get("Content-Type")))
}
data, err := job.UnmarshalHttpResponse(nil, resp.Body, ResponseJson)
if err != nil {
return err
}
res.SuccessWithData(jobs.ResponseOk, data)
default:
if isJson {
decoder := json.NewDecoder(resp.Body)
data := httpFailureResponse{}
if err := decoder.Decode(&data); err != nil {
return err
}
res.Failure(jobs.SimpleError{jobs.ResponseError, data.Message})
return nil
}
io.Copy(os.Stderr, resp.Body)
res.Failure(jobs.SimpleError{jobs.ResponseError, "Unable to decode response."})
}
return nil
}