forked from yottadynamics/kickstart-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkickstart_generator.go
52 lines (42 loc) · 1.17 KB
/
kickstart_generator.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 main
import (
"fmt"
"html/template"
"io/ioutil"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", Index)
router.HandleFunc("/status", Status)
router.HandleFunc("/ks_generate/", ks_generate)
log.Fatal(http.ListenAndServe(":8080", router))
}
func Index(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Welcome to Kickstart File Generator")
}
func Status(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "API is up and running")
}
func check_error(err error) {
if err != nil {
panic(err)
}
}
func ks_generate(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
check_error(err)
tmpl_file := "ks.tmpl"
tp, err := ioutil.ReadFile(tmpl_file)
check_error(err)
data := make(map[string]string)
for i, j := range r.Form {
data[i] = j[0]
}
t, err := template.New("index").Parse(string(tp))
check_error(err)
err = t.Execute(w, data)
check_error(err)
}