1
Within my project I have 2 files, main.go
and price.go
; in my file main.go
within the function main()
i tried calling a file function price
which is exportable (starts with uppercase letter), and when trying to execute I get the error that the function was not defined;
./main.go:13:30: United States: Getprice
Code:
main.go:
package main
import ( ... )
func main() {
router := mux.NewRouter()
// Router registry for "/price" endpoint
router.HandleFunc("/price", GetPrice).Methods("POST")
http.ListenAndServe(":8080", router)
}
price.go:
package main
import (...)
// Price represent all fields in prices request
type Price struct {
SKU string `json:"sku"`
SellerID string `json:"seller_id"`
}
// GetPrice retrieve a json response to requested price
func GetPrice(writter http.ResponseWriter, request *http.Request) {
fmt.Println("Hello! GET PRICE!")
}
Even declaring an "exportable" function because I keep getting this error?
I don’t see any problem, you’re using the
go run
? Use thego build
orgo run *.go
.– Inkeliz
@Inkeliz the problem was
run
as you commented, I was running onlygo run main.go
, when I executedgo run *.go
worked. Please put as answer so I can mark as solved.– RFL