Git Product home page Git Product logo

gin's Introduction

Build Status

GIN JSON-API framework

Gin is an JSON-API framework, currently in its early stage.

It has been designed to allow for fast development, TDD and ease of maintenance.

Gin is helpful when you need an extra-boost in performance and scalability, as it runs embedded in a packaged version of nginx called OpenResty and it's entirely written in Lua. For those not familiar with Lua, don't let that scare you away: Lua is really easy to use, very fast and simple to get started with.

For instance, this is what a simple Gin controller looks like:

local InfoController = {}

function InfoController:whoami()
    return 200, { name = 'gin' }
end

return InfoController

When called, this returns an HTTP 200 response with body:

{
	"name": "gin"
}

Features

Gin already provides:

Get started now! Please refer to the official gin.io website for documentation.

Contributing

So you want to contribute? That's great! Please follow the guidelines below. It will make it easier to get merged in.

Before implementing a new feature, please submit a ticket to discuss what you intend to do. Your feature might already be in the works, or an alternative implementation might have already been discussed.

Every pull request should have its own topic branch. In this way, every additional adjustments to the original pull request might be done easily, and squashed with git rebase -i. The updated branch will be visible in the same pull request, so there will be no need to open new pull requests when there are changes to be applied.

Do not commit to master in your fork. Provide a clean branch without merge commits.

Ensure to include proper testing. To test gin you simply have to be in the project's root directory and issue:

$ busted

●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●●● ○
195 successes / 0 failures / 0 pending : 0.156489 seconds.

There will be no merges without a clean build.

gin's People

Contributors

arialdomartini avatar istr avatar leite avatar neomantra avatar ostinelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gin's Issues

Another question about Gin start(Symbol not found: _luaL_setfuncs)

Hi Ostinelli Yestoday I run Gin base the Lua and Luarocks was intalled from their Source Code not Brew install like Your Gin Doc, It works except the busted, So today I remove those Lua,Luarocks,Gin,and reinstall them as Your Doc
that I got a mistake like this:

2015/08/12 19:02:40 [error] 12773#0: *1 lua entry thread aborted: runtime error: error loading module 'cjson' from file '/usr/local/lib/lua/5.2/cjson.so':
    dlopen(/usr/local/lib/lua/5.2/cjson.so, 6): Symbol not found: _luaL_setfuncs
  Referenced from: /usr/local/lib/lua/5.2/cjson.so
  Expected in: dynamic lookup

stack traceback:
coroutine 0:
    [C]: in function 'require'
    content_by_lua(development-nginx.conf:39):1: in function <content_by_lua(development-nginx.conf:39):1>, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:7200"
2015/08/12 19:02:41 [error] 12773#0: *2 lua entry thread aborted: runtime error: error loading module 'cjson' from file '/usr/local/lib/lua/5.2/cjson.so':
    dlopen(/usr/local/lib/lua/5.2/cjson.so, 6): Symbol not found: _luaL_setfuncs
  Referenced from: /usr/local/lib/lua/5.2/cjson.so
  Expected in: dynamic lookup

stack traceback:
coroutine 0:
    [C]: in function 'require'
    content_by_lua(development-nginx.conf:39):1: in function <content_by_lua(development-nginx.conf:39):1>, client: 127.0.0.1, server: , request: "GET /favicon.ico HTTP/1.1", host: "localhost:7200", referrer: "http://localhost:7200/"

here My question is That openresty runs base on LuaJIT, LuaJIT use the lua 5.1 ABI, but Gin is base on lua 5.2, luaL_setfuncs is a ABI of Lua 5.2, so how to fix this?

Data validation

There are some type of "data validation" for the request?

ORM by itself?

Hi,

So for the time being, I'm working with some Lua scripts requiring database access. I don't need the entire Gin framework, only the Models/ORM as it seems far superior to anything related I've come across so far.

Is there a way to use it without OpenResty and the rest of the Gin (API related) framework?

A question about LUA_PACKAGE_PATH

Hi,ostinelli!
I found that you set nginx directive lua_package_path in a func named gin_init, gin start execute with a param -e 'package.path, but as a result in my development-nginx.conf I got this

lua_code_cache off;
    lua_package_path "./?.lua;$prefix/lib/?.lua;#{= LUA_PACKAGE_PATH };;";

This made a mistake when i visit http://localhost:7200/ like

2015/08/11 17:38:07 [error] 79803#0: *3 lua entry thread aborted: runtime error: content_by_lua(development-nginx.conf:38):1: module 'gin.core.router' not found:
    no field package.preload['gin.core.router']
    no file './gin/core/router.lua'
    no file '/Users/zj-gin/sina//lib/gin/core/router.lua'
    no file '#{= LUA_PACKAGE_PATH }'
    no file '/usr/local/nginx_x/lualib/gin/core/router.lua'
    no file '/usr/local/nginx_x/lualib/gin/core/router/init.lua'
    no file './gin/core/router.lua'
    no file '/usr/local/nginx_x/luajit/share/luajit-2.1.0-alpha/gin/core/router.lua'
    no file '/usr/local/share/lua/5.1/gin/core/router.lua'
    no file '/usr/local/share/lua/5.1/gin/core/router/init.lua'
    no file '/usr/local/nginx_x/luajit/share/lua/5.1/gin/core/router.lua'
    no file '/usr/local/nginx_x/luajit/share/lua/5.1/gin/core/router/init.lua'
    no file '/usr/local/nginx_x/lualib/gin/core/router.so'
    no file './gin/core/router.so'
    no file '/usr/local/lib/lua/5.1/gin/core/router.so'
    no file '/usr/local/nginx_x/luajit/lib/lua/5.1/gin/core/router.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
    no file '/usr/local/nginx_x/lualib/gin.so'
    no file './gin.so'
    no file '/usr/local/lib/lua/5.1/gin.so'
    no file '/usr/local/nginx_x/luajit/lib/lua/5.1/gin.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:

what's this? #{= LUA_PACKAGE_PATH }? a nginx conf syntactic sugar?

Question: API Test Coverage (gin.io + busted + luacov)

This is not an issue but a question to all gin.io users / developers.
I am currently trying to figure out how to report busted / API test coverage.

Due to the integrative / indirect nature of the tests run with hit(), there is no direct code coverage path that busted -c could use to connect the test suite driven API calls with the underlying controller implementation.

Does anybody of you have a good idea on how to achieve a code coverage report on indirect / integration tests for gin.io?

I would like to refrain from the naïve approach adding direct calls to the controller's handler functions.
Rather, I am thinking about a way

  • either for hit() to automatically add a call to the appropriate handler (as configured in routes)
  • or to read out the configured routes and track the calls to each handler using spies or the like

Anybody with any experience or code for this approach?

Transform Test Cases to Use busted 2.0

As busted 2.0 seems to be nearing a release, I would like to transform the test cases to be compatible with busted 2.0. Currently the test suite fails using 2.0 mainly when pcalls are involved. I would like to investigate and make an upgrade to the test suites. Would that contribution be welcome?

Can't start new application

Hello,

I've created new app according documentation but i doesn't start:

mephist@devbox:~/work/lua-experiments$ gin new demo
Creating app demo...
  created file demo/spec/models/.gitkeep
  created file demo/app/models/.gitkeep
  created file demo/spec/spec_helper.lua
  created file demo/config/settings.lua
  created file demo/spec/controllers/1/pages_controller_spec.lua
  created file demo/db/schemas/.gitkeep
  created file demo/db/mysql.lua
  created file demo/config/nginx.conf
  created file demo/config/errors.lua
  created file demo/lib/.gitkeep
  created file demo/config/application.lua
  created file demo/app/controllers/1/pages_controller.lua
  created file demo/db/migrations/.gitkeep
  created file demo/.gitignore
  created file demo/config/routes.lua
mephist@devbox:~/work/lua-experiments/demo$ gin start
ERROR: Cannot initialize launcher (is this a Gin project directory?).
mephist@devbox:~/work/lua-experiments/demo$

When i modified file to see some errors, I got new error.

mephist@devbox:~/work/lua-experiments/demo$ diff -u /usr/local/share/lua/5.1/gin/cli/launcher.lua.1 /usr/local/share/lua/5.1/gin/cli/launcher.lua
--- /usr/local/share/lua/5.1/gin/cli/launcher.lua.1 2013-12-15 00:33:20.724902129 +0400
+++ /usr/local/share/lua/5.1/gin/cli/launcher.lua   2013-12-15 00:38:55.628691819 +0400
@@ -139,8 +139,9 @@

 function GinLauncher.start(env)
     -- init base_launcher
-    local ok, base_launcher = pcall(function() return base_launcher() end)
-
+    local ok = true
+    base_launcher = function() return base_launcher() end
+    
     if ok == false then
         print(ansicolors("%{red}ERROR:%{reset} Cannot initialize launcher (is this a Gin project directory?)."))
         return
mephist@devbox:~/work/lua-experiments/demo$ gin start
/usr/bin/lua: /usr/local/share/lua/5.1//gin/cli/launcher.lua:150: attempt to index global 'base_launcher' (a function value)
stack traceback:
    /usr/local/share/lua/5.1//gin/cli/launcher.lua:150: in function 'start'
    /usr/local/lib/luarocks/rocks/gin/0.1.3-1/bin/gin:49: in main chunk
    [C]: ?

Could you please show me the way how to debug this issue? Thanks

LuaRocks dependency

Hi!, I just installed gin and running gin command gives me the following error:

2013/12/04 09:35 s@fenrir:~ ➯ gin
/usr/local/opt/lua/bin/lua: .../share/lua/5.1/gin/db/sql/mysql/adapter_detached.lua:2: module 'DBI' not found:No LuaRocks module found for DBI
    no field package.preload['DBI']
    no file '/usr/local/share/lua/5.1/DBI.lua'
    no file '/usr/local/share/lua/5.1/DBI/init.lua'
    no file '/Users/s/.luarocks/share/lua/5.1/DBI.lua'
    no file '/Users/s/.luarocks/share/lua/5.1/DBI/init.lua'
    no file '/usr/local/share/lua/5.1/DBI.lua'
    no file '/usr/local/share/lua/5.1/DBI/init.lua'
    no file '/Users/s/.luarocks/share/lua/5.1/DBI.lua'
    no file '/Users/s/.luarocks/share/lua/5.1/DBI/init.lua'
    no file '/usr/local/Cellar/luarocks/2.1.0/share/lua/5.1//DBI.lua'
    no file '/usr/local/Cellar/luarocks/2.1.0/share/lua/5.1//DBI/init.lua'
    no file './DBI.lua'
    no file '/usr/local/share/lua/5.1/DBI.lua'
    no file '/usr/local/share/lua/5.1/DBI/init.lua'
    no file '/usr/local/lib/lua/5.1/DBI.lua'
    no file '/usr/local/lib/lua/5.1/DBI/init.lua'
    no file '/usr/local/lib/lua/5.1/DBI.so'
    no file '/Users/s/.luarocks/lib/lua/5.1/DBI.so'
    no file '/usr/local/lib/lua/5.1/DBI.so'
    no file '/Users/s/.luarocks/lib/lua/5.1/DBI.so'
    no file './DBI.so'
    no file '/usr/local/lib/lua/5.1/DBI.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
    [C]: in function 'require'
    .../share/lua/5.1/gin/db/sql/mysql/adapter_detached.lua:2: in main chunk
    [C]: in function 'require'
    /usr/local/share/lua/5.1/gin/core/detached.lua:2: in main chunk
    [C]: in function 'require'
    /usr/local/share/lua/5.1/gin/db/migrations.lua:2: in main chunk
    [C]: in function 'require'
    /usr/local/share/lua/5.1/gin/cli/migrations.lua:7: in main chunk
    [C]: in function 'require'
    /usr/local//lib/luarocks/rocks/gin/0.1.2-1/bin/gin:45: in main chunk
    [C]: ?

Then I just run:

luarocks install dbi

And gin starts perfectly:

2013/12/04 09:38 s@fenrir:~ ➯ gin

           /++++/:
           NNNNNmm
           mNNMNmy
          .dNMMNms`
      .:+sydMMMMMdyo/-`
   `sdmmmNNNMMMMMNmdhhddo
   `dMMNNMMMMMMMMMNdhdMMy
   `dMMMNMMMMdsymMNdhdNMy
   `dMMMNNho-....:shhdNMy
   `dMMdo-......`.``:sNMy
   `dd/........-..````-hy
   `:...--.`----..`````.-
   ``//+-  G  I  N  .+-/`
   `:..-..``-...-.`.`.``-
   `hs-```-./.:`-/`.```os
   `hNms-.``.-.-.````+mmy
   `hNNNNh+.-:---`-smNNmy
   `hNNNMMMNy+.:sdNNNNNmy`
   `dNNNNMMMMMNNNNNNNNNNy`
   `hNNNNNMMMMMMMMNNmNNNy`
    ./osyhhddddddhhyss+:`

GIN v0.1, a JSON-API web framework.

Usage: gin COMMAND [ARGS]

The available gin commands are:
 new [name]             Create a new Gin application
 start                  Starts the Gin server
 stop                   Stops the Gin server
 console                Start a Gin console
 generate migration     Create a new migration
 migrate                Run all migrations that have not been run
 migrate rollback       Rollback one migration

Maybe you could add this dependency on your rockspec?
Regards

Code understanding: How postgresql connection is created?

Hello, @ostinelli!
I'm exploring your gin project code to create database management tools on top of your code (see open source project https://bitbucket.org/d9kd9k/db_tools). I hope MIT license you've chosen (https://github.com/ostinelli/gin/blob/master/LICENSE.md) allows reuse of your code?

I can't find how is postgresql connection created in non-detached postgresql adapter (file gin/db/sql/postgresql/adapter.lua). I don't need non-detached adapter for my project, but I'm curious.

Docker container for Gin

I tried to install Gin on my Macbook without success (for example, brew pcre fails).
After I tried to install it on Linux and it was even worse.
A docker container would be very useful because someone can start using Gin without caring about the complications or installs and configurations.

Can't start new application

the same problem as here:
#6

in guest OS (ubuntu 14)

vagrant@vagrant:/vagrant/data/testapp$ sudo gin start 
ERROR: Could not start Gin app on port 7200 (is it running already?).
vagrant@vagrant:/vagrant/data/testapp$ sudo gin stop
ERROR: Could not stop Gin app (are you sure it is running?).

in host os (mac osx)

MacBook-Air-myname:testapp $ gin start      
ERROR: Could not start Gin app on port 7200 (is it running already?).
MacBook-Air-myname:testapp $ gin stop         
ERROR: Could not stop Gin app (are you sure it is running?).

Can't running gin server after installed

I have installed luarockes as lua package manager and follow installation step as your document describes. Then I run commands as follows:

~ gin new demo
~ cd demo
~ gin start

After that, I get a error prompt like:
ERROR: Could not start Gin app on port 7200 (is it running already?).

So, anything wrong?

trash in project dir

vagrant@vagrant:/vagrant/data/testapp$ ls
app client_body_temp config db fastcgi_temp lib logs proxy_temp scgi_temp spec tmp uwsgi_temp

its not good to strt nginx from local dir.
this totally pollutes it with tempdirs :(

change primary key field

Hello... i have the issues what my db don't have a primary key called id.... theirs name are.. "brand_id", "city_id", etc.... how i can specify it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.