This repository has been archived by the owner on May 27, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #169 from getantibody/keep-order
keep the order of the plugins
- Loading branch information
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package antibody | ||
|
||
import ( | ||
"sort" | ||
"strings" | ||
) | ||
|
||
type indexedLine struct { | ||
idx int | ||
line string | ||
} | ||
|
||
type indexedLines []indexedLine | ||
|
||
// Len is needed by Sort interface | ||
func (slice indexedLines) Len() int { | ||
return len(slice) | ||
} | ||
|
||
// Less is needed by Sort interface | ||
func (slice indexedLines) Less(i, j int) bool { | ||
return slice[i].idx < slice[j].idx | ||
} | ||
|
||
// Swap is needed by Sort interface | ||
func (slice indexedLines) Swap(i, j int) { | ||
slice[i], slice[j] = slice[j], slice[i] | ||
} | ||
|
||
// Sort all lines and join them in a string | ||
func (slice indexedLines) String() string { | ||
sort.Sort(slice) | ||
var lines []string | ||
for _, line := range slice { | ||
lines = append(lines, line.line) | ||
} | ||
return strings.Join(lines, "\n") | ||
} |