本文整理匯總了Golang中github.com/zenoss/rog-go/new9p/client.Ns.Open方法的典型用法代碼示例。如果您正苦於以下問題:Golang Ns.Open方法的具體用法?Golang Ns.Open怎麽用?Golang Ns.Open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/zenoss/rog-go/new9p/client.Ns
的用法示例。
在下文中一共展示了Ns.Open方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: cmdget
// Copy a remote file to local filesystem
func cmdget(ns *g9pc.Ns, s []string) {
var from, to string
switch len(s) {
case 1:
from, to = path.Split(path.Clean(s[0]))
case 2:
from, to = 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, err := ns.Open(from, g9p.OREAD)
if err != nil {
fmt.Fprintf(os.Stderr, "error opening %s for writing: %s\n", to, err)
return
}
defer file.Close()
_, err = io.Copy(tofile, file)
if err != nil {
fmt.Fprintf(os.Stderr, "error copying: %v\n", err)
return
}
}
示例2: lsone
func lsone(ns *g9pc.Ns, s string, long bool) {
st, err := ns.Stat(s)
if err != nil {
fmt.Fprintf(os.Stderr, "error stat: %s\n", err)
return
}
if st.Mode&g9p.DMDIR != 0 {
file, err := ns.Open(s, g9p.OREAD)
if err != nil {
fmt.Fprintf(os.Stderr, "error opening dir: %s\n", err)
return
}
defer file.Close()
for {
d, err := file.Dirread()
if err != nil && err != io.EOF {
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))
}
}
示例3: cmdcat
// Print the contents of f
func cmdcat(ns *g9pc.Ns, s []string) {
for _, fname := range s {
file, err := ns.Open(fname, g9p.OREAD)
if err != nil {
fmt.Fprintf(os.Stderr, "error opening %s: %s\n", fname, err)
continue
}
defer file.Close()
_, err = io.Copy(os.Stdout, file)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
}
}
}
示例4: 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
}
}
示例5: 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)
}