在go中处理POST请求

I am having trouble decoding POST request with gorilla/schema.

My code is creating a basic http server:

package main

import (
    "net/http"
    "gorilla/schema"
    "fmt"
    "log"
)

type Payload struct{
    slot_temp string
    data      string
    time      string
    device    string
    signal    string
}

func MyHandler(w http.ResponseWriter, r *http.Request) {
    err := r.ParseForm()

    if err != nil {
        fmt.Println("Error parsing form")
    }

    p := new(Payload)
    decoder := schema.NewDecoder()

    fmt.Println(r.PostForm)

    err = decoder.Decode(p, r.Form)

    if err != nil {
        fmt.Println("Error decoding")
    }
    fmt.Println(p.slot_temp)

}

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/", MyHandler)
    log.Fatal(http.ListenAndServe(":8082", mux))
}

I test i with

curl -X POST -H 'application/x-www-form-urlencoded' -d "slot_temp=34&data=22ltime=1495092909&device=1B3C29&signal=18.63" localhost:8082

But I get the following output

map[device:[1B3C29] signal:[18.63] slot_temp:[34] data:[22] time:[1495092909]]

// content of map and a blank line instead if the value of p.slot_temp

The content of the structure field is never printed.

I guess there is an issue with the decoder, but I can't figure out what is wrong.

Thanks

Change your struct fields name to uppercase. Your decoder is external package and it doesn't have access to your struct

package main

import (
    "fmt"
    "log"
    "net/http"

    "github.com/gorilla/schema"
)

type Payload struct {
    Slot_temp string
    Data      string
    Time      string
    Device    string
    Signal    string
}

func MyHandler(w http.ResponseWriter, r *http.Request) {
    err := r.ParseForm()

    if err != nil {
        fmt.Println("Error parsing form")
    }

    p := new(Payload)
    decoder := schema.NewDecoder()

    fmt.Println(r.PostForm)

    err = decoder.Decode(p, r.Form)

    if err != nil {
        fmt.Println("Error decoding")
    }
    fmt.Println(p.Slot_temp)

}

func main() {
    mux := http.NewServeMux()
    mux.HandleFunc("/", MyHandler)
    log.Fatal(http.ListenAndServe(":8082", mux))
}