本文整理匯總了Golang中github.com/mozilla-services/heka/message.Field類的典型用法代碼示例。如果您正苦於以下問題:Golang Field類的具體用法?Golang Field怎麽用?Golang Field使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Field類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addToDimensions
// Function used to add a specific dynamic metric namespace element
// into the dimensions field of final Heka message structure
func addToDimensions(f *message.Field, fName string) (*message.Field, error) {
// If the dimension field does not exists yet, create ti
if f == nil {
field, err := message.NewField("dimensions", fName, "")
if err != nil {
logger.WithField("_block", "addToDimensions").Error(err)
return nil, err
}
return field, nil
}
// Add field name to dimension field
f.AddValue(fName)
return f, nil
}
示例2: lookup_field
func lookup_field(msg *message.Message, fn string, fi int, ai int) (int,
unsafe.Pointer, int) {
var field *message.Field
if fi != 0 {
fields := msg.FindAllFields(fn)
if fi >= len(fields) {
return 0, unsafe.Pointer(nil), 0
}
field = fields[fi]
} else {
if field = msg.FindFirstField(fn); field == nil {
return 0, unsafe.Pointer(nil), 0
}
}
fieldType := int(field.GetValueType())
switch field.GetValueType() {
case message.Field_STRING:
if ai >= len(field.ValueString) {
return fieldType, unsafe.Pointer(nil), 0
}
value := field.ValueString[ai]
cs := C.CString(value) // freed by the caller
return fieldType, unsafe.Pointer(cs), len(value)
case message.Field_BYTES:
if ai >= len(field.ValueBytes) {
return fieldType, unsafe.Pointer(nil), 0
}
value := field.ValueBytes[ai]
return fieldType, unsafe.Pointer(&field.ValueBytes[ai][0]), len(value)
case message.Field_INTEGER:
if ai >= len(field.ValueInteger) {
return fieldType, unsafe.Pointer(nil), 0
}
return fieldType, unsafe.Pointer(&field.ValueInteger[ai]), 0
case message.Field_DOUBLE:
if ai >= len(field.ValueDouble) {
return fieldType, unsafe.Pointer(nil), 0
}
return fieldType, unsafe.Pointer(&field.ValueDouble[ai]), 0
case message.Field_BOOL:
if ai >= len(field.ValueBool) {
return fieldType, unsafe.Pointer(nil), 0
}
return fieldType, unsafe.Pointer(&field.ValueBool[ai]), 0
}
return 0, unsafe.Pointer(nil), 0
}
示例3: getFieldAsString
func getFieldAsString(msg *message.Message, mvar *messageVariable) string {
var field *message.Field
if mvar.fi != 0 {
fields := msg.FindAllFields(mvar.name)
if mvar.fi >= len(fields) {
return ""
}
field = fields[mvar.fi]
} else {
if field = msg.FindFirstField(mvar.name); field == nil {
return ""
}
}
switch field.GetValueType() {
case message.Field_STRING:
if mvar.ai >= len(field.ValueString) {
return ""
}
return field.ValueString[mvar.ai]
case message.Field_BYTES:
if mvar.ai >= len(field.ValueBytes) {
return ""
}
return string(field.ValueBytes[mvar.ai])
case message.Field_INTEGER:
if mvar.ai >= len(field.ValueInteger) {
return ""
}
return fmt.Sprintf("%d", field.ValueInteger[mvar.ai])
case message.Field_DOUBLE:
if mvar.ai >= len(field.ValueDouble) {
return ""
}
return fmt.Sprintf("%g", field.ValueDouble[mvar.ai])
case message.Field_BOOL:
if mvar.ai >= len(field.ValueBool) {
return ""
}
return fmt.Sprintf("%t", field.ValueBool[mvar.ai])
}
return ""
}
示例4: writeField
func writeField(first bool, b *bytes.Buffer, f *message.Field, raw bool) {
if !first {
b.WriteString(`,`)
}
writeQuotedString(b, f.GetName())
b.WriteString(`:`)
switch f.GetValueType() {
case message.Field_STRING:
values := f.GetValueString()
if len(values) > 1 {
b.WriteString(`[`)
for i, value := range values {
if raw {
b.WriteString(value)
} else {
writeQuotedString(b, value)
}
if i < len(values)-1 {
b.WriteString(`,`)
}
}
b.WriteString(`]`)
} else {
if raw {
b.WriteString(values[0])
} else {
writeQuotedString(b, values[0])
}
}
case message.Field_BYTES:
values := f.GetValueBytes()
if len(values) > 1 {
b.WriteString(`[`)
for i, value := range values {
if raw {
b.WriteString(string(value))
} else {
writeQuotedString(b, base64.StdEncoding.EncodeToString(value))
}
if i < len(values)-1 {
b.WriteString(`,`)
}
}
b.WriteString(`]`)
} else {
if raw {
b.WriteString(string(values[0]))
} else {
writeQuotedString(b, string(values[0]))
}
}
case message.Field_INTEGER:
values := f.GetValueInteger()
if len(values) > 1 {
b.WriteString(`[`)
for i, value := range values {
b.WriteString(strconv.FormatInt(value, 10))
if i < len(values)-1 {
b.WriteString(`,`)
}
}
b.WriteString(`]`)
} else {
b.WriteString(strconv.FormatInt(values[0], 10))
}
case message.Field_DOUBLE:
values := f.GetValueDouble()
if len(values) > 1 {
b.WriteString(`[`)
for i, value := range values {
b.WriteString(strconv.FormatFloat(value, 'g', -1, 64))
if i < len(values)-1 {
b.WriteString(`,`)
}
}
b.WriteString(`]`)
} else {
b.WriteString(strconv.FormatFloat(values[0], 'g', -1, 64))
}
case message.Field_BOOL:
values := f.GetValueBool()
if len(values) > 1 {
b.WriteString(`[`)
for i, value := range values {
b.WriteString(strconv.FormatBool(value))
if i < len(values)-1 {
b.WriteString(`,`)
}
}
b.WriteString(`]`)
} else {
b.WriteString(strconv.FormatBool(values[0]))
}
}
}