Created
April 25, 2018 11:42
-
-
Save akira093/0603b4e522e14d2770a3d655d297f34c to your computer and use it in GitHub Desktop.
In golang, there are two way of joining filepath.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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