• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang schema.Bool函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: importLinkLayerDeviceV1

func importLinkLayerDeviceV1(source map[string]interface{}) (*linklayerdevice, error) {
	fields := schema.Fields{
		"provider-id":  schema.String(),
		"machine-id":   schema.String(),
		"name":         schema.String(),
		"mtu":          schema.Int(),
		"type":         schema.String(),
		"mac-address":  schema.String(),
		"is-autostart": schema.Bool(),
		"is-up":        schema.Bool(),
		"parent-name":  schema.String(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"provider-id": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "linklayerdevice v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	return &linklayerdevice{
		ProviderID_:  valid["provider-id"].(string),
		MachineID_:   valid["machine-id"].(string),
		Name_:        valid["name"].(string),
		MTU_:         uint(valid["mtu"].(int64)),
		Type_:        valid["type"].(string),
		MACAddress_:  valid["mac-address"].(string),
		IsAutoStart_: valid["is-autostart"].(bool),
		IsUp_:        valid["is-up"].(bool),
		ParentName_:  valid["parent-name"].(string),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:35,代码来源:linklayerdevice.go


示例2: importFilesystemAttachmentV1

func importFilesystemAttachmentV1(source map[string]interface{}) (*filesystemAttachment, error) {
	fields := schema.Fields{
		"machine-id":  schema.String(),
		"provisioned": schema.Bool(),
		"read-only":   schema.Bool(),
		"mount-point": schema.String(),
	}
	defaults := schema.Defaults{
		"mount-point": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "filesystemAttachment v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &filesystemAttachment{
		MachineID_:   valid["machine-id"].(string),
		Provisioned_: valid["provisioned"].(bool),
		ReadOnly_:    valid["read-only"].(bool),
		MountPoint_:  valid["mount-point"].(string),
	}
	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:28,代码来源:filesystem.go


示例3: importVolumeAttachmentV1

func importVolumeAttachmentV1(source map[string]interface{}) (*volumeAttachment, error) {
	fields := schema.Fields{
		"machine-id":  schema.String(),
		"provisioned": schema.Bool(),
		"read-only":   schema.Bool(),
		"device-name": schema.String(),
		"device-link": schema.String(),
		"bus-address": schema.String(),
	}
	checker := schema.FieldMap(fields, nil) // no defaults

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "volumeAttachment v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &volumeAttachment{
		MachineID_:   valid["machine-id"].(string),
		Provisioned_: valid["provisioned"].(bool),
		ReadOnly_:    valid["read-only"].(bool),
		DeviceName_:  valid["device-name"].(string),
		DeviceLink_:  valid["device-link"].(string),
		BusAddress_:  valid["bus-address"].(string),
	}
	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:29,代码来源:volume.go


示例4: importSpaceV1

func importSpaceV1(source map[string]interface{}) (*space, error) {
	fields := schema.Fields{
		"name":        schema.String(),
		"public":      schema.Bool(),
		"provider-id": schema.String(),
	}
	// Some values don't have to be there.
	defaults := schema.Defaults{
		"provider-id": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "space v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	return &space{
		Name_:       valid["name"].(string),
		Public_:     valid["public"].(bool),
		ProviderID_: valid["provider-id"].(string),
	}, nil
}
开发者ID:bac,项目名称:juju,代码行数:26,代码来源:space.go


示例5: importBlockDeviceV1

func importBlockDeviceV1(source map[string]interface{}) (*blockdevice, error) {
	fields := schema.Fields{
		"name":        schema.String(),
		"links":       schema.List(schema.String()),
		"label":       schema.String(),
		"uuid":        schema.String(),
		"hardware-id": schema.String(),
		"bus-address": schema.String(),
		"size":        schema.ForceUint(),
		"fs-type":     schema.String(),
		"in-use":      schema.Bool(),
		"mount-point": schema.String(),
	}

	defaults := schema.Defaults{
		"links":       schema.Omit,
		"label":       "",
		"uuid":        "",
		"hardware-id": "",
		"bus-address": "",
		"fs-type":     "",
		"mount-point": "",
	}
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "block device v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.
	result := &blockdevice{
		Name_:           valid["name"].(string),
		Links_:          convertToStringSlice(valid["links"]),
		Label_:          valid["label"].(string),
		UUID_:           valid["uuid"].(string),
		HardwareID_:     valid["hardware-id"].(string),
		BusAddress_:     valid["bus-address"].(string),
		Size_:           valid["size"].(uint64),
		FilesystemType_: valid["fs-type"].(string),
		InUse_:          valid["in-use"].(bool),
		MountPoint_:     valid["mount-point"].(string),
	}

	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:47,代码来源:blockdevice.go


示例6: importUserV1

func importUserV1(source map[string]interface{}) (*user, error) {
	fields := schema.Fields{
		"name":            schema.String(),
		"display-name":    schema.String(),
		"created-by":      schema.String(),
		"read-only":       schema.Bool(),
		"date-created":    schema.Time(),
		"last-connection": schema.Time(),
		"access":          schema.String(),
	}

	// Some values don't have to be there.
	defaults := schema.Defaults{
		"display-name":    "",
		"last-connection": time.Time{},
		"read-only":       false,
	}
	checker := schema.FieldMap(fields, defaults)
	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "user v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &user{
		Name_:        valid["name"].(string),
		DisplayName_: valid["display-name"].(string),
		CreatedBy_:   valid["created-by"].(string),
		DateCreated_: valid["date-created"].(time.Time),
		Access_:      valid["access"].(string),
	}

	lastConn := valid["last-connection"].(time.Time)
	if !lastConn.IsZero() {
		result.LastConnection_ = &lastConn
	}

	return result, nil

}
开发者ID:bac,项目名称:juju,代码行数:42,代码来源:user.go


示例7: vlan_2_0

func vlan_2_0(source map[string]interface{}) (*vlan, error) {
	fields := schema.Fields{
		"id":           schema.ForceInt(),
		"resource_uri": schema.String(),
		"name":         schema.OneOf(schema.Nil(""), schema.String()),
		"fabric":       schema.String(),
		"vid":          schema.ForceInt(),
		"mtu":          schema.ForceInt(),
		"dhcp_on":      schema.Bool(),
		// racks are not always set.
		"primary_rack":   schema.OneOf(schema.Nil(""), schema.String()),
		"secondary_rack": schema.OneOf(schema.Nil(""), schema.String()),
	}
	checker := schema.FieldMap(fields, nil)
	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "vlan 2.0 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	// Since the primary and secondary racks are optional, we use the two
	// part cast assignment. If the case fails, then we get the default value
	// we care about, which is the empty string.
	primary_rack, _ := valid["primary_rack"].(string)
	secondary_rack, _ := valid["secondary_rack"].(string)
	name, _ := valid["name"].(string)

	result := &vlan{
		resourceURI:   valid["resource_uri"].(string),
		id:            valid["id"].(int),
		name:          name,
		fabric:        valid["fabric"].(string),
		vid:           valid["vid"].(int),
		mtu:           valid["mtu"].(int),
		dhcp:          valid["dhcp_on"].(bool),
		primaryRack:   primary_rack,
		secondaryRack: secondary_rack,
	}
	return result, nil
}
开发者ID:voidspace,项目名称:gomaasapi,代码行数:42,代码来源:vlan.go


示例8: importEndpointV1

func importEndpointV1(source map[string]interface{}) (*endpoint, error) {
	fields := schema.Fields{
		"service-name":  schema.String(),
		"name":          schema.String(),
		"role":          schema.String(),
		"interface":     schema.String(),
		"optional":      schema.Bool(),
		"limit":         schema.Int(),
		"scope":         schema.String(),
		"unit-settings": schema.StringMap(schema.StringMap(schema.Any())),
	}

	checker := schema.FieldMap(fields, nil) // No defaults.

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "endpoint v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.

	result := &endpoint{
		ServiceName_:  valid["service-name"].(string),
		Name_:         valid["name"].(string),
		Role_:         valid["role"].(string),
		Interface_:    valid["interface"].(string),
		Optional_:     valid["optional"].(bool),
		Limit_:        int(valid["limit"].(int64)),
		Scope_:        valid["scope"].(string),
		UnitSettings_: make(map[string]map[string]interface{}),
	}

	for unitname, settings := range valid["unit-settings"].(map[string]interface{}) {
		result.UnitSettings_[unitname] = settings.(map[string]interface{})
	}

	return result, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:39,代码来源:relation.go


示例9: TestBool

func (s *S) TestBool(c *gc.C) {
	s.sch = schema.Bool()

	for _, trueValue := range []interface{}{true, "1", "true", "True", "TRUE"} {
		out, err := s.sch.Coerce(trueValue, aPath)
		c.Assert(err, gc.IsNil)
		c.Assert(out, gc.Equals, true)
	}

	for _, falseValue := range []interface{}{false, "0", "false", "False", "FALSE"} {
		out, err := s.sch.Coerce(falseValue, aPath)
		c.Assert(err, gc.IsNil)
		c.Assert(out, gc.Equals, false)
	}

	out, err := s.sch.Coerce(42, aPath)
	c.Assert(out, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, `<path>: expected bool, got int\(42\)`)

	out, err = s.sch.Coerce(nil, aPath)
	c.Assert(out, gc.IsNil)
	c.Assert(err, gc.ErrorMatches, "<path>: expected bool, got nothing")
}
开发者ID:howbazaar,项目名称:schema,代码行数:23,代码来源:schema_test.go


示例10: prompt

func (f *PromptingFiller) prompt(name string, attr environschema.Attr) (interface{}, error) {
	prompter := f.Prompter
	if prompter == nil {
		prompter = DefaultPrompter
	}
	tries := f.MaxTries
	if tries == 0 {
		tries = 3
	}
	for i := 0; i < tries; i++ {
		val, err := prompter.Prompt(name, attr)
		if err != nil {
			return nil, errgo.Notef(err, "cannot get input")
		}
		switch attr.Type {
		case environschema.Tbool:
			b, err := schema.Bool().Coerce(val, nil)
			if err == nil {
				return b, nil
			}
		case environschema.Tint:
			i, err := schema.Int().Coerce(val, nil)
			if err == nil {
				return i, nil
			}
		case environschema.Tstring:
			i, err := schema.String().Coerce(val, nil)
			if err == nil {
				return i, nil
			}
		default:
			return nil, errgo.Newf("unsupported attribute type %q", attr.Type)
		}
	}
	return nil, errgo.New("too many invalid inputs")
}
开发者ID:cmars,项目名称:oo,代码行数:36,代码来源:form.go


示例11: newEnvironConfig

	"github.com/juju/schema"

	"github.com/juju/juju/environs/config"
)

const defaultStoragePort = 8040

var (
	configFields = schema.Fields{
		"bootstrap-host":    schema.String(),
		"bootstrap-user":    schema.String(),
		"storage-listen-ip": schema.String(),
		"storage-port":      schema.ForceInt(),
		"storage-auth-key":  schema.String(),
		"use-sshstorage":    schema.Bool(),
	}
	configDefaults = schema.Defaults{
		"bootstrap-user":    "",
		"storage-listen-ip": "",
		"storage-port":      defaultStoragePort,
		"use-sshstorage":    true,
	}
)

type environConfig struct {
	*config.Config
	attrs map[string]interface{}
}

func newEnvironConfig(config *config.Config, attrs map[string]interface{}) *environConfig {
开发者ID:jiasir,项目名称:juju,代码行数:30,代码来源:config.go


示例12:

	"io/ioutil"
	"os"

	"github.com/juju/schema"

	"github.com/juju/juju/environs/config"
)

var configFields = schema.Fields{
	"location":                    schema.String(),
	"management-subscription-id":  schema.String(),
	"management-certificate-path": schema.String(),
	"management-certificate":      schema.String(),
	"storage-account-name":        schema.String(),
	"force-image-name":            schema.String(),
	"availability-sets-enabled":   schema.Bool(),
}
var configDefaults = schema.Defaults{
	"location":                    "",
	"management-certificate":      "",
	"management-certificate-path": "",
	"force-image-name":            "",
	// availability-sets-enabled is set to Omit (equivalent
	// to false) for backwards compatibility.
	"availability-sets-enabled": schema.Omit,
}

type azureEnvironConfig struct {
	*config.Config
	attrs map[string]interface{}
}
开发者ID:Pankov404,项目名称:juju,代码行数:31,代码来源:config.go


示例13:

	}
	return New(NoDefaults, defined)
}

var fields = schema.Fields{
	"type":                      schema.String(),
	"name":                      schema.String(),
	"default-series":            schema.String(),
	"tools-metadata-url":        schema.String(),
	"image-metadata-url":        schema.String(),
	"image-stream":              schema.String(),
	"authorized-keys":           schema.String(),
	"authorized-keys-path":      schema.String(),
	"firewall-mode":             schema.String(),
	"agent-version":             schema.String(),
	"development":               schema.Bool(),
	"admin-secret":              schema.String(),
	"ca-cert":                   schema.String(),
	"ca-cert-path":              schema.String(),
	"ca-private-key":            schema.String(),
	"ca-private-key-path":       schema.String(),
	"ssl-hostname-verification": schema.Bool(),
	"state-port":                schema.ForceInt(),
	"api-port":                  schema.ForceInt(),
	"syslog-port":               schema.ForceInt(),
	"rsyslog-ca-cert":           schema.String(),
	"logging-config":            schema.String(),
	"charm-store-auth":          schema.String(),
	"provisioner-safe-mode":     schema.Bool(),
	"http-proxy":                schema.String(),
	"https-proxy":               schema.String(),
开发者ID:rogpeppe,项目名称:juju,代码行数:31,代码来源:config.go


示例14: importServiceV1

func importServiceV1(source map[string]interface{}) (*service, error) {
	fields := schema.Fields{
		"name":                schema.String(),
		"series":              schema.String(),
		"subordinate":         schema.Bool(),
		"charm-url":           schema.String(),
		"cs-channel":          schema.String(),
		"charm-mod-version":   schema.Int(),
		"force-charm":         schema.Bool(),
		"exposed":             schema.Bool(),
		"min-units":           schema.Int(),
		"status":              schema.StringMap(schema.Any()),
		"settings":            schema.StringMap(schema.Any()),
		"settings-refcount":   schema.Int(),
		"leader":              schema.String(),
		"leadership-settings": schema.StringMap(schema.Any()),
		"metrics-creds":       schema.String(),
		"units":               schema.StringMap(schema.Any()),
	}

	defaults := schema.Defaults{
		"subordinate":   false,
		"force-charm":   false,
		"exposed":       false,
		"min-units":     int64(0),
		"leader":        "",
		"metrics-creds": "",
	}
	addAnnotationSchema(fields, defaults)
	addConstraintsSchema(fields, defaults)
	addStatusHistorySchema(fields)
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "service v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.
	result := &service{
		Name_:                 valid["name"].(string),
		Series_:               valid["series"].(string),
		Subordinate_:          valid["subordinate"].(bool),
		CharmURL_:             valid["charm-url"].(string),
		Channel_:              valid["cs-channel"].(string),
		CharmModifiedVersion_: int(valid["charm-mod-version"].(int64)),
		ForceCharm_:           valid["force-charm"].(bool),
		Exposed_:              valid["exposed"].(bool),
		MinUnits_:             int(valid["min-units"].(int64)),
		Settings_:             valid["settings"].(map[string]interface{}),
		SettingsRefCount_:     int(valid["settings-refcount"].(int64)),
		Leader_:               valid["leader"].(string),
		LeadershipSettings_:   valid["leadership-settings"].(map[string]interface{}),
		StatusHistory_:        newStatusHistory(),
	}
	result.importAnnotations(valid)
	if err := result.importStatusHistory(valid); err != nil {
		return nil, errors.Trace(err)
	}

	if constraintsMap, ok := valid["constraints"]; ok {
		constraints, err := importConstraints(constraintsMap.(map[string]interface{}))
		if err != nil {
			return nil, errors.Trace(err)
		}
		result.Constraints_ = constraints
	}

	encodedCreds := valid["metrics-creds"].(string)
	// The model stores the creds encoded, but we want to make sure that
	// we are storing something that can be decoded.
	if _, err := base64.StdEncoding.DecodeString(encodedCreds); err != nil {
		return nil, errors.Annotate(err, "metrics credentials not valid")
	}
	result.MetricsCredentials_ = encodedCreds

	status, err := importStatus(valid["status"].(map[string]interface{}))
	if err != nil {
		return nil, errors.Trace(err)
	}
	result.Status_ = status

	units, err := importUnits(valid["units"].(map[string]interface{}))
	if err != nil {
		return nil, errors.Trace(err)
	}
	result.setUnits(units)

	return result, nil
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:91,代码来源:service.go


示例15:

	return New(NoDefaults, defined)
}

var fields = schema.Fields{
	"type":                       schema.String(),
	"name":                       schema.String(),
	"uuid":                       schema.UUID(),
	"default-series":             schema.String(),
	"tools-metadata-url":         schema.String(),
	"image-metadata-url":         schema.String(),
	"image-stream":               schema.String(),
	"authorized-keys":            schema.String(),
	"authorized-keys-path":       schema.String(),
	"firewall-mode":              schema.String(),
	"agent-version":              schema.String(),
	"development":                schema.Bool(),
	"admin-secret":               schema.String(),
	"ca-cert":                    schema.String(),
	"ca-cert-path":               schema.String(),
	"ca-private-key":             schema.String(),
	"ca-private-key-path":        schema.String(),
	"ssl-hostname-verification":  schema.Bool(),
	"state-port":                 schema.ForceInt(),
	"api-port":                   schema.ForceInt(),
	"syslog-port":                schema.ForceInt(),
	"rsyslog-ca-cert":            schema.String(),
	"logging-config":             schema.String(),
	"charm-store-auth":           schema.String(),
	"provisioner-safe-mode":      schema.Bool(),
	"http-proxy":                 schema.String(),
	"https-proxy":                schema.String(),
开发者ID:kapilt,项目名称:juju,代码行数:31,代码来源:config.go


示例16:

	"launchpad.net/goose/identity"

	"github.com/juju/juju/environs/config"
)

var configFields = schema.Fields{
	"username":             schema.String(),
	"password":             schema.String(),
	"tenant-name":          schema.String(),
	"auth-url":             schema.String(),
	"auth-mode":            schema.String(),
	"access-key":           schema.String(),
	"secret-key":           schema.String(),
	"region":               schema.String(),
	"control-bucket":       schema.String(),
	"use-floating-ip":      schema.Bool(),
	"use-default-secgroup": schema.Bool(),
	"network":              schema.String(),
}
var configDefaults = schema.Defaults{
	"username":             "",
	"password":             "",
	"tenant-name":          "",
	"auth-url":             "",
	"auth-mode":            string(AuthUserPass),
	"access-key":           "",
	"secret-key":           "",
	"region":               "",
	"control-bucket":       "",
	"use-floating-ip":      false,
	"use-default-secgroup": false,
开发者ID:jiasir,项目名称:juju,代码行数:31,代码来源:config.go


示例17: importVolumeV1

func importVolumeV1(source map[string]interface{}) (*volume, error) {
	fields := schema.Fields{
		"id":          schema.String(),
		"storage-id":  schema.String(),
		"binding":     schema.String(),
		"provisioned": schema.Bool(),
		"size":        schema.ForceUint(),
		"pool":        schema.String(),
		"hardware-id": schema.String(),
		"volume-id":   schema.String(),
		"persistent":  schema.Bool(),
		"status":      schema.StringMap(schema.Any()),
		"attachments": schema.StringMap(schema.Any()),
	}

	defaults := schema.Defaults{
		"storage-id":  "",
		"binding":     "",
		"pool":        "",
		"hardware-id": "",
		"volume-id":   "",
		"attachments": schema.Omit,
	}
	addStatusHistorySchema(fields)
	checker := schema.FieldMap(fields, defaults)

	coerced, err := checker.Coerce(source, nil)
	if err != nil {
		return nil, errors.Annotatef(err, "volume v1 schema check failed")
	}
	valid := coerced.(map[string]interface{})
	// From here we know that the map returned from the schema coercion
	// contains fields of the right type.
	result := &volume{
		ID_:            valid["id"].(string),
		StorageID_:     valid["storage-id"].(string),
		Binding_:       valid["binding"].(string),
		Provisioned_:   valid["provisioned"].(bool),
		Size_:          valid["size"].(uint64),
		Pool_:          valid["pool"].(string),
		HardwareID_:    valid["hardware-id"].(string),
		VolumeID_:      valid["volume-id"].(string),
		Persistent_:    valid["persistent"].(bool),
		StatusHistory_: newStatusHistory(),
	}
	if err := result.importStatusHistory(valid); err != nil {
		return nil, errors.Trace(err)
	}

	status, err := importStatus(valid["status"].(map[string]interface{}))
	if err != nil {
		return nil, errors.Trace(err)
	}
	result.Status_ = status

	attachments, err := importVolumeAttachments(valid["attachments"].(map[string]interface{}))
	if err != nil {
		return nil, errors.Trace(err)
	}
	result.setAttachments(attachments)

	return result, nil
}
开发者ID:bac,项目名称:juju,代码行数:63,代码来源:volume.go


示例18:

)

// FieldType describes the type of an attribute value.
type FieldType string

// The following constants are the possible type values.
const (
	Tstring FieldType = "string"
	Tbool   FieldType = "bool"
	Tint    FieldType = "int"
	Tattrs  FieldType = "attrs"
)

var checkers = map[FieldType]schema.Checker{
	Tstring: schema.String(),
	Tbool:   schema.Bool(),
	Tint:    schema.ForceInt(),
	Tattrs:  attrsC{},
}

// Alternative possibilities to ValidationSchema to bear in mind for
// the future:
// func (s Fields) Checker() schema.Checker
// func (s Fields) Validate(value map[string]interface{}) (v map[string] interface{}, extra []string, err error)

// ValidationSchema returns values suitable for passing to
// schema.FieldMap to create a schema.Checker that will validate the given fields.
// It will return an error if the fields are invalid.
//
// The Defaults return value will contain entries for all non-mandatory
// attributes set to schema.Omit. It is the responsibility of the
开发者ID:cmars,项目名称:oo,代码行数:31,代码来源:fields.go


示例19:

// ebsProvider creates volume sources which use AWS EBS volumes.
type ebsProvider struct{}

var _ storage.Provider = (*ebsProvider)(nil)

var ebsConfigFields = schema.Fields{
	EBS_VolumeType: schema.OneOf(
		schema.Const(volumeTypeMagnetic),
		schema.Const(volumeTypeSsd),
		schema.Const(volumeTypeProvisionedIops),
		schema.Const(volumeTypeStandard),
		schema.Const(volumeTypeGp2),
		schema.Const(volumeTypeIo1),
	),
	EBS_IOPS:      schema.ForceInt(),
	EBS_Encrypted: schema.Bool(),
}

var ebsConfigChecker = schema.FieldMap(
	ebsConfigFields,
	schema.Defaults{
		EBS_VolumeType: volumeTypeMagnetic,
		EBS_IOPS:       schema.Omit,
		EBS_Encrypted:  false,
	},
)

type ebsConfig struct {
	volumeType string
	iops       int
	encrypted  bool
开发者ID:pmatulis,项目名称:juju,代码行数:31,代码来源:ebs.go


示例20: GenerateControllerCertAndKey

	if uuid, ok := c[ControllerUUIDKey].(string); ok && !utils.IsValidUUIDString(uuid) {
		return errors.Errorf("controller-uuid: expected UUID, got string(%q)", uuid)
	}

	return nil
}

// GenerateControllerCertAndKey makes sure that the config has a CACert and
// CAPrivateKey, generates and returns new certificate and key.
func GenerateControllerCertAndKey(caCert, caKey string, hostAddresses []string) (string, string, error) {
	return cert.NewDefaultServer(caCert, caKey, hostAddresses)
}

var configChecker = schema.FieldMap(schema.Fields{
	AuditingEnabled:         schema.Bool(),
	APIPort:                 schema.ForceInt(),
	StatePort:               schema.ForceInt(),
	IdentityURL:             schema.String(),
	IdentityPublicKey:       schema.String(),
	SetNUMAControlPolicyKey: schema.Bool(),
	AutocertURLKey:          schema.String(),
	AutocertDNSNameKey:      schema.String(),
	AllowModelAccessKey:     schema.Bool(),
}, schema.Defaults{
	APIPort:                 DefaultAPIPort,
	AuditingEnabled:         DefaultAuditingEnabled,
	StatePort:               DefaultStatePort,
	IdentityURL:             schema.Omit,
	IdentityPublicKey:       schema.Omit,
	SetNUMAControlPolicyKey: DefaultNUMAControlPolicy,
开发者ID:bac,项目名称:juju,代码行数:30,代码来源:config.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang schema.FieldMap函数代码示例发布时间:2022-05-23
下一篇:
Golang schema.Any函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap