当前位置: 首页>>代码示例>>Golang>>正文


Golang api.ResponseOutput函数代码示例

本文整理汇总了Golang中github.com/rancher/convoy/api.ResponseOutput函数的典型用法代码示例。如果您正苦于以下问题:Golang ResponseOutput函数的具体用法?Golang ResponseOutput怎么用?Golang ResponseOutput使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ResponseOutput函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: doBackupInspect

func (s *daemon) doBackupInspect(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	s.GlobalLock.RLock()
	defer s.GlobalLock.RUnlock()

	request := &api.BackupListRequest{}
	if err := decodeRequest(r, request); err != nil {
		return err
	}
	request.URL = util.UnescapeURL(request.URL)
	backupOps, err := s.getBackupOpsForBackup(request.URL)
	if err != nil {
		return err
	}

	info, err := backupOps.GetBackupInfo(request.URL)
	if err != nil {
		return err
	}

	data, err := api.ResponseOutput(info)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:PaulCharlton,项目名称:convoy,代码行数:26,代码来源:objectstore.go

示例2: doBackupList

func (s *daemon) doBackupList(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	request := &api.BackupListRequest{}
	if err := decodeRequest(r, request); err != nil {
		return err
	}
	request.URL = util.UnescapeURL(request.URL)

	opts := map[string]string{
		OPT_VOLUME_NAME: request.VolumeName,
	}
	result := make(map[string]map[string]string)
	for _, driver := range s.ConvoyDrivers {
		backupOps, err := driver.BackupOps()
		if err != nil {
			// Not support backup ops
			continue
		}
		infos, err := backupOps.ListBackup(request.URL, opts)
		if err != nil {
			return err
		}
		for k, v := range infos {
			result[k] = v
		}
	}

	data, err := api.ResponseOutput(result)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:alwang1234,项目名称:convoy,代码行数:33,代码来源:objectstore.go

示例3: doBackupList

func (s *daemon) doBackupList(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	s.GlobalLock.RLock()
	defer s.GlobalLock.RUnlock()

	request := &api.BackupListRequest{}
	if err := decodeRequest(r, request); err != nil {
		return err
	}

	opts := map[string]string{
		convoydriver.OPT_VOLUME_UUID: request.VolumeUUID,
	}
	result := make(map[string]map[string]string)
	for _, driver := range s.ConvoyDrivers {
		backupOps, err := driver.BackupOps()
		if err != nil {
			// Not support backup ops
			continue
		}
		infos, err := backupOps.ListBackup(request.URL, opts)
		if err != nil {
			return err
		}
		for k, v := range infos {
			result[k] = v
		}
	}

	data, err := api.ResponseOutput(result)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:mehulsbhatt,项目名称:convoy,代码行数:35,代码来源:objectstore.go

示例4: writeResponseOutput

func writeResponseOutput(w http.ResponseWriter, v interface{}) error {
	output, err := api.ResponseOutput(v)
	if err != nil {
		return err
	}
	log.Debugln("Response: ", string(output))
	_, err = w.Write(output)
	return err
}
开发者ID:alwang1234,项目名称:convoy,代码行数:9,代码来源:common.go

示例5: doInfo

func (s *daemon) doInfo(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	s.GlobalLock.RLock()
	defer s.GlobalLock.RUnlock()

	var err error
	_, err = w.Write([]byte(fmt.Sprint("{\n\"General\": ")))
	if err != nil {
		return err
	}

	data, err := api.ResponseOutput(&s.daemonConfig)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	if err != nil {
		return err
	}
	for _, driver := range s.ConvoyDrivers {
		if _, err := w.Write([]byte(fmt.Sprintf(",\n\"%v\": ", driver.Name()))); err != nil {
			return err
		}

		info, err := driver.Info()
		if err != nil {
			return err
		}
		data, err = api.ResponseOutput(info)
		if err != nil {
			return err
		}
		_, err = w.Write(data)
		if err != nil {
			return err
		}
	}

	if _, err := w.Write([]byte(fmt.Sprint("\n}"))); err != nil {
		return err
	}

	return nil
}
开发者ID:PaulCharlton,项目名称:convoy,代码行数:43,代码来源:common.go

示例6: inspectVolume

func (s *daemon) inspectVolume(volumeUUID string) ([]byte, error) {
	volume := s.loadVolume(volumeUUID)
	if volume == nil {
		return nil, fmt.Errorf("Cannot find volume %v", volumeUUID)
	}
	resp, err := s.listVolumeInfo(volume)
	if err != nil {
		return nil, err
	}
	return api.ResponseOutput(*resp)
}
开发者ID:aruneli,项目名称:convoy,代码行数:11,代码来源:volume.go

示例7: sendResponse

func sendResponse(w http.ResponseWriter, v interface{}) error {
	resp, err := api.ResponseOutput(v)
	if err != nil {
		return err
	}
	_, err = w.Write(resp)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:alwang1234,项目名称:convoy,代码行数:11,代码来源:common.go

示例8: doSnapshotInspect

func (s *daemon) doSnapshotInspect(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	s.GlobalLock.RLock()
	defer s.GlobalLock.RUnlock()

	request := &api.SnapshotInspectRequest{}
	if err := decodeRequest(r, request); err != nil {
		return err
	}
	snapshotUUID := request.SnapshotUUID
	if err := util.CheckUUID(snapshotUUID); err != nil {
		return err
	}
	volumeUUID := s.SnapshotVolumeIndex.Get(snapshotUUID)
	if volumeUUID == "" {
		return fmt.Errorf("cannot find volume for snapshot %v", snapshotUUID)
	}

	volume := s.loadVolume(volumeUUID)
	if volume == nil {
		return fmt.Errorf("cannot find volume %v", volumeUUID)
	}
	if _, exists := volume.Snapshots[snapshotUUID]; !exists {
		return fmt.Errorf("cannot find snapshot %v of volume %v", snapshotUUID, volumeUUID)
	}

	driverInfo, err := s.getSnapshotDriverInfo(snapshotUUID, volume)
	if err != nil {
		return err
	}
	size, err := util.ParseSize(driverInfo[convoydriver.OPT_SIZE])
	if err != nil {
		return err
	}

	resp := api.SnapshotResponse{
		UUID:            snapshotUUID,
		VolumeUUID:      volume.UUID,
		VolumeName:      volume.Name,
		Size:            size,
		VolumeCreatedAt: volume.CreatedTime,
		Name:            volume.Snapshots[snapshotUUID].Name,
		CreatedTime:     volume.Snapshots[snapshotUUID].CreatedTime,
		DriverInfo:      driverInfo,
	}
	data, err := api.ResponseOutput(resp)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:mehulsbhatt,项目名称:convoy,代码行数:51,代码来源:snapshot.go

示例9: doSnapshotInspect

func (s *daemon) doSnapshotInspect(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	request := &api.SnapshotInspectRequest{}
	if err := decodeRequest(r, request); err != nil {
		return err
	}
	snapshotName := request.SnapshotName
	if err := util.CheckName(snapshotName); err != nil {
		return err
	}
	volumeName := s.SnapshotVolumeIndex.Get(snapshotName)
	if volumeName == "" {
		return fmt.Errorf("cannot find volume for snapshot %v", snapshotName)
	}

	volume := s.getVolume(volumeName)
	if volume == nil {
		return fmt.Errorf("cannot find volume %v", volumeName)
	}

	volumeDriverInfo, err := s.getVolumeDriverInfo(volume)
	if err != nil {
		return err
	}

	snapshot, err := s.getSnapshotDriverInfo(snapshotName, volume)
	if err != nil {
		return fmt.Errorf("cannot find snapshot %v of volume %v", snapshotName, volumeName)
	}

	driverInfo, err := s.getSnapshotDriverInfo(snapshotName, volume)
	if err != nil {
		return err
	}

	resp := api.SnapshotResponse{
		Name:            snapshotName,
		VolumeName:      volumeName,
		VolumeCreatedAt: volumeDriverInfo[OPT_VOLUME_CREATED_TIME],
		CreatedTime:     snapshot[OPT_SNAPSHOT_CREATED_TIME],
		DriverInfo:      driverInfo,
	}
	data, err := api.ResponseOutput(resp)
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:alwang1234,项目名称:convoy,代码行数:48,代码来源:snapshot.go

示例10: doVolumeList

func (s *daemon) doVolumeList(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	driverSpecific, err := util.GetFlag(r, "driver", false, nil)
	if err != nil {
		return err
	}

	var data []byte
	if driverSpecific == "1" {
		result := s.getVolumeList()
		data, err = api.ResponseOutput(&result)
	} else {
		data, err = s.listVolume()
	}
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:alwang1234,项目名称:convoy,代码行数:19,代码来源:volume.go

示例11: listVolume

func (s *daemon) listVolume() ([]byte, error) {
	resp := make(map[string]api.VolumeResponse)

	volumes := s.getVolumeList()

	for name := range volumes {
		volume := s.getVolume(name)
		if volume == nil {
			return nil, fmt.Errorf("Volume list changed for volume %v", name)
		}
		r, err := s.listVolumeInfo(volume)
		if err != nil {
			return nil, err
		}
		resp[name] = *r
	}

	return api.ResponseOutput(resp)
}
开发者ID:alwang1234,项目名称:convoy,代码行数:19,代码来源:volume.go

示例12: doBackupInspect

func doBackupInspect(c *cli.Context) error {
	var err error

	backupURL, err := util.GetFlag(c, "", true, err)
	if err != nil {
		return err
	}
	backupURL = util.UnescapeURL(backupURL)

	info, err := objectstore.GetBackupInfo(backupURL)
	if err != nil {
		return err
	}
	data, err := api.ResponseOutput(info)
	if err != nil {
		return err
	}
	fmt.Println(string(data))
	return nil
}
开发者ID:th3architect,项目名称:longhorn,代码行数:20,代码来源:main.go

示例13: listVolume

func (s *daemon) listVolume() ([]byte, error) {
	resp := make(map[string]api.VolumeResponse)

	volumeUUIDs, err := util.ListConfigIDs(s.Root, VOLUME_CFG_PREFIX, CFG_POSTFIX)
	if err != nil {
		return nil, err
	}

	for _, uuid := range volumeUUIDs {
		volume := s.loadVolume(uuid)
		if volume == nil {
			return nil, fmt.Errorf("Volume list changed for volume %v", uuid)
		}
		r, err := s.listVolumeInfo(volume)
		if err != nil {
			return nil, err
		}
		resp[uuid] = *r
	}

	return api.ResponseOutput(resp)
}
开发者ID:aruneli,项目名称:convoy,代码行数:22,代码来源:volume.go

示例14: doVolumeList

func (s *daemon) doVolumeList(version string, w http.ResponseWriter, r *http.Request, objs map[string]string) error {
	s.GlobalLock.RLock()
	defer s.GlobalLock.RUnlock()

	driverSpecific, err := util.GetLowerCaseFlag(r, "driver", false, nil)
	if err != nil {
		return err
	}

	var data []byte
	if driverSpecific == "1" {
		result := make(map[string]map[string]string)
		for _, driver := range s.ConvoyDrivers {
			volOps, err := driver.VolumeOps()
			if err != nil {
				break
			}
			volumes, err := volOps.ListVolume(map[string]string{})
			if err != nil {
				break
			}
			for k, v := range volumes {
				v["Driver"] = driver.Name()
				result[k] = v
			}
		}
		data, err = api.ResponseOutput(&result)
	} else {
		data, err = s.listVolume()
	}
	if err != nil {
		return err
	}
	_, err = w.Write(data)
	return err
}
开发者ID:aruneli,项目名称:convoy,代码行数:36,代码来源:volume.go


注:本文中的github.com/rancher/convoy/api.ResponseOutput函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。