35 lines
613 B
Go
35 lines
613 B
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func index(w http.ResponseWriter, r *http.Request) {
|
|
formatRequest(r)
|
|
fmt.Fprintf(w, "Hello go!\n")
|
|
}
|
|
|
|
func formatRequest(r *http.Request) {
|
|
|
|
var opt Option
|
|
err := json.NewDecoder(r.Body).Decode(&opt)
|
|
if err != nil {
|
|
fmt.Printf("Error: %s\n", err)
|
|
}
|
|
|
|
fmt.Println("Option type:", opt.OptType)
|
|
fmt.Println("Strike:", opt.Strike)
|
|
fmt.Println("Expiry date:", opt.ExpiryDate.Format("2006-01-02"))
|
|
|
|
for k, v := range r.Header {
|
|
fmt.Printf("%v: %v\n", k, v)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
http.HandleFunc("/", index)
|
|
http.ListenAndServe(":8080", nil)
|
|
}
|