add luacheck to lint lua files (#2205)

This commit is contained in:
halfcrazy 2018-03-19 00:31:49 +08:00 committed by Manuel Alejandro de Brito Fontes
parent 5c02d700cb
commit 977cfcb4c7
4 changed files with 19 additions and 5 deletions

2
.luacheckrc Normal file
View file

@ -0,0 +1,2 @@
std = 'ngx_lua'
globals = {'_'}

View file

@ -7,6 +7,11 @@ services:
language: go language: go
addons:
apt:
packages:
- luarocks
notifications: notifications:
email: email:
on_failure: always on_failure: always
@ -32,6 +37,8 @@ jobs:
include: include:
- stage: Static Check - stage: Static Check
script: script:
- sudo luarocks install luacheck
- make luacheck
- go get github.com/golang/lint/golint - go get github.com/golang/lint/golint
- make verify-all - make verify-all
- stage: Coverage - stage: Coverage

View file

@ -180,6 +180,10 @@ cover:
vet: vet:
@go vet $(shell go list ${PKG}/... | grep -v vendor) @go vet $(shell go list ${PKG}/... | grep -v vendor)
.PHONY: luacheck
luacheck:
luacheck -q ./rootfs/etc/nginx/lua/
.PHONY: release .PHONY: release
release: all-container all-push release: all-container all-push
echo "done" echo "done"

View file

@ -6,11 +6,11 @@ local lrucache = require("resty.lrucache")
local resty_lock = require("resty.lock") local resty_lock = require("resty.lock")
-- measured in seconds -- measured in seconds
-- for an Nginx worker to pick up the new list of upstream peers -- for an Nginx worker to pick up the new list of upstream peers
-- it will take <the delay until controller POSTed the backend object to the Nginx endpoint> + BACKENDS_SYNC_INTERVAL -- it will take <the delay until controller POSTed the backend object to the Nginx endpoint> + BACKENDS_SYNC_INTERVAL
local BACKENDS_SYNC_INTERVAL = 1 local BACKENDS_SYNC_INTERVAL = 1
ROUND_ROBIN_LOCK_KEY = "round_robin" local ROUND_ROBIN_LOCK_KEY = "round_robin"
local round_robin_state = ngx.shared.round_robin_state local round_robin_state = ngx.shared.round_robin_state
@ -37,8 +37,8 @@ local function balance()
-- Round-Robin -- Round-Robin
round_robin_lock:lock(backend_name .. ROUND_ROBIN_LOCK_KEY) round_robin_lock:lock(backend_name .. ROUND_ROBIN_LOCK_KEY)
local index = round_robin_state:get(backend_name) local last_index = round_robin_state:get(backend_name)
local index, endpoint = next(backend.endpoints, index) local index, endpoint = next(backend.endpoints, last_index)
if not index then if not index then
index = 1 index = 1
endpoint = backend.endpoints[index] endpoint = backend.endpoints[index]
@ -96,7 +96,8 @@ function _M.call()
local host, port = balance() local host, port = balance()
local ok, err = ngx_balancer.set_current_peer(host, port) local ok
ok, err = ngx_balancer.set_current_peer(host, port)
if ok then if ok then
ngx.log(ngx.INFO, "current peer is set to " .. host .. ":" .. port) ngx.log(ngx.INFO, "current peer is set to " .. host .. ":" .. port)
else else