Skip to content

Instantly share code, notes, and snippets.

@akira093
Created April 25, 2018 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akira093/0603b4e522e14d2770a3d655d297f34c to your computer and use it in GitHub Desktop.
Save akira093/0603b4e522e14d2770a3d655d297f34c to your computer and use it in GitHub Desktop.
In golang, there are two way of joining filepath.
package main
import (
"fmt"
"os/user"
"path"
"path/filepath"
)
var dbPath = "/.config/go-wol/bolt.db"
func main() {
u, err := user.Current()
panicOnError(err)
var home = u.HomeDir
fmt.Print("path: ")
fmt.Println(path.Join(home, dbPath))
fmt.Print("filepath: ")
fmt.Println(filepath.Join(home, dbPath))
}
func panicOnError(err error) {
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment