commit 2ba1d6e2a1e0e884d0c889d3409d9eb39ddfde85 Author: xdrm-brackets Date: Sun Jun 10 22:49:32 2018 +0200 first commit - half test with: +config +controllers -no_custom_type diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1fe8d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.so \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..06bfdda --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +# xdrm go framework + +### 1. Setup + +All commands above must be launched from the root of this repository. + +In order for next steps to work properly whatever your configuration, you might execute the following command: +```bash +chmod +x $GOPATH/src/git.xdrm.io/xdrm-brackets/gfw/*.sh +``` + +### 2. Build type checkers + +Default types have to be built before using them. + +```bash +$GOPATH/src/git.xdrm.io/xdrm-brackets/gfw/build-types.sh +``` + +If the build process succeeds, the `./types` folder must contain *.so* files. + +### 3. Build controllers + +Controllers are located under the `./root` file structure. + +```bash +$GOPATH/src/git.xdrm.io/xdrm-brackets/gfw/build-controllers.sh ./root +``` + +If the build process succeeds, the `./controllers` folder must contain *.so* files. + +### 4. Launch the api + +``` +$ go run ./cmd/test/main.go +``` \ No newline at end of file diff --git a/cmd/test/main.go b/cmd/test/main.go new file mode 100644 index 0000000..7715ebb --- /dev/null +++ b/cmd/test/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "git.xdrm.io/xdrm-brackets/gfw" + "log" +) + +func main() { + + srv, err := gfw.Init("manifest.json", nil) + if err != nil { + log.Fatal(err) + } + + log.Printf("Server up and running\n") + err = srv.Launch(4444) + if err != nil { + log.Fatalf("*** server failed (%s)\n", err) + } + +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..dc49e76 --- /dev/null +++ b/manifest.json @@ -0,0 +1,115 @@ +{ + + "GET": { + "info": "returns api information", + "scope": [[]], + "in": {}, + "out": { + "version": { "info": "current api version", "type": "varchar(1,8)" }, + "info": { "info": "api information details", "type": "" } + } + }, + + "/": { + + "user": { + + "GET": { + "info": "gets all | a specific user by id", + "scope": [[]], + "in": { + "URL#0": { "info": "optional user id | all users are returned if missing", "name": "uid", "type": "?int", "default": null } + }, + "out": { + "users": { "info": "matching user(s) data", "type": "" } + } + }, + + "POST": { + "info": "creates a new user", + "scope": [["admin"]], + "in": { + "firstname": { "info": "new first name", "type": "varchar(3,20)" }, + "lastname": { "info": "new last name", "type": "varchar(3,20)" }, + "mail": { "info": "new mail", "type": "string" } + }, + "out": { + "user": { "info": "user data to acknowledge creation", "type": "" } + } + }, + + "PUT": { + "info": "updates data of an existing user; only the data given will be updated, all fields are optional", + "scope": [["admin"], ["user"]], + "in": { + "URL#0": { "info": "id of the user to update", "type": "int", "name": "user_id" }, + "firstname": { "info": "new first name", "type": "?varchar(3,20)", "default": null }, + "lastname": { "info": "new last name", "type": "?varchar(3,20)", "default": null }, + "mail": { "info": "new mail", "type": "?string", "default": null } + }, + "out": { + "user": { "info": "new updated data to acknowledge updates", "type": "" } + } + }, + + "DELETE": { + "info": "deletes an existing user", + "scope": [["admin"], ["user"]], + "in": { + "URL#0": { "info": "id of the user to delete", "type": "int" } + }, + "out": {} + }, + + "/": { + "post": { + "GET": { + "info": "gets all | a specific post for an existing user", + "scope": [["user"], []], + "in": { + "URL#0": { "info": "optional post id", "type": "int", "name": "?post_id", "default": null }, + "URL#1": { "info": "user id (if missing, current connected user)", "type": "int", "name": "?user_id", "default": null } + }, + "out": { + "posts": { "info": "matching post(s) data", "type": "" } + } + }, + + "POST": { + "info": "creates a new post for the current connected user", + "scope": [["user"]], + "in": { + "title": { "info": "new post title", "type": "varchar(3,20)" }, + "content": { "info": "new post content", "type": "string" } + }, + "out": { + "post": { "info": "post data to acknowledge creation", "type": "" } + } + }, + + "PUT": { + "info": "updates data of an existing post of the current connected user; only the data given will be updated, all fields are optional", + "scope": [["user"]], + "in": { + "title": { "info": "new post title", "type": "?varchar(3,20)", "default": null }, + "content": { "info": "new post content", "type": "?string", "default": null } + }, + "out": { + "post": { "info": "new updated data to acknowledge updates", "type": "" } + } + }, + + "DELETE": { + "info": "deletes an existing post of the current connected user", + "scope": [["user"]], + "in": { + "URL#0": { "info": "id of the post to delete", "type": "int", "name": "post_id" } + }, + "out": {} + } + } + } + } + + } +} \ No newline at end of file diff --git a/root/i.go b/root/i.go new file mode 100644 index 0000000..6d36180 --- /dev/null +++ b/root/i.go @@ -0,0 +1,15 @@ +package main + +import ( + "fmt" + e "git.xdrm.io/xdrm-brackets/gfw/err" + i "git.xdrm.io/xdrm-brackets/gfw/implement" +) + +func Get(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("GET /\n") + r.Set("api_version", 1.2) + r.Set("received_data", d) + r.Err = e.Success + return *r +} diff --git a/root/user/posti.go b/root/user/posti.go new file mode 100644 index 0000000..99a6f46 --- /dev/null +++ b/root/user/posti.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + e "git.xdrm.io/xdrm-brackets/gfw/err" + i "git.xdrm.io/xdrm-brackets/gfw/implement" +) + +func Get(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("GET /user/post\n") + r.Set("method_test", "Get") + r.Err = e.Upload + return *r +} +func Post(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("POST /user/post\n") + r.Set("method_test", "Post") + r.Err = e.Download + return *r +} +func Put(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("PUT /user/post\n") + r.Set("method_test", "Put") + r.Err = e.MissingDownloadHeaders + return *r +} +func Delete(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("DELETE /user/post\n") + r.Set("method_test", "Delete") + r.Err = e.MissingDownloadBody + return *r +} diff --git a/root/useri.go b/root/useri.go new file mode 100644 index 0000000..e6ee9db --- /dev/null +++ b/root/useri.go @@ -0,0 +1,36 @@ +package main + +import ( + "fmt" + e "git.xdrm.io/xdrm-brackets/gfw/err" + i "git.xdrm.io/xdrm-brackets/gfw/implement" +) + +func Get(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("GET /user\n") + r.Set("method_test", "Get") + r.Set("received_data", d) + r.Err = e.Upload + return *r +} +func Post(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("POST /user\n") + r.Set("method_test", "Post") + r.Set("received_data", d) + r.Err = e.Download + return *r +} +func Put(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("PUT /user\n") + r.Set("method_test", "Put") + r.Set("received_data", d) + r.Err = e.MissingDownloadHeaders + return *r +} +func Delete(d i.Arguments, r *i.Response) i.Response { + fmt.Printf("DELETE /user\n") + r.Set("method_test", "Delete") + r.Set("received_data", d) + r.Err = e.MissingDownloadBody + return *r +}