@@ -2,6 +2,7 @@ package config
2
2
3
3
import (
4
4
"context"
5
+ "fmt"
5
6
"io"
6
7
"io/ioutil"
7
8
"log"
@@ -10,8 +11,10 @@ import (
10
11
"os"
11
12
"path/filepath"
12
13
14
+ "github.com/b4b4r07/afx/pkg/data"
13
15
"github.com/b4b4r07/afx/pkg/errors"
14
16
"github.com/b4b4r07/afx/pkg/state"
17
+ "github.com/b4b4r07/afx/pkg/templates"
15
18
"github.com/h2non/filetype"
16
19
"github.com/mholt/archiver"
17
20
)
@@ -26,7 +29,12 @@ type HTTP struct {
26
29
Plugin * Plugin `yaml:"plugin"`
27
30
Command * Command `yaml:"command"`
28
31
29
- DependsOn []string `yaml:"depends-on"`
32
+ DependsOn []string `yaml:"depends-on"`
33
+ Templates Templates `yaml:"templates"`
34
+ }
35
+
36
+ type Templates struct {
37
+ Replacements map [string ]string `yaml:"replacements"`
30
38
}
31
39
32
40
// Init is
@@ -55,6 +63,16 @@ func (c HTTP) call(ctx context.Context) error {
55
63
}
56
64
defer resp .Body .Close ()
57
65
66
+ log .Printf ("[DEBUG] response code: %d" , resp .StatusCode )
67
+ switch resp .StatusCode {
68
+ case 200 , 301 , 302 :
69
+ // go
70
+ case 404 :
71
+ return fmt .Errorf ("%s: %d Not Found in %s" , c .GetName (), resp .StatusCode , c .URL )
72
+ default :
73
+ return fmt .Errorf ("%s: %d %s" , c .GetName (), resp .StatusCode , http .StatusText (resp .StatusCode ))
74
+ }
75
+
58
76
os .MkdirAll (c .GetHome (), os .ModePerm )
59
77
dest := filepath .Join (c .GetHome (), filepath .Base (c .URL ))
60
78
file , err := os .Create (dest )
@@ -84,6 +102,17 @@ func (c HTTP) Install(ctx context.Context, status chan<- Status) error {
84
102
// Go installing step!
85
103
}
86
104
105
+ url , err := templates .New (data .New (data .WithPackage (c ))).
106
+ Replace (c .Templates .Replacements ).
107
+ Apply (c .URL )
108
+ if err != nil {
109
+ return err
110
+ }
111
+ if url != c .URL {
112
+ log .Printf ("[DEBUG] %s: templating url %s" , c .GetName (), url )
113
+ c .URL = url
114
+ }
115
+
87
116
ctx , cancel := context .WithCancel (ctx )
88
117
defer cancel ()
89
118
0 commit comments