I want to store some files in appdata
path,but I don't know how to get it in golang.
It resides in user home folder, so you can get user folder and append AppData:
package main
import (
"fmt"
"os"
"runtime"
)
func UserHomeDir() string {
if runtime.GOOS == "windows" {
home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
if home == "" {
home = os.Getenv("USERPROFILE")
}
return home
}
return os.Getenv("HOME")
}
func main() {
homeDir := UserHomeDir()
fmt.Println(homeDir + "\\AppData")
}