当前位置: 首页>>代码示例>>Golang>>正文


Golang Store.Set方法代码示例

本文整理汇总了Golang中github.com/codedellemc/libstorage/api/types.Store.Set方法的典型用法代码示例。如果您正苦于以下问题:Golang Store.Set方法的具体用法?Golang Store.Set怎么用?Golang Store.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/codedellemc/libstorage/api/types.Store的用法示例。


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

示例1: Handle

// Handle is the type's Handler function.
func (h *postArgsHandler) Handle(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	reqObj := ctx.Value("reqObj")
	if reqObj == nil {
		return fmt.Errorf("missing request object")
	}

	v := reflect.ValueOf(reqObj).Elem()
	t := v.Type()

	for i := 0; i < v.NumField(); i++ {
		ft := t.Field(i)
		fv := v.Field(i).Interface()

		switch tfv := fv.(type) {
		case nil:
			// do nothing
		case map[string]interface{}:
			store.Set(getFieldName(ft), utils.NewStoreWithData(tfv))
		default:
			// add it to the store
			store.Set(getFieldName(ft), fv)
		}
	}

	return h.handler(ctx, w, req, store)
}
开发者ID:emccode,项目名称:libstorage,代码行数:32,代码来源:handlers_post_args.go

示例2: volumesForService

func (r *router) volumesForService(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	filter, err := parseFilter(store)
	if err != nil {
		return err
	}
	if filter != nil {
		store.Set("filter", filter)
	}

	service := context.MustService(ctx)

	opts := &types.VolumesOpts{
		Attachments: store.GetAttachments(),
		Opts:        store,
	}

	run := func(
		ctx types.Context,
		svc types.StorageService) (interface{}, error) {

		return getFilteredVolumes(ctx, req, store, svc, opts, filter)
	}

	return httputils.WriteTask(
		ctx,
		r.config,
		w,
		store,
		service.TaskExecute(ctx, run, schema.VolumeMapSchema),
		http.StatusOK)
}
开发者ID:emccode,项目名称:libstorage,代码行数:36,代码来源:volume_routes.go

示例3: Handle

// Handle is the type's Handler function.
func (h *queryParamsHandler) Handle(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	for k, v := range req.URL.Query() {
		ctx.WithFields(log.Fields{
			"key":        k,
			"value":      v,
			"len(value)": len(v),
		}).Debug("query param")
		switch len(v) {
		case 0:
			store.Set(k, true)
		case 1:
			if len(v[0]) == 0 {
				store.Set(k, true)
			} else {
				if i, err := strconv.ParseInt(v[0], 10, 64); err == nil {
					store.Set(k, i)
				} else if b, err := strconv.ParseBool(v[0]); err == nil {
					store.Set(k, b)
				} else {
					store.Set(k, v[0])
				}
			}
		default:
			store.Set(k, v)
		}
	}
	return h.handler(ctx, w, req, store)
}
开发者ID:emccode,项目名称:libstorage,代码行数:34,代码来源:handlers_query_params.go

示例4: volumes

func (r *router) volumes(
	ctx types.Context,
	w http.ResponseWriter,
	req *http.Request,
	store types.Store) error {

	filter, err := parseFilter(store)
	if err != nil {
		return err
	}
	if filter != nil {
		store.Set("filter", filter)
	}

	var (
		tasks   = map[string]*types.Task{}
		taskIDs []int
		opts    = &types.VolumesOpts{
			Attachments: store.GetAttachments(),
			Opts:        store,
		}
		reply = types.ServiceVolumeMap{}
	)

	for service := range services.StorageServices(ctx) {

		run := func(
			ctx types.Context,
			svc types.StorageService) (interface{}, error) {

			ctx = context.WithStorageService(ctx, svc)

			var err error
			if ctx, err = context.WithStorageSession(ctx); err != nil {
				return nil, err
			}

			return getFilteredVolumes(ctx, req, store, svc, opts, filter)
		}

		task := service.TaskExecute(ctx, run, schema.VolumeMapSchema)
		taskIDs = append(taskIDs, task.ID)
		tasks[service.Name()] = task
	}

	run := func(ctx types.Context) (interface{}, error) {

		services.TaskWaitAll(ctx, taskIDs...)

		for k, v := range tasks {
			if v.Error != nil {
				return nil, utils.NewBatchProcessErr(reply, v.Error)
			}

			objMap, ok := v.Result.(types.VolumeMap)
			if !ok {
				return nil, utils.NewBatchProcessErr(
					reply, goof.New("error casting to types.VolumeMap"))
			}
			reply[k] = objMap
		}

		return reply, nil
	}

	return httputils.WriteTask(
		ctx,
		r.config,
		w,
		store,
		services.TaskExecute(ctx, run, schema.ServiceVolumeMapSchema),
		http.StatusOK)
}
开发者ID:emccode,项目名称:libstorage,代码行数:73,代码来源:volume_routes.go


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