update
This commit is contained in:
parent
7b1863109c
commit
ef751771d2
107 changed files with 9435 additions and 850 deletions
pkg/go-nfs/example/helloworld
52
pkg/go-nfs/example/helloworld/main.go
Normal file
52
pkg/go-nfs/example/helloworld/main.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/go-git/go-billy/v5"
|
||||
"github.com/go-git/go-billy/v5/memfs"
|
||||
|
||||
nfs "git.kmsign.ru/royalcat/tstor/pkg/go-nfs"
|
||||
"git.kmsign.ru/royalcat/tstor/pkg/go-nfs/helpers"
|
||||
nfshelper "git.kmsign.ru/royalcat/tstor/pkg/go-nfs/helpers"
|
||||
)
|
||||
|
||||
// ROFS is an intercepter for the filesystem indicating it should
|
||||
// be read only. The undelrying billy.Memfs indicates it supports
|
||||
// writing, but does not in implement billy.Change to support
|
||||
// modification of permissions / modTimes, and as such cannot be
|
||||
// used as RW system.
|
||||
type ROFS struct {
|
||||
nfs.Filesystem
|
||||
}
|
||||
|
||||
// Capabilities exports the filesystem as readonly
|
||||
func (ROFS) Capabilities() billy.Capability {
|
||||
return billy.ReadCapability | billy.SeekCapability
|
||||
}
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
|
||||
listener, err := net.Listen("tcp", ":0")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to listen: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Server running at %s\n", listener.Addr())
|
||||
|
||||
mem := helpers.WrapBillyFS(memfs.New())
|
||||
f, err := mem.Create(ctx, "hello.txt")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create file: %v\n", err)
|
||||
return
|
||||
}
|
||||
_, _ = f.Write(ctx, []byte("hello world"))
|
||||
_ = f.Close(ctx)
|
||||
|
||||
handler := nfshelper.NewNullAuthHandler(ROFS{mem})
|
||||
cacheHelper := nfshelper.NewCachingHandler(handler, 1024)
|
||||
fmt.Printf("%v", nfs.Serve(listener, cacheHelper))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue