-
Notifications
You must be signed in to change notification settings - Fork 0
/
poster.go
52 lines (42 loc) · 1.11 KB
/
poster.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
52
package poster
import (
"log/slog"
"os"
"text/template"
"github.com/golangast/gentil/utility/ff"
"github.com/golangast/goservershell/cmd/rest/resttemp"
"github.com/golangast/goservershell/internal/loggers"
"github.com/Masterminds/sprig/v3"
)
func Poster(d Fielddata, types, folderdir string) {
logger := loggers.CreateLogger()
handlerfile, err := gentil.Filefolder("./src/handler/restful/"+types+"/"+folderdir+d.Lowercasename, d.Lowercasename+".go")
if err != nil {
logger.Error(
"trying to create handler file",
slog.String("error: ", err.Error()),
)
}
err = Writetemplateslice(resttemp.Posted(), handlerfile, d)
if err != nil {
logger.Error(
"trying to update router.html",
slog.String("error: ", err.Error()),
)
}
}
type Fielddata struct {
Fields []string
CheckFields []string
Lowercasename string
Uppercasename string
}
func Writetemplateslice(temp string, f *os.File, d Fielddata) error {
functionMap := sprig.TxtFuncMap()
dbmb := template.Must(template.New("t").Funcs(functionMap).Parse(temp))
err := dbmb.Execute(f, d)
if err != nil {
return err
}
return nil
}