go - Golang cannot write file into directory -


(i'm new go)

hi there, trying write file directory using go.

func (p *page) save() error {     filepath := derivepath(p.title)     fmt.println(filepath)     content, _ := json.marshalindent(p, "", "    ")     err := ioutil.writefile(filepath, content, 0600)     return err } 

this code. error occurs in line 5, saying

open data/testpage.json: system cannot find path specified. 

i tried creating file before writing os.create, doesn't work either.

loading directory data works fine, writing new files directory fails.

i don't understand why not working. know not information, don't know else need.

thanks answers in advance!

edit: project structure:

│   .gitignore │   .project │ ├───bin │       main.exe │ ├───data │       welcome.json │ ├───pkg │   └───windows_amd64 │           page.a │ ├───src │   ├───main │   │       main.go │   │ │   └───page │           page.go │           page_test.go │ └───templates         view.html 

reading data/welcome.json works fine (using io/ioutils.readfile)

the source available on https://gitlab.com/thyaris/wiki

console output

d:\gitworkspaces\wiki\wiki>go test -v page === run   testsave data/testpage.json --- fail: testsave (0.00s)         page_test.go:15: open data/testpage.json: system cannot find path specified.         page_test.go:19: 'testpage.json' not created === run   testloadpage --- fail: testloadpage (0.00s)         page_test.go:26: error while loading         page_test.go:32: file content did not match === run   testdelete --- pass: testdelete (0.00s) fail exit status 1 fail    page    0.094s 

your problem here test engine not running executable working directory expect. instead of using working directory defined shell or ide, setting source directory of code being tested. (i had bite me once, long ago :) had forgotten that...)

the simple solution change derivepath can set prefix externally, change path need @ beginning of tests. there other (possibly better?) solutions of course.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -