gfile

package module
v0.0.0-...-a1014aa Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2019 License: MIT Imports: 4 Imported by: 0

README

gfile

使用graphql进行文件或目录查询

graphql定义的结构:


type Time {

}

type FileInfo {
  Name():String!
  Size(): Int
  Mode(): Int
  ModTime(): Time
  IsDir(): Boolean
  path: String!
}

type Query {
  readDir(path:String!):[FileInfo]!
  exists(path:String):Boolean!
  findFile(path:!String,exts:[String],current:Boolean):[FileInfo]!
}

演示范例:

go run ./example/

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FileInfoType = graphql.NewObject(graphql.ObjectConfig{
	Name: "FileInfo",
	Fields: graphql.Fields{
		"name": &graphql.Field{
			Type: graphql.NewNonNull(graphql.String),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if value, ok := p.Source.(*TFileInfo); ok {
					return value.Name(), nil
				}
				return "", nil
			},
		},

		"isDir": &graphql.Field{
			Type: graphql.NewNonNull(graphql.Boolean),
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if value, ok := p.Source.(*TFileInfo); ok {
					return value.IsDir(), nil
				}
				return false, nil
			},
		},

		"size": &graphql.Field{
			Type: graphql.Int,
			Resolve: func(p graphql.ResolveParams) (interface{}, error) {
				if value, ok := p.Source.(*TFileInfo); ok {
					return value.Size(), nil
				}
				return 0, nil
			},
		},

		"path": &graphql.Field{
			Type: graphql.String,
		},
	},
})

Functions

func Do

func Do(query string) (interface{}, []error)

Run query

func Exists

func Exists(path string) bool

Exists func

Types

type TFileInfo

type TFileInfo struct {
	File os.FileInfo
	Path string `json:path`
}

func (TFileInfo) IsDir

func (f TFileInfo) IsDir() bool

func (TFileInfo) ModTime

func (f TFileInfo) ModTime() time.Time

func (TFileInfo) Mode

func (f TFileInfo) Mode() os.FileMode

func (TFileInfo) Name

func (f TFileInfo) Name() string

func (TFileInfo) Size

func (f TFileInfo) Size() int64

func (TFileInfo) Sys

func (f TFileInfo) Sys() interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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