Home > Software design >  How to add a trailing slash
How to add a trailing slash

Time:04-24

Im making a webapp and I'm trying to write views/layouts/*.html using two vars but filepath.Join only gives views/layouts instead of views/layouts/

var (
    LayoutDir string = filepath.Join("views","layouts")
    TemplateExt string = "*.html"
)

then calling

f, err:= filepath.Glob(LayoutDir   TemplateExt)

And so f contains views/layouts*.html instead of views/layouts/*.html How should I solve this and is it a good practice to use filepath.Join in this case?

CodePudding user response:

f, err:= filepath.Glob(filepath.Join(LayoutDir, TemplateExt)) should do the trick

or

LayoutDir string = filepath.Join("views", "layouts") string(filepath.Separator)

or

LayoutDir string = filepath.Join("views", "layouts") string(os.PathSeparator)

  • Related