Ejemplo n.º 1
0
// toString - Formats interface to string and cuts to `MaxVariableLength`.
func toString(v interface{}) (res string) {
	value := action.Format{v}

	if m, ok := value.Map(); ok {
		body, _ := m.JSON()
		res = string(body)
	} else if b, ok := value.Bytes(); ok {
		res = string(b)
	} else {
		res = fmt.Sprintf("%v", value.Interface())
	}

	// Cut value at 100 characters
	if len(res) >= MaxVariableLength {
		res = res[:MaxVariableLength] + "..."
	}

	// Break by new line and trim every line
	var lines []string
	for _, line := range strings.Split(res, "\n") {
		lines = append(lines, strings.TrimSpace(line))
	}

	// Join to one line
	res = strings.Join(lines, "")

	return
}