Should I get an error?

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"path/filepath"

	"gitlab.com/me/myawesomeapp/appconfig"

	yaml "gopkg.in/yaml.v2"
)

func init() {
	filename, err1 := filepath.Abs("config/config.yml") // a wrong package used
	if err1 != nil {
		log.Fatal(err1)
	}}
    ...

I didn’t get any error on err1 - should I get it?

1 Like

What do you mean by “wrong package used”? filepath has a function Abs() whichs signature allows to be called exactly like that, and it will create an absolute path from the relative one you gave it.

I’m not sure what kind of error you expect here.

1 Like

I meant there is no config package in my project gitlab.com/me/myawesomeapp, but there is an appconfig instead.Theafore I should use the appconfig in

filename, err1 := filepath.Abs("appconfig/config.yml")

and I expected an error there. Now I realize that filepath.Abs returns only absolute path, but what kind of error the filepath.Abs can return then?

1 Like

filepath.Abs() is not related to your applications/packages structure, its just about filepathes.

And it will return an error whenever os.Getwd() would return an error, but only if the path isn’t already absolute, as you can see in the code:

https://golang.org/src/path/filepath/path.go?s=6981:7161#L244

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.