Golang: HTTP Client & Server with Query Params

Client func TestDelete(id string, registered bool) { path := “http://localhost:8085/v1/shops” // Create client client := &http.Client{} // Create request req, err := http.NewRequest(“DELETE”, path, nil) if err != nil { fmt.Println(err) return } q := req.URL.Query() q.Add(“id”, r.UID) q.Add(“registered”, strconv.FormatBool(registered)) req.URL.RawQuery = q.Encode() fmt.Println(req.URL.String()) // Fetch Request resp, err := client.Do(req) if err != nil … More Golang: HTTP Client & Server with Query Params

Golang: Switch-case does not fall through!

Unlike C/C++ switch-case statements, Golang switch case does not fall through. package main import ( “fmt” ) func main() { fmt.Print(“Go runs on “) os := “darwin” switch os { case “darwin”: case “linux”: fmt.Println(“Linux.”) default: // freebsd, openbsd, // plan9, windows… fmt.Printf(“%s.\n”, os) } } The above code does not print anything! package main … More Golang: Switch-case does not fall through!

Golang Type Assertions: Dynamic Type Checking

Type Assertions Go supports dynamic type checking of variables. If the type of a variable is unknown till run-time, type assertions can run a validity check. // getRequest definition struct getRequest { name string } // Declare a void (anonymous) type variable request interface{} // Checking if variable request is not nil && // has … More Golang Type Assertions: Dynamic Type Checking