本文整理汇总了Golang中github.com/juju/schema.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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")
}
示例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")
}
示例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 {
示例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{}
}
示例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(),
示例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
}
示例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(),