Skip to content

Commit cf0adaa

Browse files
committed
vuex
1 parent 6b08dd6 commit cf0adaa

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6+
"github.com/gorilla/mux"
67
"io/ioutil"
78
"log"
89
"net/http"
10+
"text/template"
911
)
1012

1113
type ConfigFile struct {
@@ -28,11 +30,13 @@ func main() {
2830
if err != nil {
2931
log.Fatal(err)
3032
}
33+
router := mux.NewRouter()
3134

3235
for _, response := range configFile.Responses {
3336
closureResponse := response
3437
fmt.Println(closureResponse.Path, "will return status", closureResponse.Status, "with body from file ", closureResponse.JsonBody)
35-
http.HandleFunc(closureResponse.Path, func(writer http.ResponseWriter, request *http.Request) {
38+
router.HandleFunc(closureResponse.Path, func(writer http.ResponseWriter, request *http.Request) {
39+
vars := mux.Vars(request)
3640
if 200 != closureResponse.Status {
3741
writer.WriteHeader(closureResponse.Status)
3842
}
@@ -41,8 +45,11 @@ func main() {
4145
if err != nil {
4246
log.Fatal(err)
4347
}
44-
writer.Write(jsonBytes)
48+
49+
t := template.Must(template.New("letter").Parse(string(jsonBytes)))
50+
_ = t.Execute(writer, vars)
4551
})
4652
}
53+
http.Handle("/", router)
4754
log.Fatal(http.ListenAndServe(configFile.Addr, nil))
4855
}

0 commit comments

Comments
 (0)