-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_module.go
51 lines (37 loc) · 1.02 KB
/
handler_module.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 main
import (
"fmt"
"net/http"
"strings"
"text/template"
"go-initializr/common"
)
type body struct {
search string
}
func (app *Config) handlerGetModules(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
param := query.Get("search")
arr := strings.Split(param, " ")
modules, err := app.service.GetModules(arr...)
if err != nil {
common.ErrorJSON(w, 400, fmt.Sprintf("%v", err))
return
}
common.ResponseJSON(w, 200, modules)
}
func (app *Config) handlerModules(w http.ResponseWriter, r *http.Request) {
param := r.PostFormValue("search")
arr := strings.Split(param, " ")
modules, err := app.service.GetModules(arr...)
if err != nil {
common.ErrorJSON(w, 400, fmt.Sprintf("%v", err))
return
}
tmpl, _ := template.New("title").Parse(fmt.Sprintf("<p style='text-align:center'><strong>%s</strong>\n</p>", "New dependencies: "))
tmpl.Execute(w, nil)
for _, element := range modules {
tmpl, _ := template.New("element").Parse(fmt.Sprintf("%s\n", element))
tmpl.Execute(w, nil)
}
}