Access HTTP response as string in Go

I’d like to parse the response of a web request, but I’m getting trouble accessing it as string. func main() { resp, err := http.Get(“http://google.hu/”) if err != nil { // handle error } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) ioutil.WriteFile(“dump”, body, 0600) for i:= 0; i < len(body); i++ { fmt.Println( body[i] ) // … Read more

Import cycle not allowed

I have a problem with import cycle not allowed It appears when I am trying to test my controller. Here is the output: can’t load package: import cycle not allowed package project/controllers/account imports project/controllers/base imports project/components/mux imports project/controllers/account import cycle not allowed package project/controllers/account imports project/controllers/base imports project/components/mux imports project/controllers/account import cycle not allowed package … Read more

What is the shortest way to simply sort an array of structs by (arbitrary) field names?

I just had a problem where I had an array of structs, e.g. package main import “log” type Planet struct { Name string `json:”name”` Aphelion float64 `json:”aphelion”` // in million km Perihelion float64 `json:”perihelion”` // in million km Axis int64 `json:”Axis”` // in km Radius float64 `json:”radius”` } func main() { var mars = new(Planet) … Read more