Skip to content

Commit

Permalink
support endpoint with different param & fix #52
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Dec 30, 2020
1 parent ba479d4 commit f84b2f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ help: Makefile


## install_revive: Install revive for linting.
.PHONY: install_revive
install_revive:
@echo ">> ============= Install Revive ============= <<"
$(GO) get github.com/mgechev/revive


## style: Check code style.
.PHONY: style
style:
@echo ">> ============= Checking Code Style ============= <<"
@fmtRes=$$($(GOFMT) -d $$(find . -path ./vendor -prune -o -name '*.go' -print)); \
Expand All @@ -31,6 +33,7 @@ style:


## check_license: Check if license header on all files.
.PHONY: check_license
check_license:
@echo ">> ============= Checking License Header ============= <<"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
Expand All @@ -43,24 +46,28 @@ check_license:


## test_short: Run test cases with short flag.
.PHONY: test_short
test_short:
@echo ">> ============= Running Short Tests ============= <<"
$(GO) test -short $(pkgs)


## test: Run test cases.
.PHONY: test
test:
@echo ">> ============= Running All Tests ============= <<"
$(GO) test -v -cover $(pkgs)


## lint: Lint the code.
.PHONY: lint
lint:
@echo ">> ============= Lint All Files ============= <<"
revive -config config.toml -exclude vendor/... -formatter friendly ./...


## verify: Verify dependencies
.PHONY: verify
verify:
@echo ">> ============= List Dependencies ============= <<"
$(GO) list -m all
Expand All @@ -69,18 +76,21 @@ verify:


## format: Format the code.
.PHONY: format
format:
@echo ">> ============= Formatting Code ============= <<"
$(GO) fmt $(pkgs)


## vet: Examines source code and reports suspicious constructs.
.PHONY: vet
vet:
@echo ">> ============= Vetting Code ============= <<"
$(GO) vet $(pkgs)


## coverage: Create HTML coverage report
.PHONY: coverage
coverage:
@echo ">> ============= Coverage ============= <<"
rm -f coverage.html cover.out
Expand All @@ -89,11 +99,13 @@ coverage:


## ci: Run all CI tests.
.PHONY: ci
ci: style check_license test vet lint
@echo "\n==> All quality checks passed"


## run: Run the service
.PHONY: run
run:
-cp -n config.dist.json config.prod.json
$(GO) run rhino.go serve -c config.prod.json
Expand Down
15 changes: 15 additions & 0 deletions core/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/clivern/rhino/core/middleware"
"github.com/clivern/rhino/core/model"
"github.com/clivern/rhino/core/module"
"github.com/clivern/rhino/core/util"

"github.com/drone/envsubst"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -160,7 +161,19 @@ var serveCmd = &cobra.Command{
))
}

routes := []string{}

for _, route := range mockRoutes {
uri := fmt.Sprintf(
"%s:%s",
strings.ToLower(route.Request.Method),
route.Path,
)

if util.InArray(uri, routes) {
continue
}

if strings.ToLower(route.Request.Method) == "get" {
r.GET(route.Path, controller.Mock)
} else if strings.ToLower(route.Request.Method) == "post" {
Expand All @@ -176,6 +189,8 @@ var serveCmd = &cobra.Command{
} else if strings.ToLower(route.Request.Method) == "options" {
r.OPTIONS(route.Path, controller.Mock)
}

routes = append(routes, uri)
}

var runerr error
Expand Down
8 changes: 5 additions & 3 deletions core/model/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func GetRoute(path string, method string, parameters map[string]string) Route {
continue
}

// Match parametes
// Match parameters
if len(route.Request.Parameters) != 0 {
status := true

Expand Down Expand Up @@ -95,8 +95,8 @@ func GetRoute(path string, method string, parameters map[string]string) Route {
continue
}

// Match parametes
if len(route.Request.Parameters) != 0 {
// Match parameters
if len(route.Request.Parameters) == len(parameters) {
status := true

for key, value := range route.Request.Parameters {
Expand All @@ -112,6 +112,8 @@ func GetRoute(path string, method string, parameters map[string]string) Route {
if !status {
continue
}
} else {
continue
}

return route
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDf
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
github.com/prometheus/client_golang v1.8.0 h1:zvJNkoCFAnYFNC24FV8nW4JdRJ3GIFcLbg65lL/JDcw=
github.com/prometheus/client_golang v1.8.0/go.mod h1:O9VU6huf47PktckDQfMTX0Y8tY0/7TSWwj+ITvv0TnM=
github.com/prometheus/client_golang v1.9.0 h1:Rrch9mh17XcxvEu9D9DEpb4isxjGBtcevQjKvxPRQIU=
github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
Expand All @@ -304,8 +302,6 @@ github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y8
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
github.com/prometheus/common v0.14.0 h1:RHRyE8UocrbjU+6UvRzwi6HjiDfxrrBU91TtbKzkGp4=
github.com/prometheus/common v0.14.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
Expand Down Expand Up @@ -471,8 +467,6 @@ golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 h1:9UQO31fZ+0aKQOFldThf7BKPMJTiBfWycGh/u3UoO88=
golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e h1:AyodaIpKjppX+cBfTASF2E1US3H2JFBj920Ot3rtDjs=
golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down

0 comments on commit f84b2f2

Please sign in to comment.