當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errors.New函數代碼示例

本文整理匯總了Golang中github.com/emccode/rexray/errors.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Init

func Init(id int32, cfg *module.ModuleConfig) (module.Module, error) {

	osdm, osdmErr := osm.NewOSDriverManager(cfg.Config)
	if osdmErr != nil {
		return nil, osdmErr
	}
	if len(osdm.Drivers) == 0 {
		return nil, errors.New("no os drivers initialized")
	}

	sdm, sdmErr := storage.NewStorageDriverManager(cfg.Config)
	if sdmErr != nil {
		return nil, sdmErr
	}
	if len(sdm.Drivers) == 0 {
		return nil, errors.New("no storage drivers initialized")
	}

	vdm, vdmErr := volume.NewVolumeDriverManager(cfg.Config, osdm, sdm)
	if vdmErr != nil {
		return nil, vdmErr
	}
	if len(vdm.Drivers) == 0 {
		return nil, errors.New("no volume drivers initialized")
	}

	return &Module{
		id:   id,
		vdm:  vdm,
		name: MOD_NAME,
		desc: MOD_DESC,
		addr: cfg.Address,
	}, nil
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:34,代碼來源:voldriver.go

示例2: NetworkName

// NetworkName will return relevant information about how a volume can be discovered on an OS
func (driver *Driver) NetworkName(volumeName, instanceID string) (string, error) {
	log.WithFields(log.Fields{
		"volumeName": volumeName,
		"instanceID": instanceID,
		"driverName": driver.Name()}).Info("returning network name")

	volumes, err := driver.sdm.GetVolume("", volumeName)
	if err != nil {
		return "", err
	}

	switch {
	case len(volumes) == 0:
		return "", errors.New("No volumes returned by name")
	case len(volumes) > 1:
		return "", errors.New("Multiple volumes returned by name")
	}

	volumeAttachment, err := driver.sdm.GetVolumeAttach(
		volumes[0].VolumeID, instanceID)
	if err != nil {
		return "", err
	}

	if len(volumeAttachment) == 0 {
		return "", errors.New("Volume not attached")
	}

	volumes, err = driver.sdm.GetVolume("", volumeName)
	if err != nil {
		return "", err
	}

	return volumes[0].NetworkName, nil
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:36,代碼來源:volume.go

示例3: Path

// Path returns the mounted path of the volume
func (driver *Driver) Path(volumeName, volumeID string) (string, error) {
	log.WithFields(log.Fields{
		"volumeName": volumeName,
		"volumeID":   volumeID,
		"driverName": driver.Name()}).Info("getting path to volume")
	if volumeName == "" && volumeID == "" {
		return "", errors.New("Missing volume name or ID")
	}

	instances, err := driver.sdm.GetInstance()
	if err != nil {
		return "", err
	}

	switch {
	case len(instances) == 0:
		return "", errors.New("No instances")
	case len(instances) > 1:
		return "", errors.New("Too many instances returned, limit the storagedrivers")
	}

	volumes, err := driver.sdm.GetVolume(volumeID, volumeName)
	if err != nil {
		return "", err
	}

	switch {
	case len(volumes) == 0:
		return "", errors.New("No volumes returned by name")
	case len(volumes) > 1:
		return "", errors.New("Multiple volumes returned by name")
	}

	volumeAttachment, err := driver.sdm.GetVolumeAttach(volumes[0].VolumeID, instances[0].InstanceID)
	if err != nil {
		return "", err
	}

	if len(volumeAttachment) == 0 {
		return "", nil
	}

	mounts, err := driver.osdm.GetMounts(volumeAttachment[0].DeviceName, "")
	if err != nil {
		return "", err
	}

	if len(mounts) == 0 {
		return "", nil
	}

	return mounts[0].Mountpoint, nil
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:54,代碼來源:volume.go

示例4: getLunMaps

func (driver *Driver) getLunMaps(initiatorName, volumeID string) (xtio.Refs, error) {
	if initiatorName == "" {
		return nil, errors.New("Missing initiatorName")
	}

	initiatorGroup, err := driver.Client.GetInitiatorGroup("", initiatorName)
	if err != nil {
		return nil, err
	}

	lunMaps, err := driver.Client.GetLunMaps()
	if err != nil {
		return nil, err
	}

	var refs xtio.Refs
	for _, ref := range lunMaps {

		idents := strings.Split(ref.Name, "_")
		if len(idents) < 3 {
			continue
		} else if strconv.Itoa(initiatorGroup.Index) == idents[1] && volumeID == idents[0] {
			refs = append(refs, ref)
		}
	}

	return refs, nil
}
開發者ID:robnolen,項目名稱:rexray,代碼行數:28,代碼來源:storage.go

示例5: getVolumeMountPath

func getVolumeMountPath(name string) (string, error) {
	if name == "" {
		return "", errors.New("Missing volume name")
	}

	return fmt.Sprintf("%s/%s", mountDirectoryPath, name), nil
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:7,代碼來源:volume.go

示例6: Remove

// Remove will remove a remote volume
func (driver *Driver) Remove(volumeName string) error {
	log.WithFields(log.Fields{
		"volumeName": volumeName,
		"driverName": driver.Name()}).Info("removing volume")

	if volumeName == "" {
		return errors.New("Missing volume name")
	}

	instances, err := driver.sdm.GetInstance()
	if err != nil {
		return err
	}

	switch {
	case len(instances) == 0:
		return errors.New("No instances")
	case len(instances) > 1:
		return errors.New("Too many instances returned, limit the storagedrivers")
	}

	volumes, err := driver.sdm.GetVolume("", volumeName)
	if err != nil {
		return err
	}

	switch {
	case len(volumes) == 0:
		return errors.New("No volumes returned by name")
	case len(volumes) > 1:
		return errors.New("Multiple volumes returned by name")
	}

	err = driver.Unmount("", volumes[0].VolumeID)
	if err != nil {
		return err
	}

	err = driver.sdm.RemoveVolume(volumes[0].VolumeID)
	if err != nil {
		return err
	}

	return nil
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:46,代碼來源:volume.go

示例7: Unmount

func (osdm *OSDriverManager) Unmount(mountPoint string) error {
	for _, driver := range osdm.Drivers {
		log.WithFields(log.Fields{
			"mountPoint": mountPoint,
			"driverName": driver.Name()}).Info("unmounting filesystem")
		return driver.Unmount(mountPoint)
	}
	return errors.New("No OS detected")
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:9,代碼來源:os.go

示例8: Mounted

func (osdm *OSDriverManager) Mounted(mountPoint string) (bool, error) {
	for _, driver := range osdm.Drivers {
		log.WithFields(log.Fields{
			"mountPoint": mountPoint,
			"driverName": driver.Name()}).Info("checking filesystem mount")
		return driver.Mounted(mountPoint)
	}
	return false, errors.New("No OS detected")
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:9,代碼來源:os.go

示例9: Format

func (osdm *OSDriverManager) Format(deviceName, fsType string, overwriteFs bool) error {
	for _, driver := range osdm.Drivers {
		log.WithFields(log.Fields{
			"deviceName":  deviceName,
			"fsType":      fsType,
			"overwriteFs": overwriteFs,
			"driverName":  driver.Name()}).Info("formatting if blank or overwriteFs specified")
		return driver.Format(deviceName, fsType, overwriteFs)
	}
	return errors.New("No OS detected")
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:11,代碼來源:os.go

示例10: Mount

func (osdm *OSDriverManager) Mount(device, target, mountOptions, mountLabel string) error {
	for _, driver := range osdm.Drivers {
		log.WithFields(log.Fields{
			"device":       device,
			"target":       target,
			"mountOptions": mountOptions,
			"mountLabel":   mountLabel,
			"driverName":   driver.Name()}).Info("mounting filesystem")
		return driver.Mount(device, target, mountOptions, mountLabel)
	}
	return errors.New("No OS detected")
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:12,代碼來源:os.go

示例11: GetMounts

func (osdm *OSDriverManager) GetMounts(deviceName, mountPoint string) ([]*mount.Info, error) {

	for _, driver := range osdm.Drivers {
		mounts, err := driver.GetMounts(deviceName, mountPoint)
		if err != nil {
			return nil, err
		}
		return mounts, nil
	}

	return nil, errors.New("No OS detected")
}
開發者ID:robnolen,項目名稱:rexray,代碼行數:12,代碼來源:os.go

示例12: NewOSDriverManager

func NewOSDriverManager(conf *config.Config) (*OSDriverManager, error) {

	drivers, err := getDrivers(conf)
	if err != nil {
		return nil, err
	}

	if len(drivers) == 0 {
		return nil, errors.New("no os drivers initialized")
	}

	return &OSDriverManager{drivers, conf}, nil
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:13,代碼來源:os.go

示例13: GetMounts

func (osdm *OSDriverManager) GetMounts(deviceName, mountPoint string) ([]*mount.Info, error) {

	for _, driver := range osdm.Drivers {
		log.WithFields(log.Fields{
			"deviceName": deviceName,
			"mountPoint": mountPoint,
			"driverName": driver.Name()}).Info("getting mounts")
		mounts, err := driver.GetMounts(deviceName, mountPoint)
		if err != nil {
			return nil, err
		}
		return mounts, nil
	}

	return nil, errors.New("No OS detected")
}
開發者ID:Oskoss,項目名稱:rexray,代碼行數:16,代碼來源:os.go

示例14: NewStorageDriverManager

func NewStorageDriverManager(conf *config.Config) (*StorageDriverManager, error) {

	sd, sdErr := getDrivers(conf)
	if sdErr != nil {
		return nil, sdErr
	}

	if len(sd) == 0 {
		return nil, errors.New("no storage drivers initialized")
	}

	return &StorageDriverManager{
		Drivers: sd,
		Config:  conf,
	}, nil
}
開發者ID:robnolen,項目名稱:rexray,代碼行數:16,代碼來源:storage.go

示例15: getIQN

func getIQN() (string, error) {
	data, err := ioutil.ReadFile("/etc/iscsi/initiatorname.iscsi")
	if err != nil {
		return "", err
	}

	result := string(data)
	lines := strings.Split(result, "\n")

	for _, line := range lines {
		split := strings.Split(line, "=")
		if split[0] == "InitiatorName" {
			return split[1], nil
		}
	}
	return "", errors.New("IQN not found")
}
開發者ID:robnolen,項目名稱:rexray,代碼行數:17,代碼來源:storage.go


注:本文中的github.com/emccode/rexray/errors.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。