当前位置: 首页>>代码示例>>Golang>>正文


Golang Ns.Create方法代码示例

本文整理汇总了Golang中github.com/zenoss/rog-go/new9p/client.Ns.Create方法的典型用法代码示例。如果您正苦于以下问题:Golang Ns.Create方法的具体用法?Golang Ns.Create怎么用?Golang Ns.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/zenoss/rog-go/new9p/client.Ns的用法示例。


在下文中一共展示了Ns.Create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: mkone

// Create a single directory on remote server
func mkone(ns *g9pc.Ns, fname string) {
	file, err := ns.Create(fname, g9p.OREAD, 0777|g9p.DMDIR)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error creating directory %s: %s\n", fname, err)
		return
	}
	file.Close()
}
开发者ID:zenoss,项目名称:rog-go,代码行数:9,代码来源:cl.go

示例2: writeone

// Write the string s to remote file f. Create f if it doesn't exist
func writeone(ns *g9pc.Ns, fname, s string) {
	file, err := ns.Open(fname, g9p.OWRITE|g9p.OTRUNC)
	if err != nil {
		file, err = ns.Create(fname, g9p.OWRITE, 0666)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error opening %s: %v\n", fname, err)
			return
		}
	}
	defer file.Close()

	m, err := file.Write([]byte(s))
	if err != nil {
		fmt.Fprintf(os.Stderr, "error writing to %s: %s\n", fname, err)
		return
	}

	if m != len(s) {
		fmt.Fprintf(os.Stderr, "short write %s\n", fname)
		return
	}
}
开发者ID:zenoss,项目名称:rog-go,代码行数:23,代码来源:cl.go

示例3: cmdput

// Copy a local file to remote server
func cmdput(ns *g9pc.Ns, s []string) {
	var from, to string
	switch len(s) {
	case 1:
		_, to = path.Split(s[0])
		to = normpath(to)
		from = s[0]
	case 2:
		from, to = s[0], normpath(s[1])
	default:
		fmt.Fprintf(os.Stderr, "incorrect arguments; usage: put local [remote]\n")
	}

	fromfile, err := os.Open(from)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error opening %s for reading: %s\n", from, err)
		return
	}
	defer fromfile.Close()

	file, err := ns.Open(to, g9p.OWRITE|g9p.OTRUNC)
	if err != nil {
		file, err = ns.Create(to, g9p.OWRITE, 0666)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
			return
		}
	}
	fmt.Fprintf(os.Stderr, "opened file ok\n")
	defer file.Close()
	n, err := Copy(file, fromfile)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error copying file: %v (%d bytes copied)\n", err, n)
	}
	fmt.Fprintf(os.Stderr, "copied %d bytes\n", n)
}
开发者ID:zenoss,项目名称:rog-go,代码行数:37,代码来源:cl.go


注:本文中的github.com/zenoss/rog-go/new9p/client.Ns.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。