annotate zs_ext.go @ 31:b2f491299cee draft

dead end with template functions
author zaitsev.serge
date Wed, 02 Sep 2015 14:54:16 +0000
parents d966bcb229c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
1 package main
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
2
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
3 import (
25
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
4 "bytes"
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
5 "log"
25
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
6 "os"
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
7 "path/filepath"
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
8 "sort"
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
9 "strconv"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
10 "strings"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
11 "time"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
12
26
d966bcb229c0 fixed math package
zaitsev.serge
parents: 25
diff changeset
13 "math"
d966bcb229c0 fixed math package
zaitsev.serge
parents: 25
diff changeset
14
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
15 "github.com/drhodes/golorem"
25
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
16 "github.com/jaytaylor/html2text"
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
17 )
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
18
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
19 // zs var <filename> -- returns list of variables and their values
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
20 // zs var <filename> <var...> -- returns list of variable values
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
21 func Var(args ...string) string {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
22 if len(args) == 0 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
23 return "var: filename expected"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
24 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
25 s := ""
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
26 if vars, _, err := md(args[0], globals()); err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
27 return "var: " + err.Error()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
28 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
29 if len(args) > 1 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
30 for _, a := range args[1:] {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
31 s = s + vars[a] + "\n"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
32 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
33 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
34 for k, v := range vars {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
35 s = s + k + ":" + v + "\n"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
36 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
37 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
38 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
39 return strings.TrimSpace(s)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
40 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
41 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
42
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
43 // zs lorem <n> -- returns <n> random lorem ipsum sentences
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
44 func Lorem(args ...string) string {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
45 if len(args) > 1 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
46 return "lorem: invalid usage"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
47 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
48 if len(args) == 0 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
49 return lorem.Paragraph(5, 5)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
50 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
51 if n, err := strconv.Atoi(args[0]); err == nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
52 return lorem.Paragraph(n, n)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
53 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
54 return "lorem: " + err.Error()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
55 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
56 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
57
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
58 // zs datefmt <fmt> <date> -- returns formatted date from unix time
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
59 func DateFmt(args ...string) string {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
60 if len(args) == 0 || len(args) > 2 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
61 return "datefmt: invalid usage"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
62 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
63 if n, err := strconv.ParseInt(args[1], 10, 64); err == nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
64 return time.Unix(n, 0).Format(args[0])
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
65 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
66 return "datefmt: " + err.Error()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
67 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
68 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
69
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
70 // zs dateparse <fmt> <date> -- returns unix time from the formatted date
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
71 func DateParse(args ...string) string {
23
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
72 if len(args) == 0 || len(args) > 2 {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
73 return "dateparse: invalid usage"
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
74 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
75 if d, err := time.Parse(args[0], args[1]); err != nil {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
76 return "dateparse: " + err.Error()
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
77 } else {
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
78 return strconv.FormatInt(d.Unix(), 10)
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
79 }
40f55059fbfa fixed output file names in html pages, fixed amber function bindings, replaced print command with build, fixed plugin functions, implemented zs and exec functions
zaitsev.serge
parents:
diff changeset
80 }
25
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
81
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
82 // zs wc <file> -- returns word count in the file (markdown, html or amber)
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
83 func WordCount(args ...string) int {
25
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
84 if os.Getenv("ZS_RECURSION") != "" {
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
85 return 0
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
86 }
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
87 if len(args) != 1 {
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
88 return 0
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
89 }
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
90 os.Setenv("ZS_RECURSION", "1")
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
91 out := &bytes.Buffer{}
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
92 if err := build(args[0], out, builtins(), globals()); err != nil {
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
93 return 0
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
94 }
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
95 if s, err := html2text.FromString(string(out.Bytes())); err != nil {
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
96 return 0
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
97 } else {
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
98 return len(strings.Fields(s))
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
99 }
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
100 }
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
101
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
102 // zs timetoread <file> -- returns number of minutes required to read the text
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
103 func TimeToRead(args ...string) int {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
104 wc := WordCount(args...)
26
d966bcb229c0 fixed math package
zaitsev.serge
parents: 25
diff changeset
105 return int(math.Floor(float64(wc)/200.0 + .5))
25
42b0a9fa5883 added word count and time to read functions
zaitsev.serge
parents: 23
diff changeset
106 }
31
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
107
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
108 // zs ls <dir> <regexp>
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
109 func List(args ...string) []string {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
110 if len(args) != 2 {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
111 return []string{}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
112 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
113
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
114 dir := args[0]
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
115 mask := args[1]
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
116
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
117 res := []string{}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
118 filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
119 if err != nil {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
120 return nil
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
121 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
122 if !info.IsDir() {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
123 if ok, err := filepath.Match(mask, info.Name()); ok && err == nil {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
124 res = append(res, path)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
125 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
126 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
127 return nil
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
128 })
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
129 return res
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
130 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
131
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
132 // zs sort <key> <files...>
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
133 func Sort(args ...string) []string {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
134 delim := -1
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
135 for i, s := range args {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
136 if s == "--" {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
137 delim = i
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
138 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
139 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
140 cmd := []string{"var", "title"}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
141 if delim != -1 {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
142 cmd = args[:delim]
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
143 args = args[delim+1:]
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
144 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
145
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
146 sorted := map[string][]string{}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
147 sortedKeys := []string{}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
148 for _, f := range args {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
149 params := append(cmd, f)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
150 out := bytes.NewBuffer(nil)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
151 run(os.Args[0], params, globals(), out)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
152 val := string(out.Bytes())
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
153 sorted[val] = append(sorted[val], f)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
154 sortedKeys = append(sortedKeys, val)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
155 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
156 log.Println(sortedKeys)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
157 sort.Strings(sortedKeys)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
158 if !asc {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
159 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
160
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
161 list := []string{}
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
162 for _, k := range sortedKeys {
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
163 vals := sorted[k]
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
164 sort.Strings(vals)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
165 list = append(list, vals...)
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
166 }
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
167 return list
b2f491299cee dead end with template functions
zaitsev.serge
parents: 26
diff changeset
168 }