widness
2/24/2018 - 8:12 AM

Get Request Method

How to get the method of the request

func uploadVideo(w http.ResponseWriter, r *http.Request) {
  
	fmt.Println("method:", r.Method)
	if r.Method == "GET" {  // On GET
	  
	  params := mux.Vars(r) // Get params (http://video/{id})
	  id := params["id"]    // Return string 
    /* ... */
    
	} else {                // On POST
	  r.ParseMultipartForm(0)
	  inputBlabla := r.FormValue("blabla")
	  inputThings := r.FormValue("things")
	  /* ... */
	  
	  var appendVideo AppendVideo
  	var err error
  
  	err = json.NewDecoder(r.Body).Decode(&appendVideo)
  
  	gotFirst := getVideoFunc(appendVideo.First)
	}
}