Has anyone used go as a serverless function via vercel, I have a single go function which cannot read my txt file (error in console: open file.txt: cant find the file), I put the file in the API folder. It's probably more of a Vercel question, but i don't know where else to ask
Some notes: -I'm only using the 'vercel dev' command for local development right now, but the go function is working
-don't want to use embed package in go, because I'm going to add more txt files later on
-files has to be hidden from frontend/client (i am using svelte)
-txt files are small (about 100kb), so AWS S3 storage shouldn't be required
what I already tried: putting the file in root directory, and naming the path without api
func Handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Running GO function")
byto, err := createByteChunk("/api/dataxx.txt")
w.Write("Hello")
}
func createByteChunk(path string) ([][]byte, error) {
file, err := os.Open(path)// "/api/dataxx.txt" gets passed in the main function, tried "/dataxx.txt" too
if err != nil {
return nil, err
}
defer file.Close()
var byte_arr2 [][]byte
var byte_arr []byte
scanner := bufio.NewScanner(file)
for scanner.Scan() {
byte_arr = []byte(scanner.Text())
byte_arr2 = append(byte_arr2, byte_arr)
}
return byte_arr2, scanner.Err()
}
folder structure: