fsgraph

package module
v0.0.0-...-796e0ea Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2018 License: MIT Imports: 18 Imported by: 0

README

fsgraph

fsgraph is a GraphQL interface for a file system, built with gqlgen.

Getting Started

Build it:

$ go get -v github.com/millerlogic/fsgraph/...
$ go install github.com/millerlogic/fsgraph/cmd/fsgraph

Usage:

$ fsgraph --help
Usage of fsgraph:
  -address string
    	HTTP address for the GraphQL server (default "localhost:8080")
  -protected
    	Writes go to a temporary location (default true)
  -root string
    	Root path of the file system to serve (default "/current/dir")
  -scope string
    	Set the file ID scope, before hashing (defaults to hostname:root)

Run:

$ fsgraph &
2018/11/06 20:30:22 FS root: /current/dir
2018/11/06 20:30:22 file ID scope: e3248d8392f13fa55fc3dc192ed4e793 (hashed from myhost:/current/dir)
2018/11/06 20:30:22 protected: temporary overlay dir: /tmp/fsgraph923227248
2018/11/06 20:30:22 connect to http://localhost:8080/ for GraphQL playground

By default it serves files from your current directory on localhost:8080 (only localhost can connect), and protected is enabled which means any writes will go to a separate temporary location. Scope is used to create file IDs, as a way of attempting to make them global IDs. By default it is your computer's host name, a colon, and the root dir path, which all gets hashed. All of these defaults can be overridden on the command line.

Query

See the GraphQL schema file: schema.graphql

Example:

query ls {
  root {
    children {
      name
      mode {
        type
      }
    }
  }
}

Output:

{
  "data": {
    "root": {
      "children": [
        {
          "name": ".git",
          "mode": {
            "type": "dir"
          }
        },
        {
          "name": "schema.graphql",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "LICENSE",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "gqlgen.yml",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "fsgraph_test.go",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "cmd",
          "mode": {
            "type": "dir"
          }
        },
        {
          "name": "generated.go",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "resolver.go",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "README.md",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "fs.go",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "models_gen.go",
          "mode": {
            "type": "regular"
          }
        },
        {
          "name": "types.go",
          "mode": {
            "type": "regular"
          }
        }
      ]
    }
  }
}

forthebadge forthebadge forthebadge

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidEncoding = errors.New("Invalid encoding")

ErrInvalidEncoding is returned if the Encoding is not valid.

Functions

func NewExecutableSchema

func NewExecutableSchema(cfg Config) graphql.ExecutableSchema

NewExecutableSchema creates an ExecutableSchema from the ResolverRoot interface.

Types

type ComplexityRoot

type ComplexityRoot struct {
	Dir struct {
		Id       func(childComplexity int) int
		Name     func(childComplexity int) int
		Path     func(childComplexity int) int
		Size     func(childComplexity int) int
		Mode     func(childComplexity int) int
		ModTime  func(childComplexity int) int
		Parent   func(childComplexity int) int
		Children func(childComplexity int, first int) int
		File     func(childComplexity int, path string) int
	}

	FileContents struct {
		Data     func(childComplexity int) int
		Next     func(childComplexity int) int
		Encoding func(childComplexity int) int
		Warning  func(childComplexity int) int
	}

	FileMode struct {
		Type   func(childComplexity int) int
		Perm   func(childComplexity int) int
		Sticky func(childComplexity int) int
	}

	FileResult struct {
		S       func(childComplexity int) int
		Warning func(childComplexity int) int
		File    func(childComplexity int) int
	}

	InternalOtherFile struct {
		Id      func(childComplexity int) int
		Name    func(childComplexity int) int
		Path    func(childComplexity int) int
		Size    func(childComplexity int) int
		Mode    func(childComplexity int) int
		ModTime func(childComplexity int) int
		Parent  func(childComplexity int) int
	}

	Mutation struct {
		Remove   func(childComplexity int, path string) int
		Rename   func(childComplexity int, path string, newName string) int
		Chmod    func(childComplexity int, path string, mode int) int
		Write    func(childComplexity int, path string, contents string, open []FileOpen, encoding Encoding) int
		Mkdir    func(childComplexity int, path string) int
		MkdirAll func(childComplexity int, path string) int
	}

	Okresult struct {
		S       func(childComplexity int) int
		Warning func(childComplexity int) int
	}

	Query struct {
		Root func(childComplexity int) int
		Cd   func(childComplexity int, path string) int
		File func(childComplexity int, path string) int
	}

	RegularFile struct {
		Id       func(childComplexity int) int
		Name     func(childComplexity int) int
		Path     func(childComplexity int) int
		Size     func(childComplexity int) int
		Mode     func(childComplexity int) int
		ModTime  func(childComplexity int) int
		Parent   func(childComplexity int) int
		Contents func(childComplexity int, encoding Encoding, maxReadBytes Int64, seek Int64) int
	}
}

type Config

type Config struct {
	Resolvers  ResolverRoot
	Directives DirectiveRoot
	Complexity ComplexityRoot
}

type Dir

type Dir struct {
	// contains filtered or unexported fields
}

func (Dir) ID

func (fb Dir) ID() string

func (Dir) IsFile

func (Dir) IsFile()

func (Dir) ModTime

func (fb Dir) ModTime() string

func (Dir) Mode

func (fb Dir) Mode() FileMode

func (Dir) Name

func (fb Dir) Name() string

func (Dir) Size

func (fb Dir) Size() Int64

type DirResolver

type DirResolver interface {
	Parent(ctx context.Context, obj *Dir) (File, error)
	Children(ctx context.Context, obj *Dir, first int) ([]File, error)
	File(ctx context.Context, obj *Dir, path string) (File, error)
}

type DirectiveRoot

type DirectiveRoot struct {
	ScalarInfo func(ctx context.Context, obj interface{}, next graphql.Resolver, baseType string) (res interface{}, err error)
}

type Encoding

type Encoding string

file contents (read) or write encoding

const (
	EncodingAuto   Encoding = "auto"
	EncodingUtf8   Encoding = "utf8"
	EncodingBase64 Encoding = "base64"
)

func (Encoding) IsValid

func (e Encoding) IsValid() bool

func (Encoding) MarshalGQL

func (e Encoding) MarshalGQL(w io.Writer)

func (Encoding) String

func (e Encoding) String() string

func (*Encoding) UnmarshalGQL

func (e *Encoding) UnmarshalGQL(v interface{}) error

type FS

type FS struct {
	afero.Fs
	Scope []byte
}

func (FS) GetDir

func (fs FS) GetDir(dirPath string) (Dir, error)

func (FS) GetFile

func (fs FS) GetFile(path string) (File, error)

func (FS) ID

func (fs FS) ID() string

type File

type File interface {
	IsFile()
}

a generic file

type FileContents

type FileContents struct {
	Data     string   `json:"data"`
	Next     *Int64   `json:"next"`
	Encoding Encoding `json:"encoding"`
	Warning  *string  `json:"warning"`
}

the contents of a file

type FileMode

type FileMode struct {
	Type   FileType `json:"type"`
	Perm   int      `json:"perm"`
	Sticky bool     `json:"sticky"`
}

a representation of the file's mode

type FileOpen

type FileOpen string

specifies how a file is to be opened

const (
	// create file if it doesn't exist
	FileOpenCreate FileOpen = "create"
	// file must not exist
	FileOpenNew FileOpen = "new"
	// truncate the file if it exists
	FileOpenTruncate FileOpen = "truncate"
	// writes will be appended to the end of the file
	FileOpenAppend FileOpen = "append"
)

func (FileOpen) IsValid

func (e FileOpen) IsValid() bool

func (FileOpen) MarshalGQL

func (e FileOpen) MarshalGQL(w io.Writer)

func (FileOpen) String

func (e FileOpen) String() string

func (*FileOpen) UnmarshalGQL

func (e *FileOpen) UnmarshalGQL(v interface{}) error

type FileResult

type FileResult struct {
	S       string  `json:"s"`
	Warning *string `json:"warning"`
	// contains filtered or unexported fields
}

func (FileResult) IsResult

func (FileResult) IsResult()

type FileResultResolver

type FileResultResolver interface {
	File(ctx context.Context, obj *FileResult) (File, error)
}

type FileType

type FileType string
const (
	FileTypeRegular    FileType = "regular"
	FileTypeDir        FileType = "dir"
	FileTypeSymlink    FileType = "symlink"
	FileTypeNamedPipe  FileType = "namedPipe"
	FileTypeSocket     FileType = "socket"
	FileTypeDevice     FileType = "device"
	FileTypeCharDevice FileType = "charDevice"
	FileTypeIrregular  FileType = "irregular"
)

func (FileType) IsValid

func (e FileType) IsValid() bool

func (FileType) MarshalGQL

func (e FileType) MarshalGQL(w io.Writer)

func (FileType) String

func (e FileType) String() string

func (*FileType) UnmarshalGQL

func (e *FileType) UnmarshalGQL(v interface{}) error

type Int64

type Int64 int64

func (Int64) MarshalGQL

func (x Int64) MarshalGQL(w io.Writer)

func (*Int64) UnmarshalGQL

func (x *Int64) UnmarshalGQL(v interface{}) error

type Internal_OtherFile

type Internal_OtherFile struct {
	// contains filtered or unexported fields
}

func (Internal_OtherFile) ID

func (fb Internal_OtherFile) ID() string

func (Internal_OtherFile) IsFile

func (Internal_OtherFile) IsFile()

func (Internal_OtherFile) ModTime

func (fb Internal_OtherFile) ModTime() string

func (Internal_OtherFile) Mode

func (fb Internal_OtherFile) Mode() FileMode

func (Internal_OtherFile) Name

func (fb Internal_OtherFile) Name() string

func (Internal_OtherFile) Size

func (fb Internal_OtherFile) Size() Int64

type Internal_OtherFileResolver

type Internal_OtherFileResolver interface {
	Parent(ctx context.Context, obj *Internal_OtherFile) (File, error)
}

type MutationResolver

type MutationResolver interface {
	Remove(ctx context.Context, path string) (OKResult, error)
	Rename(ctx context.Context, path string, newName string) (FileResult, error)
	Chmod(ctx context.Context, path string, mode int) (FileResult, error)
	Write(ctx context.Context, path string, contents string, open []FileOpen, encoding Encoding) (FileResult, error)
	Mkdir(ctx context.Context, path string) (FileResult, error)
	MkdirAll(ctx context.Context, path string) (FileResult, error)
}

type OKResult

type OKResult struct {
	S       string  `json:"s"`
	Warning *string `json:"warning"`
}

func (OKResult) IsResult

func (OKResult) IsResult()

type QueryResolver

type QueryResolver interface {
	Root(ctx context.Context) (Dir, error)
	Cd(ctx context.Context, path string) (*Dir, error)
	File(ctx context.Context, path string) (File, error)
}

type RegularFile

type RegularFile struct {
	// contains filtered or unexported fields
}

func (RegularFile) ID

func (fb RegularFile) ID() string

func (RegularFile) IsFile

func (RegularFile) IsFile()

func (RegularFile) ModTime

func (fb RegularFile) ModTime() string

func (RegularFile) Mode

func (fb RegularFile) Mode() FileMode

func (RegularFile) Name

func (fb RegularFile) Name() string

func (RegularFile) Size

func (fb RegularFile) Size() Int64

type RegularFileResolver

type RegularFileResolver interface {
	Parent(ctx context.Context, obj *RegularFile) (File, error)
	Contents(ctx context.Context, obj *RegularFile, encoding Encoding, maxReadBytes Int64, seek Int64) (FileContents, error)
}

type Resolver

type Resolver struct {
	RootFS FS
}

func (*Resolver) Dir

func (r *Resolver) Dir() DirResolver

func (*Resolver) FileResult

func (r *Resolver) FileResult() FileResultResolver

func (*Resolver) Internal_OtherFile

func (r *Resolver) Internal_OtherFile() Internal_OtherFileResolver

func (*Resolver) Mutation

func (r *Resolver) Mutation() MutationResolver

func (*Resolver) Query

func (r *Resolver) Query() QueryResolver

func (*Resolver) RegularFile

func (r *Resolver) RegularFile() RegularFileResolver

type ResolverRoot

type ResolverRoot interface {
	Dir() DirResolver
	FileResult() FileResultResolver
	Internal_OtherFile() Internal_OtherFileResolver
	Mutation() MutationResolver
	Query() QueryResolver
	RegularFile() RegularFileResolver
}

type Result

type Result interface {
	IsResult()
}

a generic result of an operation

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL