/
adapter.go
45 lines (38 loc) · 1.22 KB
/
adapter.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
package zap
import (
"log"
"os"
"path"
"github.com/moomerman/zap/adapter"
"github.com/moomerman/zap/adapter/buffalo"
"github.com/moomerman/zap/adapter/hugo"
"github.com/moomerman/zap/adapter/phoenix"
"github.com/moomerman/zap/adapter/rails"
"github.com/moomerman/zap/adapter/static"
)
// GetAdapter returns the corresponding adapter for the given
// host/dir combination
func GetAdapter(host, dir string) (adapter.Adapter, error) {
_, err := os.Stat(path.Join(dir, "mix.exs"))
if err == nil {
log.Println("[app]", host, "using the phoenix adapter (found mix.exs)")
return phoenix.New(host, dir), nil
}
_, err = os.Stat(path.Join(dir, "Gemfile"))
if err == nil {
log.Println("[app]", host, "using the rails adapter (found Gemfile)")
return rails.New(host, dir), nil
}
_, err = os.Stat(path.Join(dir, ".buffalo.dev.yml"))
if err == nil {
log.Println("[app]", host, "using the buffalo adapter (found .buffalo.dev.yml)")
return buffalo.New(host, dir), nil
}
_, err = os.Stat(path.Join(dir, "config.toml"))
if err == nil {
log.Println("[app]", host, "using the hugo adapter (found config.toml)")
return hugo.New(host, dir), nil
}
log.Println("[app]", host, "using the static adapter")
return static.New(dir)
}