nfsserv.go 663 B

123456789101112131415161718192021222324252627282930313233343536
  1. package nfsserv
  2. import (
  3. "fmt"
  4. "net"
  5. nfs "github.com/willscott/go-nfs"
  6. "imuslab.com/arozos/mod/permission"
  7. )
  8. type Option struct {
  9. ListeningPort int
  10. AllowAccessGroup *permission.PermissionGroup
  11. }
  12. type Instance struct {
  13. server *nfs.Server
  14. isRunning bool
  15. option *Option
  16. }
  17. // Create a new NFS Server
  18. func NewNfsServer(option Option) (*Instance, error) {
  19. // Check if the listening port is free and not occupied by another application
  20. l, err := net.Listen("tcp", fmt.Sprintf(":%d", option.ListeningPort))
  21. if err != nil {
  22. return nil, err
  23. }
  24. l.Close()
  25. return &Instance{
  26. server: nil,
  27. isRunning: false,
  28. option: &option,
  29. }, nil
  30. }