I am trying to build an API with golang. To get started I am just trying to send some json data when I visit http://localhost:8085/search but all I am viewing in the browser is null
.
I got this example from a Medium post
package main
import (
"log"
"net/http"
"encoding/json"
"github.com/gorilla/mux"
)
type Place struct {
Location string `json:"123 Houston st"`
Name string `json:"Ricks Barber Shop"`
Body string `json:"this is the best barber shop in the world"`
}
var place []Place
func search(write http.ResponseWriter, req *http.Request) {
write.Header().Set("Content-Type", "application/json")
json.NewEncoder(write).Encode(place)
}
func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/search", search).Methods("GET")
log.Fatal(http.ListenAndServe(":8085", router))
}