當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Field.GetValue方法代碼示例

本文整理匯總了Golang中rsprd/com/spread/pkg/spreadproto.Field.GetValue方法的典型用法代碼示例。如果您正苦於以下問題:Golang Field.GetValue方法的具體用法?Golang Field.GetValue怎麽用?Golang Field.GetValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rsprd/com/spread/pkg/spreadproto.Field的用法示例。


在下文中一共展示了Field.GetValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: InteractiveArgs

// InteractiveArgs hosts an interactive session using a Reader and Writer which prompts for input which is used to
// populate the provided field. If required is true then only fields without defaults will be prompted for.
func InteractiveArgs(r io.ReadCloser, w io.Writer, field *pb.Field, required bool) error {
	param := field.GetParam()

	defaultVal := param.GetDefault()
	// don't prompt if only checking for required and has default
	if required && defaultVal != nil {
		return nil
	}

	fmt.Fprintln(w, "Name: ", param.Name)
	fmt.Fprintln(w, "Prompt: ", param.Prompt)
	fmt.Fprint(w, "Input: ", displayDefault(defaultVal))
	reader := bufio.NewReader(r)
	text, err := reader.ReadString('\n')
	if err != nil {
		return err
	}

	// use default if no input given
	args := []*pb.Argument{defaultVal}
	if len(text) > 1 {
		_, str := field.GetValue().(*pb.Field_Str)
		args, err = ParseArguments(text[:len(text)-1], str)
		if err != nil {
			return err
		}
	}

	return ApplyArguments(field, args...)
}
開發者ID:redspread,項目名稱:spread,代碼行數:32,代碼來源:parameter.go

示例2: decodeField

func decodeField(field *pb.Field) (interface{}, error) {
	val := field.GetValue()
	if val == nil {
		return nil, nil
	}

	switch v := val.(type) {
	case *pb.Field_Number:
		return v.Number, nil
	case *pb.Field_Str:
		return v.Str, nil
	case *pb.Field_Boolean:
		return v.Boolean, nil
	case *pb.Field_Object:
		return decodeObject(v.Object.GetItems())
	case *pb.Field_Array:
		return decodeArray(v.Array.GetItems())
	case *pb.Field_Link:
		// TODO: IMPLEMENT FOLLOWING LINKS
		return nil, nil
	}

	return nil, fmt.Errorf("unknown type for Field '%s'", field.Key)
}
開發者ID:redspread,項目名稱:spread,代碼行數:24,代碼來源:decode.go

示例3: AddParameterFields

// AddParameterFields adds fields with parameters from the given field (and its subfields) to the map given. The name of the parameter is the key.
func AddParameterFields(field *pb.Field, params map[string]*pb.Field) {
	param := field.GetParam()
	// add to map if has parameter
	if param != nil {
		params[param.Name] = field
	}

	switch val := field.GetValue().(type) {
	case *pb.Field_Object:
		for _, objField := range val.Object.GetItems() {
			AddParameterFields(objField, params)
		}
	case *pb.Field_Array:
		for _, arrField := range val.Array.GetItems() {
			AddParameterFields(arrField, params)
		}
	}
}
開發者ID:redspread,項目名稱:spread,代碼行數:19,代碼來源:parameter.go

示例4: FieldValueEquals

// FieldValueEquals returns true if the value of the given fields is the same.
func FieldValueEquals(this, other *pb.Field) bool {
	// check for pointer + primitive  matches and nil values
	switch {
	case this == other:
		return true
	case this == nil || other == nil:
		return false
	case this.GetValue() == other.GetValue():
		return true
	case this.GetValue() == nil || other.GetValue() == nil:
		return false
	}

	// check for matches with objects and arrays
	switch val := this.GetValue().(type) {
	case *pb.Field_Number:
		otherVal, ok := other.GetValue().(*pb.Field_Number)
		if !ok {
			return false
		}
		return val.Number == otherVal.Number
	case *pb.Field_Str:
		otherVal, ok := other.GetValue().(*pb.Field_Str)
		if !ok {
			return false
		}
		return val.Str == otherVal.Str
	case *pb.Field_Boolean:
		otherVal, ok := other.GetValue().(*pb.Field_Boolean)
		if !ok {
			return false
		}
		return val.Boolean == otherVal.Boolean
	case *pb.Field_Object:
		otherVal, ok := other.GetValue().(*pb.Field_Object)
		if !ok {
			return false
		}
		items, otherItems := val.Object.GetItems(), otherVal.Object.GetItems()

		if len(items) != len(otherItems) {
			return false
		}

		for k, v := range items {
			otherV, ok := otherItems[k]
			if !ok {
				return false
			}

			return FieldValueEquals(v, otherV)
		}
	case *pb.Field_Array:
		otherVal, ok := other.GetValue().(*pb.Field_Array)
		if !ok {
			return false
		}
		items, otherItems := val.Array.GetItems(), otherVal.Array.GetItems()

		if len(items) != len(otherItems) {
			return false
		}

		for k, v := range items {
			return FieldValueEquals(v, otherItems[k])
		}
	}

	return false
}
開發者ID:redspread,項目名稱:spread,代碼行數:71,代碼來源:fields.go


注:本文中的rsprd/com/spread/pkg/spreadproto.Field.GetValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。