本文整理汇总了Golang中github.com/zenoss/rog-go/go9p/g9pc.Client.FOpen方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.FOpen方法的具体用法?Golang Client.FOpen怎么用?Golang Client.FOpen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/zenoss/rog-go/go9p/g9pc.Client
的用法示例。
在下文中一共展示了Client.FOpen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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))
}
}
示例2: 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
}
}
}
示例3: 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
}
}
}
示例4: 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))
}
示例5: 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])
}
}
}
示例6: 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
}
}