本文整理汇总了Golang中path.Join函数的典型用法代码示例。如果您正苦于以下问题:Golang Join函数的具体用法?Golang Join怎么用?Golang Join使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Join函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetChain
func GetChain(ctx *cli.Context) (*core.ChainManager, common.Database, common.Database) {
dataDir := ctx.GlobalString(DataDirFlag.Name)
blockDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "blockchain"))
if err != nil {
Fatalf("Could not open database: %v", err)
}
stateDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "state"))
if err != nil {
Fatalf("Could not open database: %v", err)
}
extraDb, err := ethdb.NewLDBDatabase(path.Join(dataDir, "extra"))
if err != nil {
Fatalf("Could not open database: %v", err)
}
eventMux := new(event.TypeMux)
chainManager := core.NewChainManager(blockDb, stateDb, eventMux)
pow := ethash.New()
txPool := core.NewTxPool(eventMux, chainManager.State, chainManager.GasLimit)
blockProcessor := core.NewBlockProcessor(stateDb, extraDb, pow, txPool, chainManager, eventMux)
chainManager.SetProcessor(blockProcessor)
return chainManager, blockDb, stateDb
}
示例2: encode
func (fs *Datastore) encode(key datastore.Key) (dir, file string) {
safe := hex.EncodeToString(key.Bytes()[1:])
prefix := (safe + padding)[:fs.hexPrefixLen]
dir = path.Join(fs.path, prefix)
file = path.Join(dir, safe+extension)
return dir, file
}
示例3: DownloadByGoGet
func (n *Node) DownloadByGoGet(ctx *cli.Context, u *url.URL) error {
baseDir := path.Join(setting.HomeDir, ".gopm/temp/goget")
os.MkdirAll(baseDir, os.ModePerm)
defer func() {
os.RemoveAll(baseDir)
}()
oriGopath := os.Getenv("GOPATH")
os.Setenv("GOPATH", baseDir)
fmt.Println(baseDir)
defer func() {
os.Setenv("GOPATH", oriGopath)
}()
log.Debug("RUN 'go get %s'", n.RootPath)
_, stderr, err := base.ExecCmdDir(baseDir, "go", "get", n.RootPath)
if err != nil {
log.Error("Error occurs when 'go get" + n.RootPath + "'")
log.Error("\t" + stderr)
return errors.New(stderr)
}
tmpPath := path.Join(baseDir, "src", n.RootPath)
if !n.IsEmptyVal() {
base.ExecCmdDir(tmpPath, "git", "checkout", n.Value)
if err != nil {
log.Error("Error occurs when 'git checkout" + n.Value + "'")
log.Error("\t" + stderr)
return errors.New(stderr)
}
}
os.MkdirAll(path.Dir(n.InstallPath), os.ModePerm)
os.Rename(tmpPath, n.InstallPath)
return nil
}
示例4: listChart
// listChart enumerates all of the relevant files in a chart
func listChart(chartDir string) ([]string, error) {
var files []string
metadataFile := path.Join(chartDir, "Chart.yaml")
manifestDir := path.Join(chartDir, "manifests")
// check for existence of important files and directories
for _, path := range []string{chartDir, metadataFile, manifestDir} {
if _, err := os.Stat(path); os.IsNotExist(err) {
return nil, err
}
}
// add metadata file to front of list
files = append(files, metadataFile)
// add manifest files
walker := func(fname string, fi os.FileInfo, e error) error {
if e != nil {
log.Warn("Encounter error walking %q: %s", fname, e)
return nil
}
if filepath.Ext(fname) == ".yaml" {
files = append(files, fname)
}
return nil
}
filepath.Walk(manifestDir, walker)
return files, nil
}
示例5: listDirectories
// Lists all directories under "path" and outputs the results as children of "parent".
func listDirectories(dirpath string, parent string, recursive bool, output map[string]struct{}) error {
// Ignore if this hierarchy does not exist.
if !utils.FileExists(dirpath) {
return nil
}
entries, err := ioutil.ReadDir(dirpath)
if err != nil {
return err
}
for _, entry := range entries {
// We only grab directories.
if entry.IsDir() {
name := path.Join(parent, entry.Name())
output[name] = struct{}{}
// List subcontainers if asked to.
if recursive {
err := listDirectories(path.Join(dirpath, entry.Name()), name, true, output)
if err != nil {
return err
}
}
}
}
return nil
}
示例6: goListPkg
// goListPkg takes one package name, and computes all the files it needs to build,
// seperating them into Go tree files and uroot files. For now we just 'go list'
// but hopefully later we can do this programatically.
func goListPkg(name string) (*GoDirs, error) {
cmd := exec.Command("go", "list", "-json", name)
cmd.Env = append(os.Environ(), "CGO_ENABLED=0")
debug("Run %v @ %v", cmd, cmd.Dir)
j, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}
var p GoDirs
if err := json.Unmarshal([]byte(j), &p); err != nil {
return nil, err
}
debug("%v, %v %v %v", p, p.GoFiles, p.SFiles, p.HFiles)
for _, v := range append(append(p.GoFiles, p.SFiles...), p.HFiles...) {
if p.Goroot {
GorootFiles[path.Join(p.ImportPath, v)] = true
} else {
UrootFiles[path.Join(p.ImportPath, v)] = true
}
}
return &p, nil
}
示例7: Get
// Return the rootfs path for the id
// This will mount the dir at it's given path
func (a *Driver) Get(id, mountLabel string) (string, error) {
ids, err := getParentIds(a.rootPath(), id)
if err != nil {
if !os.IsNotExist(err) {
return "", err
}
ids = []string{}
}
// Protect the a.active from concurrent access
a.Lock()
defer a.Unlock()
count := a.active[id]
// If a dir does not have a parent ( no layers )do not try to mount
// just return the diff path to the data
out := path.Join(a.rootPath(), "diff", id)
if len(ids) > 0 {
out = path.Join(a.rootPath(), "mnt", id)
if count == 0 {
if err := a.mount(id, mountLabel); err != nil {
return "", err
}
}
}
a.active[id] = count + 1
return out, nil
}
示例8: createMigration
func createMigration(name string) string {
if name == "" {
return "invalid migration name"
}
wd, err := os.Getwd()
if err != nil {
return err.Error()
}
err = os.MkdirAll(path.Join(wd, kDbDir, kMgrDir), 0777)
if err != nil {
panic(err)
}
ts := time.Now().Unix()
fileName := path.Join(kDbDir, kMgrDir, fmt.Sprintf("%d_%s.go", ts, name))
f, err := os.OpenFile(path.Join(wd, fileName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
panic(err)
}
defer f.Close()
err = migrationTemplate.Execute(f, &Migration{
Timestamp: ts,
Name: name,
})
if err != nil {
panic(err)
}
return fmt.Sprintf("created migration '%s'", fileName)
}
示例9: Inject
// Inject the io.Reader at the given path. Note: do not close the reader
func (container *Container) Inject(file io.Reader, pth string) error {
// Return error if path exists
if _, err := os.Stat(path.Join(container.rwPath(), pth)); err == nil {
// Since err is nil, the path could be stat'd and it exists
return fmt.Errorf("%s exists", pth)
} else if !os.IsNotExist(err) {
// Expect err might be that the file doesn't exist, so
// if it's some other error, return that.
return err
}
// Make sure the directory exists
if err := os.MkdirAll(path.Join(container.rwPath(), path.Dir(pth)), 0755); err != nil {
return err
}
dest, err := os.Create(path.Join(container.rwPath(), pth))
if err != nil {
return err
}
if _, err := io.Copy(dest, file); err != nil {
return err
}
return nil
}
示例10: genSource
// genSource renders the given template to produce source code, which it writes
// to the given directory and file.
func genSource(dir, filename, templateSource string, args map[string]interface{}) {
sourceCode := revel.ExecuteTemplate(
template.Must(template.New("").Parse(templateSource)),
args)
// Create a fresh dir.
tmpPath := path.Join(revel.AppPath, dir)
err := os.RemoveAll(tmpPath)
if err != nil {
revel.ERROR.Println("Failed to remove dir:", err)
}
err = os.Mkdir(tmpPath, 0777)
if err != nil {
revel.ERROR.Fatalf("Failed to make tmp directory: %v", err)
}
// Create the file
file, err := os.Create(path.Join(tmpPath, filename))
defer file.Close()
if err != nil {
revel.ERROR.Fatalf("Failed to create file: %v", err)
}
_, err = file.WriteString(sourceCode)
if err != nil {
revel.ERROR.Fatalf("Failed to write to file: %v", err)
}
}
示例11: dictionary
func dictionary(file string) {
f, _ := os.OpenFile(path.Join(".", "data", file), os.O_SYNC|os.O_APPEND|os.O_RDWR, 0755)
defer f.Close()
scanner := bufio.NewScanner(f)
scanner.Split(bufio.ScanLines)
var n []string
for scanner.Scan() {
n = append(n, scanner.Text())
if len(n) == 0 {
break
}
}
w, _ := os.Create(path.Join(".", "data", file))
defer w.Close()
for i := 0; i < len(n); i++ {
f.WriteString(n[i] + "\n")
}
line := " this is the APPENDED text"
f.WriteString(line)
}
示例12: overlayRender
// overlayRender renders the image that corresponds to the given hash using the
// overlay filesystem.
// It writes the manifest in the specified directory and mounts an overlay
// filesystem from the cached tree of the image as rootfs.
func overlayRender(cfg RunConfig, img types.Hash, cdir string, dest string) error {
if err := writeManifest(cfg.CommonConfig, img, dest); err != nil {
return err
}
destRootfs := path.Join(dest, "rootfs")
if err := os.MkdirAll(destRootfs, 0755); err != nil {
return err
}
cachedTreePath := cfg.Store.GetTreeStoreRootFS(img.String())
overlayDir := path.Join(cdir, "overlay", img.String())
if err := os.MkdirAll(overlayDir, 0755); err != nil {
return err
}
upperDir := path.Join(overlayDir, "upper")
if err := os.MkdirAll(upperDir, 0755); err != nil {
return err
}
workDir := path.Join(overlayDir, "work")
if err := os.MkdirAll(workDir, 0755); err != nil {
return err
}
opts := fmt.Sprintf("lowerdir=%s,upperdir=%s,workdir=%s", cachedTreePath, upperDir, workDir)
opts = label.FormatMountLabel(opts, cfg.MountLabel)
if err := syscall.Mount("overlay", destRootfs, "overlay", 0, opts); err != nil {
return fmt.Errorf("error mounting: %v", err)
}
return nil
}
示例13: RenderPost
func (r Renderer) RenderPost(pc *PostContext, templates *template.Template) error {
err := os.MkdirAll(path.Join(r.OutputPath, pc.Slug), 0755)
if err != nil {
log.Panicf(err.Error())
}
outfile, err := os.Create(path.Join(r.OutputPath, pc.Slug, "index.html"))
if err != nil {
log.Panicf(err.Error())
}
err = templates.ExecuteTemplate(outfile, "post.html", pc)
if err != nil {
log.Panicf(err.Error())
}
// copy images
log.Printf("\"%s\": Using %d %s", pc.Slug, len(pc.Images), pluralize("image", len(pc.Images)))
for _, image := range pc.Images {
err = cp(image.SrcAbsPath, path.Join(r.OutputPath, pc.Slug, image.Filename))
if err != nil {
log.Panicf(err.Error())
}
}
log.Printf("\"%s\": Done rendering", pc.Slug)
return nil
}
示例14: RenderAll
func (r Renderer) RenderAll(site *SiteContext, posts []*Post) error {
templates := template.Must(
template.ParseGlob(path.Join(r.TemplatePath, "*.html")))
// ensure the output directory exists
err := os.MkdirAll(path.Join(r.OutputPath), 0755)
if err != nil {
return err
}
// copy assets
cpDir(path.Join(r.TemplatePath, "assets"), path.Join(r.OutputPath, "assets"))
// make the index page
index, err := os.Create(path.Join(r.OutputPath, "index.html"))
if err != nil {
log.Panicf(err.Error())
}
err = templates.ExecuteTemplate(index, "index.html", &IndexContext{site, posts, "Home", ""})
// gratuitous use of goroutines
// use a WaitGroup to ensure all goroutines get access to STDOUT
var wg sync.WaitGroup
for _, post := range posts {
wg.Add(1)
go func(site *SiteContext, post *Post) {
defer wg.Done()
pc := &PostContext{site, post, "../"}
r.RenderPost(pc, templates)
}(site, post)
}
wg.Wait()
return nil
}
示例15: Get
func (pfs *ProcFS) Get(k string) {
var uf = path.Join(procfsdir, "uptime")
switch k {
case PROCFS_SELF:
var selfdir = path.Join(procfsdir, "self")
if !exists(selfdir) {
return
}
fi, _ := os.Readlink(selfdir)
pfs.Self = fi
case PROCFS_UPTIME:
str, err := ioutil.ReadFile(uf)
if err == nil {
ss := strings.Fields(string(str))
if len(ss) >= 2 {
it, _ := strconv.ParseFloat(ss[0], 64)
pfs.Uptime = int(it)
}
}
case PROCFS_IDLETIME:
str, err := ioutil.ReadFile(uf)
if err == nil {
ss := strings.Fields(string(str))
if len(ss) >= 2 {
it, _ := strconv.ParseFloat(ss[1], 64)
pfs.Idletime = int(it)
}
}
case PROCFS_MOUNTS:
pfs.Mounts = getMounts(path.Join(procfsdir, "mounts"))
}
}