Beispiel #1
0
//export go_operationSetProperty
func go_operationSetProperty(operationId *C.char, k *C.char, v *C.char, convertTo *C.char) {
	if obj, ok := cgoget(C.GoString(operationId)); ok {
		switch obj.(type) {
		case *Operation:
			operation := obj.(*Operation)

			var payload *Payload

			if operation.Index < 0 {
				payload = operation.AddPayload()
				operation.Index = 0
			} else {
				payload = operation.Payloads[operation.Index]
			}

			if key := C.GoString(k); key != `` {
				if value := C.GoString(v); value != `` {
					if convertTo != nil {
						var ctype stringutil.ConvertType

						switch C.GoString(convertTo) {
						case `bool`:
							ctype = stringutil.Boolean
						case `float`:
							ctype = stringutil.Float
						case `int`:
							ctype = stringutil.Integer
						case `time`:
							ctype = stringutil.Time
						default:
							ctype = stringutil.String
						}

						if convertedValue, err := stringutil.ConvertTo(ctype, value); err == nil {
							payload.Properties[key] = convertedValue
						} else {
							payload.Properties[key] = value
						}
					} else {
						payload.Properties[key] = value
					}
				}
			}
		default:
			panic(fmt.Sprintf("go_operationSetProperty(): invalid object %s; expected *pulse.Operation, got %T", operationId, obj))
		}
	}
}
//export go_operationSetProperty
func go_operationSetProperty(operationPtr unsafe.Pointer, k *C.char, v *C.char, convertTo *C.char) {
	if operationPtr != nil {
		operation := (*Operation)(operationPtr)
		var payload *Payload

		if operation.Index < 0 {
			payload = operation.AddPayload()
			operation.Index = 0
		} else {
			payload = operation.Payloads[operation.Index]
		}

		if key := C.GoString(k); key != `` {
			if value := C.GoString(v); value != `` {
				if convertTo != nil {
					var ctype stringutil.ConvertType

					switch C.GoString(convertTo) {
					case `bool`:
						ctype = stringutil.Boolean
					case `float`:
						ctype = stringutil.Float
					case `int`:
						ctype = stringutil.Integer
					case `time`:
						ctype = stringutil.Time
					default:
						ctype = stringutil.String
					}

					if convertedValue, err := stringutil.ConvertTo(ctype, value); err == nil {
						payload.Properties[key] = convertedValue
					} else {
						payload.Properties[key] = value
					}
				} else {
					payload.Properties[key] = value
				}
			}
		}
	}
}