Ok so this question has been asked before and I believe I have looked through all of them to and tested the answers but I will explain how each one doesn't match my case. I might have missed the answer in one of those but I read each one and attempted to see if it could fit my case
How to import local packages in go? I believe my imports follow the structure of the answer
Go build: "Cannot find package" (even though GOPATH is set) I'm not sure if this one is fully pertinent but I don't think it's the same error.
Golang - Why can't I import local package in GOPATH/src/project but can in home directory? My import path isn't relative so this question isn't pertinent.
My error is simple:
cannot find package "api/handlers" in any of:
C:\Go\src\api\handlers (from $GOROOT)
C:\Projects\Go\src\api\handlers (from $GOPATH)`
My project structure is as follows:
src
|
--api
|
-- index.go
-- repo.go
|
github.com
|
main.go
Environment variables:
$GOPATH : C:\Projects\Go
$GOROOT : C:\Go\
index and repo.go both have the same package name, imports, and just an empty function:
package handlers
import (
"net/http"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
}
My main.go:
package main
import (
"fmt"
"log"
"net/http"
"api/handlers"
)
func main() {
http.HandleFunc("/api/index", handlers.indexHandler)
http.HandleFunc("/api/repo", handlers.repoHandler)
log.Fatal(http.ListenAndServer("localhost:8080", nil))
}