/
examples.go
51 lines (43 loc) · 1.32 KB
/
examples.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package examples
import (
"fmt"
"os"
"path/filepath"
"regexp"
iom "github.com/grokify/gotilla/io/ioutilmore"
)
const (
HandlersDir = "github.com/grokify/chathooks/docs/handlers"
Examples = "aha,appsignal,apteligent,circleci,codeship,confluence,datadog,deskdotcom,enchant,gosquared,heroku,librato,magnumci,marketo,opsgenie,papertrail,pingdom,raygun,runscope,semaphore,statuspage,travisci,userlike,victorops"
)
func AbsDirGopath(dir string) string {
return filepath.Join(os.Getenv("GOPATH"), "src", dir)
}
func DocsHandlersDirInfo() ([]string, []string, error) {
dirname := AbsDirGopath(HandlersDir)
fmt.Println(dirname)
dirs := []string{}
exampleFiles := []string{}
sdirs, _, err := iom.ReadDirSplit(dirname, true)
if err != nil {
return dirs, exampleFiles, err
}
for _, sdir := range sdirs {
fmt.Printf("SDIR: %v\n", sdir.Name())
absSubDir := filepath.Join(dirname, sdir.Name())
files, err := iom.DirEntriesReSizeGt0(absSubDir,
regexp.MustCompile(`^event-example_.+\.(json|txt)$`))
if err != nil {
return dirs, exampleFiles, err
}
if len(files) > 0 {
dirs = append(dirs, sdir.Name())
for _, f := range files {
fmt.Printf("FILE: %v\n", f.Name())
exFilepath := filepath.Join(absSubDir, f.Name())
exampleFiles = append(exampleFiles, exFilepath)
}
}
}
return dirs, exampleFiles, nil
}