-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.go
37 lines (32 loc) · 955 Bytes
/
utils.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
package plugins
import (
"fmt"
"github.com/pterm/pterm"
"os"
"text/template"
)
type PluginFileParams struct {
Domain string
RelaySecretKey string
}
func CreatePluginFile(pluginFilePath, pluginTemplate string, pluginFileParams *PluginFileParams) {
pluginFile, err := os.Create(pluginFilePath)
if err != nil {
pterm.Println()
pterm.Error.Println(fmt.Sprintf("Failed to create plugin file: %v", err))
os.Exit(1)
}
defer pluginFile.Close()
pluginTmpl, err := template.New("plugin").Parse(pluginTemplate)
if err != nil {
pterm.Println()
pterm.Error.Println(fmt.Sprintf("Failed to parse plugin template: %v", err))
os.Exit(1)
}
err = pluginTmpl.Execute(pluginFile, struct{ Domain, RelaySecretKey string }{Domain: pluginFileParams.Domain, RelaySecretKey: pluginFileParams.RelaySecretKey})
if err != nil {
pterm.Println()
pterm.Error.Println(fmt.Sprintf("Failed to execute plugin template: %v", err))
os.Exit(1)
}
}