• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang g9pc.Client类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中code/google/com/p/rog-go/go9p/g9pc.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: lsone

func lsone(c *g9pc.Client, s string, long bool) {
	st, err := c.FStat(normpath(s))
	if err != nil {
		fmt.Fprintf(os.Stderr, "error stat: %s\n", err)
		return
	}
	if st.Mode&g9p.DMDIR != 0 {
		file, err := c.FOpen(s, g9p.OREAD)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error opening dir: %s\n", err)
			return
		}
		defer file.Close()
		for {
			d, err := file.Readdir(0)
			if err != nil {
				fmt.Fprintf(os.Stderr, "error reading dir: %s\n", err)
			}
			if d == nil || len(d) == 0 {
				break
			}
			for _, dir := range d {
				if long {
					fmt.Fprintf(os.Stdout, "%s\n", dirtostr(dir))
				} else {
					os.Stdout.WriteString(dir.Name + "\n")
				}
			}
		}
	} else {
		fmt.Fprintf(os.Stdout, "%s\n", dirtostr(st))
	}
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:33,代码来源:cl.go


示例2: interactive

func interactive(c *g9pc.Client) {
	reader, ok := bufio.NewReaderSize(os.Stdin, 8192)
	if ok != nil {
		fmt.Fprintf(os.Stderr, "can't create reader buffer: %s\n", ok)
	}
	done := make(chan error)
	go func() {
		e := c.Wait()
		fmt.Printf("wait finished (%v)\n", e)
		done <- e
	}()
loop:
	for {
		select {
		case e := <-done:
			fmt.Fprintf(os.Stderr, "server: %v\n", e)
			break loop
		default:
		}
		fmt.Print(*prompt)
		line, ok := reader.ReadSlice('\n')
		if ok != nil {
			fmt.Fprintf(os.Stderr, "exiting...\n")
			break
		}
		str := strings.TrimSpace(string(line))
		// TODO: handle larger input lines by doubling buffer
		in := strings.Split(str, "\n")
		for i := range in {
			if len(in[i]) > 0 {
				cmd(c, in[i])
			}
		}
	}
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:35,代码来源:cl.go


示例3: rmone

// Remove f from remote server
func rmone(c *g9pc.Client, f string) {
	fname := normpath(f)

	err := c.FRemove(fname)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error in stat %s: %s\n", fname, err)
		return
	}
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:10,代码来源:cl.go


示例4: mkone

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


示例5: walkone

func walkone(c *g9pc.Client, s string) {
	ncwd := normpath(s)
	_, err := c.FWalk(ncwd)
	if err != nil {
		fmt.Fprintf(os.Stderr, "walk error: %s\n", err)
		return
	}
	cwd = ncwd
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:9,代码来源:cl.go


示例6: statone

// Stat the remote file f
func statone(c *g9pc.Client, f string) {
	fname := normpath(f)

	stat, err := c.FStat(fname)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error in stat %s: %s\n", fname, err)
		return
	}
	fmt.Fprintf(os.Stdout, "%s\n", stat)
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:11,代码来源:cl.go


示例7: cmdput

// Copy a local file to remote server
func cmdput(c *g9pc.Client, 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, ferr := c.FOpen(to, g9p.OWRITE|g9p.OTRUNC)
	if ferr != nil {
		file, ferr = c.FCreate(to, 0666, g9p.OWRITE)
		if ferr != nil {
			fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
			return
		}
	}
	defer file.Close()

	buf := make([]byte, 8192)
	for {
		n, oserr := fromfile.Read(buf)
		if oserr != nil && oserr != io.EOF {
			fmt.Fprintf(os.Stderr, "error reading %s: %s\n", from, oserr)
			return
		}

		if n == 0 {
			break
		}

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

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


示例8: cmdget

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

	tofile, err := os.Create(to)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
		return
	}
	defer tofile.Close()

	file, ferr := c.FOpen(from, g9p.OREAD)
	if ferr != nil {
		fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
		return
	}
	defer file.Close()

	buf := make([]byte, 8192)
	for {
		n, oserr := file.Read(buf)
		if oserr != nil {
			fmt.Fprintf(os.Stderr, "error reading %s: %s\n", from, oserr)
			return
		}
		if n == 0 {
			break
		}

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

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


示例9: main

func main() {
	var user g9p.User
	var err error
	var c *g9pc.Client
	var file *g9pc.File
	var d []*g9p.Dir

	flag.Parse()
	user = g9p.OsUsers.Uid2User(os.Geteuid())
	c, err = g9pc.Mount("tcp", *addr, "", user, nil)
	if err != nil {
		goto error
	}

	if flag.NArg() != 1 {
		log.Println("invalid arguments")
		return
	}

	file, err = c.FOpen(flag.Arg(0), g9p.OREAD)
	if err != nil {
		goto error
	}

	for {
		d, err = file.Readdir(0)
		if err != nil {
			goto error
		}

		if d == nil || len(d) == 0 {
			break
		}

		for i := 0; i < len(d); i++ {
			os.Stdout.WriteString(d[i].Name + "\n")
		}
	}

	file.Close()
	return

error:
	log.Println(fmt.Sprintf("Error: %v", err))
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:45,代码来源:ls.go


示例10: cmdcat

// Print the contents of f
func cmdcat(c *g9pc.Client, s []string) {
	buf := make([]byte, 8192)
	for _, f := range s {
		fname := normpath(f)
		file, err := c.FOpen(fname, g9p.OREAD)
		if err != nil {
			fmt.Fprintf(os.Stderr, "error opening %s: %s\n", f, err)
			continue
		}
		defer file.Close()
		for {
			n, err := file.Read(buf)
			if err != nil {
				fmt.Fprintf(os.Stderr, "error reading %s: %s\n", f, err)
			}
			if n == 0 {
				break
			}
			os.Stdout.Write(buf[0:n])
		}
	}
}
开发者ID:zxpbenson,项目名称:rog-go,代码行数:23,代码来源:cl.go


示例11: writeone

// Write the string s to remote file f. Create f if it doesn't exist
func writeone(c *g9pc.Client, f, s string) {
	fname := normpath(f)
	file, err := c.FOpen(fname, g9p.OWRITE|g9p.OTRUNC)
	if err != nil {
		file, err = c.FCreate(fname, 0666, g9p.OWRITE)
		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:zxpbenson,项目名称:rog-go,代码行数:24,代码来源:cl.go



注:本文中的code/google/com/p/rog-go/go9p/g9pc.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang client.Ns类代码示例发布时间:2022-05-24
下一篇:
Golang token.Position类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap