I'm trying to create a go app that will display the users IP.
I can't figure out my Log Console error:
go:14: not enough arguments in call to getJsonRes
Go app code:
package main
import (
"encoding/json"
"net/http"
"fmt"
)
type Addrs struct {
ip string
}
func handler(w http.ResponseWriter, r *http.Request) {
response, err := getJsonRes()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
fmt.Fprintf(w, string(response))
}
func main() {
http.HandleFunc("/", handler)
}
func getJsonRes(r *http.Request)([]byte, error ) {
ip := Addrs{ r.RemoteAddr }
return json.MarshalIndent(ip, "", " ")
}