-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
39 lines (30 loc) · 796 Bytes
/
main.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
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"github.com/hashicorp/hcl2/hclwrite"
muxtrace "gopkg.in/DataDog/dd-trace-go.v1/contrib/gorilla/mux"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
func homePage(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to the HCL Format !")
}
func format(w http.ResponseWriter, r *http.Request) {
in, _ := ioutil.ReadAll(r.Body)
fmt.Fprintf(w, string(hclwrite.Format([]byte(in))))
}
func handleRequests() {
myRouter := muxtrace.NewRouter().StrictSlash(true)
myRouter.HandleFunc("/", homePage)
myRouter.HandleFunc("/format", format).Methods("POST")
if err := http.ListenAndServe(":3000", myRouter); err != nil {
log.Fatal(err)
}
}
func main() {
tracer.Start()
defer tracer.Stop()
handleRequests()
}