Expose MarshalOrder (#470)
It is needed as argument to some already public function. Fixes #459 Ref #469
This commit is contained in:
+4
-4
@@ -57,12 +57,12 @@ var annotationDefault = annotation{
|
|||||||
defaultValue: tagDefault,
|
defaultValue: tagDefault,
|
||||||
}
|
}
|
||||||
|
|
||||||
type marshalOrder int
|
type MarshalOrder int
|
||||||
|
|
||||||
// Orders the Encoder can write the fields to the output stream.
|
// Orders the Encoder can write the fields to the output stream.
|
||||||
const (
|
const (
|
||||||
// Sort fields alphabetically.
|
// Sort fields alphabetically.
|
||||||
OrderAlphabetical marshalOrder = iota + 1
|
OrderAlphabetical MarshalOrder = iota + 1
|
||||||
// Preserve the order the fields are encountered. For example, the order of fields in
|
// Preserve the order the fields are encountered. For example, the order of fields in
|
||||||
// a struct.
|
// a struct.
|
||||||
OrderPreserve
|
OrderPreserve
|
||||||
@@ -256,7 +256,7 @@ type Encoder struct {
|
|||||||
annotation
|
annotation
|
||||||
line int
|
line int
|
||||||
col int
|
col int
|
||||||
order marshalOrder
|
order MarshalOrder
|
||||||
promoteAnon bool
|
promoteAnon bool
|
||||||
indentation string
|
indentation string
|
||||||
}
|
}
|
||||||
@@ -317,7 +317,7 @@ func (e *Encoder) ArraysWithOneElementPerLine(v bool) *Encoder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Order allows to change in which order fields will be written to the output stream.
|
// Order allows to change in which order fields will be written to the output stream.
|
||||||
func (e *Encoder) Order(ord marshalOrder) *Encoder {
|
func (e *Encoder) Order(ord MarshalOrder) *Encoder {
|
||||||
e.order = ord
|
e.order = ord
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -103,7 +103,7 @@ func encodeTomlString(value string) string {
|
|||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func tomlTreeStringRepresentation(t *Tree, ord marshalOrder) (string, error) {
|
func tomlTreeStringRepresentation(t *Tree, ord MarshalOrder) (string, error) {
|
||||||
var orderedVals []sortNode
|
var orderedVals []sortNode
|
||||||
switch ord {
|
switch ord {
|
||||||
case OrderPreserve:
|
case OrderPreserve:
|
||||||
@@ -126,7 +126,7 @@ func tomlTreeStringRepresentation(t *Tree, ord marshalOrder) (string, error) {
|
|||||||
return "{ " + strings.Join(values, ", ") + " }", nil
|
return "{ " + strings.Join(values, ", ") + " }", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func tomlValueStringRepresentation(v interface{}, commented string, indent string, ord marshalOrder, arraysOneElementPerLine bool) (string, error) {
|
func tomlValueStringRepresentation(v interface{}, commented string, indent string, ord MarshalOrder, arraysOneElementPerLine bool) (string, error) {
|
||||||
// this interface check is added to dereference the change made in the writeTo function.
|
// this interface check is added to dereference the change made in the writeTo function.
|
||||||
// That change was made to allow this function to see formatting options.
|
// That change was made to allow this function to see formatting options.
|
||||||
tv, ok := v.(*tomlValue)
|
tv, ok := v.(*tomlValue)
|
||||||
@@ -310,7 +310,7 @@ func (t *Tree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64, a
|
|||||||
return t.writeToOrdered(w, indent, keyspace, bytesCount, arraysOneElementPerLine, OrderAlphabetical, " ", false)
|
return t.writeToOrdered(w, indent, keyspace, bytesCount, arraysOneElementPerLine, OrderAlphabetical, " ", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree) writeToOrdered(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool, ord marshalOrder, indentString string, parentCommented bool) (int64, error) {
|
func (t *Tree) writeToOrdered(w io.Writer, indent, keyspace string, bytesCount int64, arraysOneElementPerLine bool, ord MarshalOrder, indentString string, parentCommented bool) (int64, error) {
|
||||||
var orderedVals []sortNode
|
var orderedVals []sortNode
|
||||||
|
|
||||||
switch ord {
|
switch ord {
|
||||||
|
|||||||
Reference in New Issue
Block a user