本文整理汇总了Golang中go4/org/jsonconfig.Obj.OptionalList方法的典型用法代码示例。如果您正苦于以下问题:Golang Obj.OptionalList方法的具体用法?Golang Obj.OptionalList怎么用?Golang Obj.OptionalList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go4/org/jsonconfig.Obj
的用法示例。
在下文中一共展示了Obj.OptionalList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: convertToMultiServers
// convertToMultiServers takes an old style single-server client configuration and maps it to new a multi-servers configuration that is returned.
func convertToMultiServers(conf jsonconfig.Obj) (jsonconfig.Obj, error) {
server := conf.OptionalString("server", "")
if server == "" {
return nil, errors.New("Could not convert config to multi-servers style: no \"server\" key found.")
}
newConf := jsonconfig.Obj{
"servers": map[string]interface{}{
"server": map[string]interface{}{
"auth": conf.OptionalString("auth", ""),
"default": true,
"server": server,
},
},
"identity": conf.OptionalString("identity", ""),
"identitySecretRing": conf.OptionalString("identitySecretRing", ""),
}
if ignoredFiles := conf.OptionalList("ignoredFiles"); ignoredFiles != nil {
var list []interface{}
for _, v := range ignoredFiles {
list = append(list, v)
}
newConf["ignoredFiles"] = list
}
return newConf, nil
}
示例2: thumbnailerFromConfig
func thumbnailerFromConfig(config jsonconfig.Obj) Thumbnailer {
command := config.OptionalList("command")
if len(command) < 1 {
return DefaultThumbnailer
}
return &configThumbnailer{prog: command[0], args: command[1:]}
}
示例3: newFromConfig
func newFromConfig(ld blobserver.Loader, config jsonconfig.Obj) (storage blobserver.Storage, err error) {
sto := &replicaStorage{
replicaPrefixes: config.RequiredList("backends"),
readPrefixes: config.OptionalList("readBackends"),
}
nReplicas := len(sto.replicaPrefixes)
sto.minWritesForSuccess = config.OptionalInt("minWritesForSuccess", nReplicas)
if err := config.Validate(); err != nil {
return nil, err
}
if nReplicas == 0 {
return nil, errors.New("replica: need at least one replica")
}
if sto.minWritesForSuccess == 0 {
sto.minWritesForSuccess = nReplicas
}
// readPrefixes defaults to the write prefixes.
if len(sto.readPrefixes) == 0 {
sto.readPrefixes = sto.replicaPrefixes
}
for _, prefix := range sto.replicaPrefixes {
s, err := ld.GetStorage(prefix)
if err != nil {
// If it's not a storage interface, it might be an http Handler
// that also supports being a target (e.g. a sync handler).
h, _ := ld.GetHandler(prefix)
var ok bool
if s, ok = h.(blobserver.Storage); !ok {
return nil, err
}
}
sto.replicas = append(sto.replicas, s)
}
for _, prefix := range sto.readPrefixes {
s, err := ld.GetStorage(prefix)
if err != nil {
return nil, err
}
sto.readReplicas = append(sto.readReplicas, s)
}
return sto, nil
}