本文整理汇总了Golang中github.com/akutz/goof.WithField函数的典型用法代码示例。如果您正苦于以下问题:Golang WithField函数的具体用法?Golang WithField怎么用?Golang WithField使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WithField函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: createGetSnapshot
func (d *driver) createGetSnapshot(
volumeOpts core.VolumeOpts) (*core.Snapshot, error) {
var optSnapshotName string
var optSnapshotID string
optSnapshotName, _ = volumeOpts["snapshotname"]
optSnapshotID, _ = volumeOpts["snapshotid"]
if optSnapshotName == "" && optSnapshotID == "" {
return nil, nil
}
var err error
var snapshots []*core.Snapshot
if snapshots, err = d.r.Storage.GetSnapshot(
"", optSnapshotID, optSnapshotName); err != nil {
return nil, err
}
switch {
case len(snapshots) == 0:
return nil, goof.WithField(
"optSnapshotName", optSnapshotName, "No snapshots returned")
case len(snapshots) > 1:
return nil, goof.WithField(
"optSnapshotName", optSnapshotName, "Too many snapshots returned")
}
return snapshots[0], nil
}
示例2: createInitVolume
func (d *driver) createInitVolume(
volumeName string,
volumeOpts core.VolumeOpts) (*core.Volume, error) {
var optVolumeName string
var optVolumeID string
optVolumeName, _ = volumeOpts["volumename"]
optVolumeID, _ = volumeOpts["volumeid"]
if optVolumeName == "" && optVolumeID == "" {
return nil, nil
}
var err error
var volumes []*core.Volume
if volumes, err = d.r.Storage.GetVolume(optVolumeID, optVolumeName); err != nil {
return nil, err
}
switch {
case len(volumes) == 0:
return nil, goof.WithField(
"optVolumeName", optVolumeName, "No volumes returned")
case len(volumes) > 1:
return nil, goof.WithField(
"optVolumeName", optVolumeName, "Too many volumes returned")
}
return volumes[0], nil
}
示例3: RegisterCustomKey
// RegisterCustomKey registers a custom key with the context package.
func RegisterCustomKey(key interface{}, mask CustomKeyTypes) error {
customKeysRWL.Lock()
defer customKeysRWL.Unlock()
if _, ok := customKeys[key]; ok {
return goof.WithField("key", key, "key already registered")
}
newCustomKey := &customKey{
internalID: len(customKeys) + 1,
externalID: key,
keyBitmask: mask,
}
customKeys[newCustomKey.externalID] = newCustomKey
log.WithFields(log.Fields{
"internalID": newCustomKey.internalID,
"externalID": newCustomKey.externalID,
"keyBitmask": newCustomKey.keyBitmask,
}).Info("registered custom context key")
return nil
}
示例4: CompileFilter
// CompileFilter compiles a filter string.
func CompileFilter(s string) (*types.Filter, error) {
es, err := url.QueryUnescape(s)
if err != nil {
return nil, err
}
s = es
if len(s) == 0 || s[0] != '(' {
return nil, errCharZeroNotLParen
}
f, pos, err := compileFilter(s, 1)
if err != nil {
return nil, err
}
if pos != len(s) {
return nil, goof.WithField(
"extra", s[pos:],
"finished compiling filter with extra at end")
}
return f, nil
}
示例5: CreateVolume
func (d *driver) CreateVolume(
runAsync bool, volumeName, volumeID, snapshotID, volumeType string,
IOPS, size int64, availabilityZone string) (*core.Volume, error) {
volumes, err := d.GetVolume("", volumeName)
if err != nil {
return nil, err
}
if len(volumes) > 0 {
return nil, goof.WithField("volumeName", volumeName, "volume name already exists")
}
resp, err := d.createVolume(
runAsync, volumeName, volumeID, snapshotID, volumeType,
IOPS, size, availabilityZone)
if err != nil {
return nil, err
}
volumes, err = d.GetVolume(resp.VolumeId, "")
if err != nil {
return nil, err
}
// log.Println(fmt.Sprintf("Created volume: %+v", volumes[0]))
return volumes[0], nil
}
示例6: getServiceInfo
func (c *client) getServiceInfo(service string) (*types.ServiceInfo, error) {
if si := c.serviceCache.GetServiceInfo(service); si != nil {
return si, nil
}
return nil, goof.WithField("name", service, "unknown service")
}
示例7: initStorageDriver
func (s *storageService) initStorageDriver(ctx types.Context) error {
driverName := s.config.GetString("driver")
if driverName == "" {
driverName = s.config.GetString("libstorage.driver")
if driverName == "" {
driverName = s.config.GetString("libstorage.storage.driver")
if driverName == "" {
return goof.WithField(
"service", s.name, "error getting driver name")
}
}
}
ctx.WithField("driverName", driverName).Debug("got driver name")
driver, err := registry.NewStorageDriver(driverName)
if err != nil {
return err
}
ctx = ctx.WithValue(context.DriverKey, driver)
if err := driver.Init(ctx, s.config); err != nil {
return err
}
s.driver = driver
return nil
}
示例8: GetModuleInstance
// GetModuleInstance gets the module instance with the provided instance ID.
func GetModuleInstance(modInstID int32) (*Instance, error) {
modInstancesRwl.RLock()
defer modInstancesRwl.RUnlock()
mod, modExists := modInstances[modInstID]
if !modExists {
return nil,
goof.WithField("id", modInstID, "unknown module instance")
}
return mod, nil
}
示例9: GetModuleInstance
// GetModuleInstance gets the module instance with the provided name.
func GetModuleInstance(name string) (*Instance, error) {
modInstancesRwl.RLock()
defer modInstancesRwl.RUnlock()
name = strings.ToLower(name)
mod, modExists := modInstances[name]
if !modExists {
return nil,
goof.WithField("name", name, "unknown module instance")
}
return mod, nil
}
示例10: updateExecutor
func (c *client) updateExecutor(ctx types.Context) error {
if c.isController() {
return utils.NewUnsupportedForClientTypeError(
c.clientType, "updateExecutor")
}
ctx.Debug("updating executor")
lsxi := c.lsxCache.GetExecutorInfo(types.LSX.Name())
if lsxi == nil {
return goof.WithField("lsx", types.LSX, "unknown executor")
}
ctx.Debug("waiting on executor lock")
if err := c.lsxMutexWait(); err != nil {
return err
}
defer func() {
ctx.Debug("signalling executor lock")
if err := c.lsxMutexSignal(); err != nil {
panic(err)
}
}()
if !types.LSX.Exists() {
ctx.Debug("executor does not exist, download executor")
return c.downloadExecutor(ctx)
}
ctx.Debug("executor exists, getting local checksum")
checksum, err := c.getExecutorChecksum(ctx)
if err != nil {
return err
}
if lsxi.MD5Checksum != checksum {
ctx.WithFields(log.Fields{
"remoteChecksum": lsxi.MD5Checksum,
"localChecksum": checksum,
}).Debug("executor checksums do not match, download executor")
return c.downloadExecutor(ctx)
}
return nil
}
示例11: UnmarshalText
// UnmarshalText unmarshals the Transaction from a string.
func (t *Transaction) UnmarshalText(text []byte) error {
m := txRX.FindSubmatch(text)
if len(m) == 0 {
return goof.WithField("value", string(text), "invalid transaction")
}
t.ID = &UUID{}
if err := t.ID.UnmarshalText(m[1]); err != nil {
return err
}
if err := (&t.Created).UnmarshalText(m[2]); err != nil {
return err
}
return nil
}
示例12: probeFsType
func probeFsType(device string) (string, error) {
probes := []probeData{
{"btrfs", "_BHRfS_M", 0x10040},
{"ext4", "\123\357", 0x438},
{"xfs", "XFSB", 0},
}
maxLen := uint64(0)
for _, p := range probes {
l := p.offset + uint64(len(p.magic))
if l > maxLen {
maxLen = l
}
}
file, err := os.Open(device)
if err != nil {
return "", err
}
defer file.Close()
buffer := make([]byte, maxLen)
l, err := file.Read(buffer)
if err != nil {
return "", err
}
if uint64(l) != maxLen {
return "", goof.WithField(
"device", device, "error detecting filesystem")
}
for _, p := range probes {
if bytes.Equal(
[]byte(p.magic), buffer[p.offset:p.offset+uint64(len(p.magic))]) {
return p.fsName, nil
}
}
return "", errUnknownFileSystem
}
示例13: createGetVolumes
func (d *driver) createGetVolumes(
volumeName string,
volumeOpts core.VolumeOpts) ([]*core.Volume, bool, error) {
var err error
var volumes []*core.Volume
if volumes, err = d.r.Storage.GetVolume("", volumeName); err != nil {
return nil, false, err
}
overwriteFs, _ := strconv.ParseBool(volumeOpts["overwritefs"])
switch {
case len(volumes) == 1 && !overwriteFs:
return volumes, overwriteFs, nil
case len(volumes) > 1:
return nil, overwriteFs, goof.WithField(
"volumeName", volumeName, "Too many volumes returned")
}
return volumes, overwriteFs, nil
}
示例14: CreateVolume
func (d *driver) CreateVolume(
notUsed bool,
volumeName, volumeID, snapshotID, NUvolumeType string,
NUIOPS, size int64, NUavailabilityZone string) (*core.Volume, error) {
fields := eff(map[string]interface{}{
"volumeID": volumeID,
"volumeName": volumeName,
"snapshotID": snapshotID,
"size": size,
})
size = size * 1024 * 1024 * 1024
volumes, err := d.GetVolume("", volumeName)
if err != nil {
return nil, err
}
if len(volumes) > 0 {
return nil, goof.WithField(volumeName, "volumeName", "volume exists already")
}
volume, err := d.createVolume(volumeName, size)
if err != nil {
return nil, goof.WithFieldsE(fields, "error creating new volume", err)
}
volumes, err = d.GetVolume(volume.ID, "")
if err != nil {
return nil, err
}
if len(volumes) == 0 {
return nil, goof.New("failed to get new volume")
}
return volumes[0], nil
}
示例15: UnmarshalText
// UnmarshalText unmarshals the data into a an InstanceID provided the data
// adheres to the format described in the MarshalText function.
func (l *LocalDevices) UnmarshalText(value []byte) error {
m := ldRX.FindSubmatch(value)
lm := len(m)
if lm < 3 {
return goof.WithField("value", string(value), "invalid LocalDevices")
}
l.Driver = string(m[1])
l.DeviceMap = map[string]string{}
for _, p := range bytes.Split(m[2], commaByteSep) {
pp := bytes.Split(p, colonByteSep)
if len(pp) < 2 {
continue
}
l.DeviceMap[string(pp[0])] = string(pp[1])
}
return nil
}