# cmd structureCommon way to have command line utils in a packages is under a "cmd" folder. (e.g. see https://github.com/bradfitz/camlistore/tree/master/cmd)I would recommend having:cmd/bytenginecmd/beshell
# Naming - avoid stutterThe package name is part of a nameThe full name for that type is bfs.BFSResponse, bfs.Response is nicer.mongo.MongodbBFS -> mongo.BFS or mongodb.BFSThere are more similar to this....
# bfs.Response
It would look better as:
type Status string
const (
OK Status = "ok"
Error Status = "error"
)
type Response struct {
Status Status
StatusMessage string
Data map[string]interface{}
}
This means you don't need a lot of the functions
In bfs/mongo you can now return
bfs.Response{bfs.OK, "", data}
bfs.Respones{bfs.Error, "something missing", nil}
Checking for success...
if bfs.Response.Status == bfs.OK {}
Of course the idiomatic way would be to have multiple returns
type Response map[string]interface{}
type BFS interface {
Start(config string, b *bst.ByteStore) error
ClearAll() (Response, error)
ListDatabase(filter string) (Response, error)
CreateDatabase(db string) (Response, error)
DropDatabase(db string) (Response, error)
NewDir(p, db string) (Response, error)
NewFile(p, db string, jsondata map[string]interface{}) (Response, error)
ListDir(p, filter, db string) (Response, error)
ReadJson(p, db string, fields []string) (Response, error)
}
https://github.com/johnwilson/bytengine/blob/master/core/core.go#L18
CommandHandler would be more appropriate
https://github.com/johnwilson/bytengine/blob/master/core/core.go#L23
Add would suffice.
# Naming of packages
ext -> plugin, then you can use the methods as:
plugin.New(...)
plugin.Register(...)
Similarly: fltcore -> plugin/datafilter
datafilter.New(...)
datafilter.Register(...)
Also, somehow the package layout isn't indicitave of the different parts.
auth, bfs, bst, core look like they should belong in the same package...
maybe pull auth, bfs, bts into the root level:
auth.User -> bytengine.User
core.Engine -> bytengine.Engine
bfs.BFS -> bytengine.FileSystem
bst.ByteStore -> bytengine.ByteStore
auth.Authentication -> authentication.Interface
// authentication.Register / authentication.New
bfs/mongo -> bytengine/filesystem/mongo
bts/mongo -> bytengine/bytestore/mongo
Basically I would leave the only the registration points in the separate packages...
Anyways... I'm also not convinced that my would be the best either... anyways a point that could use some hard thinking :)
# misc
https://github.com/johnwilson/bytengine/blob/master/bytengine/engine/handlers.go#L17
Name it "func user_new", then you won't need the comment.
# generally
Otherwise, the code looks great... nice and clean as it should be.
Hi everyone!So I've done a bit of refactoring and here's a quick report.# cmd structureCommon way to have command line utils in a packages is under a "cmd" folder. (e.g. see https://github.com/bradfitz/camlistore/tree/master/cmd)I would recommend having:cmd/bytenginecmd/beshell
Done and updated the README. It makes the 'go get' command longer but it also makes a lot more sense (thanks for the camlistore link)
I chose to be 'less idiomatic' for the following reasons:
- I didn't want to use two channels when getting responses from 'filesystem' namely one for 'bfs.Response' types and one for 'error' types, thus requiring a 'switch statement' here https://github.com/johnwilson/bytengine/blob/master/cmd/bytengine/bytengine.go#L53
In regard to suggestion 1, when core, auth, bytestore, filesystem etc are put into "bytengine" (root) package this causes an import cycle error because they're used by the plugins and the plugins are in turn called by config.go which is at root package level.
Right, that's not a bad idea at all. Blimey you're quick!So if I undrstand you clearly, this will mean that config.go which imports plugins and config.json which handles plugin configurations will be in the same location i.e. in cmd/bytengine.
So this update took a bit longer ( a few things pending) but here's what has been done so far:
- Constants all caps changed
- Bytengine API Client is in its own package now
- References to 'BFS' have been changed to 'FileSystem'
- Bytengine error response has been removed: https://github.com/johnwilson/bytengine/blob/master/filesystem.go#L10 (although i added response functions in the cmd/bytengine/bytengine.go )
- 'Plugin' suffix removed https://github.com/johnwilson/bytengine/blob/master/engine.go#L27-L33
- Simplejson dependancy removed (thanks for the json.RawMessage tip/example)
- Removed panic in packages but I couldn't figure out a neat way of throwing errors in package init functions (I'm using log.Fatal at the moment but I'm sure there's a better solution to this) for example https://github.com/johnwilson/bytengine/blob/master/filesystem.go#L40 and https://github.com/johnwilson/bytengine/blob/master/filesystem/mongo/mongo.go#L1453 . If I return an error in the RegisterFileSystem function does the init function just log the error or is there a better way to handle it?
Still need to review quite a few sections of the code though, but do let me know if you spot omissions/mistakes that I might have made. And thanks once again for the feedback.
- Added utils.go to auth, bytestore and filesystem packages
- Moved plugin registration and creation functions to same files as their interface specification.
- Parser is now a plugin and is implemented here bytengine/parser/base