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

Golang goof.WithField函数代码示例

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

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



在下文中一共展示了WithField函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:luk5,项目名称:rexray,代码行数:32,代码来源:volume.go


示例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
}
开发者ID:luk5,项目名称:rexray,代码行数:31,代码来源:volume.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:26,代码来源:context_keys.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:26,代码来源:filters.go


示例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

}
开发者ID:lucmichalski,项目名称:rexray,代码行数:30,代码来源:ec2.go


示例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")
}
开发者ID:emccode,项目名称:libstorage,代码行数:7,代码来源:libstorage_client.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:28,代码来源:services_storage.go


示例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
}
开发者ID:bottkars,项目名称:rexray,代码行数:14,代码来源:module.go


示例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
}
开发者ID:luk5,项目名称:rexray,代码行数:15,代码来源:module.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:47,代码来源:libstorage_client.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:19,代码来源:types_tx.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:41,代码来源:linux.go


示例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
}
开发者ID:luk5,项目名称:rexray,代码行数:22,代码来源:volume.go


示例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
}
开发者ID:lucmichalski,项目名称:rexray,代码行数:39,代码来源:virtualbox.go


示例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
}
开发者ID:emccode,项目名称:libstorage,代码行数:24,代码来源:types_localdevices.go


示例16: CreateVolume

func (d *driver) CreateVolume(
	notUsed bool,
	volumeName, volumeID, snapshotID, volumeType string,
	IOPS, size int64, availabilityZone string) (*core.Volume, error) {

	if volumeName == "" {
		return nil, goof.New("no volume name specified")
	}

	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(
		notUsed, volumeName, volumeID, snapshotID,
		volumeType, IOPS, size, availabilityZone)

	if err != nil {
		return nil, err
	}

	volumes, err = d.GetVolume(resp.ID, "")
	if err != nil {
		return nil, err
	}

	log.WithFields(log.Fields{
		"provider": providerName,
		"volume":   volumes[0],
	}).Debug("created volume")
	return volumes[0], nil

}
开发者ID:luk5,项目名称:rexray,代码行数:38,代码来源:scaleio.go


示例17: UnmarshalText

// UnmarshalText unmarshals the data into a an InstanceID provided the data
// adheres to the format described in the MarshalText function.
func (i *InstanceID) UnmarshalText(value []byte) error {

	m := iidRX.FindSubmatch(value)
	lm := len(m)

	if lm < 3 {
		return goof.WithField("value", string(value), "invalid InstanceID")
	}

	i.Driver = string(m[1])
	i.ID = string(m[2])

	if lm > 3 && len(m[3]) > 0 {
		qs, err := url.ParseQuery(string(m[3]))
		if err != nil {
			return err
		}
		i.Fields = map[string]string{}
		for k := range qs {
			i.Fields[k] = qs.Get(k)
		}
	}

	if lm > 4 && len(m[4]) > 0 {
		enc := m[4]
		dec := b64.NewDecoder(b64.StdEncoding, bytes.NewReader(enc))
		i.metadata = make([]byte, b64.StdEncoding.DecodedLen(len(enc)))
		n, err := dec.Read(i.metadata)
		if err != nil {
			return err
		}
		i.metadata = i.metadata[:n]
	}

	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:38,代码来源:types_instanceid.go


示例18: Start

func (m *mod) Start() error {

	proto, addr, parseAddrErr := gotil.ParseAddress(m.Address())
	if parseAddrErr != nil {
		return parseAddrErr
	}

	const validProtoPatt = "(?i)^unix|tcp$"
	isProtoValid, matchProtoErr := regexp.MatchString(validProtoPatt, proto)
	if matchProtoErr != nil {
		return goof.WithFieldsE(goof.Fields{
			"protocol":       proto,
			"validProtoPatt": validProtoPatt,
		}, "error matching protocol", matchProtoErr)
	}
	if !isProtoValid {
		return goof.WithField("protocol", proto, "invalid protocol")
	}

	if err := m.r.InitDrivers(); err != nil {
		return goof.WithFieldsE(goof.Fields{
			"m":   m,
			"m.r": m.r,
		}, "error initializing drivers", err)
	}

	if err := os.MkdirAll("/etc/docker/plugins", 0755); err != nil {
		return err
	}

	var specPath string
	var startFunc func() error

	mux := m.buildMux()

	if proto == "unix" {
		sockFile := addr
		sockFileDir := filepath.Dir(sockFile)
		mkSockFileDirErr := os.MkdirAll(sockFileDir, 0755)
		if mkSockFileDirErr != nil {
			return mkSockFileDirErr
		}

		_ = os.RemoveAll(sockFile)

		specPath = m.Address()
		startFunc = func() error {
			l, lErr := net.Listen("unix", sockFile)
			if lErr != nil {
				return lErr
			}
			defer l.Close()
			defer os.Remove(sockFile)

			return http.Serve(l, mux)
		}
	} else {
		specPath = addr
		startFunc = func() error {
			s := &http.Server{
				Addr:           addr,
				Handler:        mux,
				ReadTimeout:    10 * time.Second,
				WriteTimeout:   10 * time.Second,
				MaxHeaderBytes: 1 << 20,
			}
			return s.ListenAndServe()
		}
	}

	go func() {
		sErr := startFunc()
		if sErr != nil {
			panic(sErr)
		}
	}()

	writeSpecErr := ioutil.WriteFile(
		"/etc/docker/plugins/rexray.spec", []byte(specPath), 0644)
	if writeSpecErr != nil {
		return writeSpecErr
	}

	return nil
}
开发者ID:luk5,项目名称:rexray,代码行数:85,代码来源:remvoldriver.go


示例19: ParseTLSConfig

// ParseTLSConfig returns a new TLS configuration.
func ParseTLSConfig(
	config gofig.Config,
	fields log.Fields,
	roots ...string) (*tls.Config, error) {

	f := func(k string, v interface{}) {
		if fields == nil {
			return
		}
		fields[k] = v
	}

	if !isSet(config, types.ConfigTLS, roots...) {
		return nil, nil
	}

	if isSet(config, types.ConfigTLSDisabled, roots...) {
		tlsDisabled := getBool(config, types.ConfigTLSDisabled, roots...)
		if tlsDisabled {
			f(types.ConfigTLSDisabled, true)
			return nil, nil
		}
	}

	if !isSet(config, types.ConfigTLSKeyFile, roots...) {
		return nil, goof.New("keyFile required")
	}
	keyFile := getString(config, types.ConfigTLSKeyFile, roots...)
	if !gotil.FileExists(keyFile) {
		return nil, goof.WithField("path", keyFile, "invalid key file")
	}
	f(types.ConfigTLSKeyFile, keyFile)

	if !isSet(config, types.ConfigTLSCertFile, roots...) {
		return nil, goof.New("certFile required")
	}
	certFile := getString(config, types.ConfigTLSCertFile, roots...)
	if !gotil.FileExists(certFile) {
		return nil, goof.WithField("path", certFile, "invalid cert file")
	}
	f(types.ConfigTLSCertFile, certFile)

	cer, err := tls.LoadX509KeyPair(certFile, keyFile)
	if err != nil {
		return nil, err
	}

	tlsConfig := &tls.Config{Certificates: []tls.Certificate{cer}}

	if isSet(config, types.ConfigTLSServerName, roots...) {
		serverName := getString(config, types.ConfigTLSServerName, roots...)
		tlsConfig.ServerName = serverName
		f(types.ConfigTLSServerName, serverName)
	}

	if isSet(config, types.ConfigTLSClientCertRequired, roots...) {
		clientCertRequired := getBool(
			config, types.ConfigTLSClientCertRequired, roots...)
		if clientCertRequired {
			tlsConfig.ClientAuth = tls.RequireAndVerifyClientCert
		}
		f(types.ConfigTLSClientCertRequired, clientCertRequired)
	}

	if isSet(config, types.ConfigTLSTrustedCertsFile, roots...) {
		trustedCertsFile := getString(
			config, types.ConfigTLSTrustedCertsFile, roots...)

		if !gotil.FileExists(trustedCertsFile) {
			return nil, goof.WithField(
				"path", trustedCertsFile, "invalid trust file")
		}

		f(types.ConfigTLSTrustedCertsFile, trustedCertsFile)

		buf, err := func() ([]byte, error) {
			f, err := os.Open(trustedCertsFile)
			if err != nil {
				return nil, err
			}
			defer f.Close()
			buf, err := ioutil.ReadAll(f)
			if err != nil {
				return nil, err
			}
			return buf, nil
		}()
		if err != nil {
			return nil, err
		}

		certPool := x509.NewCertPool()
		certPool.AppendCertsFromPEM(buf)
		tlsConfig.RootCAs = certPool
		tlsConfig.ClientCAs = certPool
	}

	return tlsConfig, nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:100,代码来源:utils_tls.go


示例20: initEndpoints

func (s *server) initEndpoints(ctx types.Context) error {

	endpointsObj := s.config.Get(types.ConfigEndpoints)
	if endpointsObj == nil {
		if err := s.initDefaultEndpoint(); err != nil {
			return goof.WithError("no endpoints defined", err)
		}
		endpointsObj = s.config.Get(types.ConfigEndpoints)
	}

	endpoints, ok := endpointsObj.(map[string]interface{})
	if !ok {
		return goof.New("endpoints invalid type")
	}

	if len(endpoints) == 0 {
		if err := s.initDefaultEndpoint(); err != nil {
			return err
		}
	}

	for endpointName := range endpoints {

		endpoint := fmt.Sprintf("%s.%s", types.ConfigEndpoints, endpointName)
		address := fmt.Sprintf("%s.address", endpoint)
		laddr := s.config.GetString(address)
		if laddr == "" {
			return goof.WithField("endpoint", endpoint, "missing address")
		}

		laddrET := types.ParseEndpointType(laddr)
		switch laddrET {

		case types.TCPEndpoint:

			var tcpPort int
			func() {
				tcpPortLock.Lock()
				defer tcpPortLock.Unlock()
				tcpPort = gotil.RandomTCPPort()
			}()

			laddr = fmt.Sprintf("tcp://127.0.0.1:%d", tcpPort)
			s.ctx.WithField("endpoint", endpoint).Info(
				"initializing auto tcp endpoint")

		case types.UnixEndpoint:

			laddr = fmt.Sprintf("unix://%s", utils.GetTempSockFile())
			s.ctx.WithField("endpoint", endpoint).Info(
				"initializing auto unix endpoint")

		}

		s.ctx.WithFields(log.Fields{
			"endpoint": endpoint, "address": laddr}).Debug("endpoint info")

		s.addrs = append(s.addrs, laddr)

		proto, addr, err := gotil.ParseAddress(laddr)
		if err != nil {
			return err
		}

		logFields := map[string]interface{}{
			"endpoint": endpointName,
			"address":  laddr,
		}

		tlsConfig, err :=
			utils.ParseTLSConfig(s.config.Scope(endpoint), logFields, endpoint)
		if err != nil {
			return err
		}

		ctx.WithFields(logFields).Info("configured endpoint")

		srv, err := s.newHTTPServer(proto, addr, tlsConfig)
		if err != nil {
			return err
		}

		ctx.Info("server created")
		s.servers = append(s.servers, srv)
	}

	return nil
}
开发者ID:emccode,项目名称:libstorage,代码行数:88,代码来源:server_http.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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