Skip to content

Commit

Permalink
support mock rel path (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Sep 18, 2020
1 parent 4c196df commit bedf663
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:1.15.2

ARG RHINO_VERSION=1.1.0
ARG RHINO_VERSION=1.2.0

ENV GO111MODULE=on

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<p align="center">
<img alt="Rhino Logo" src="https://raw.githubusercontent.com/clivern/Rhino/master/assets/img/gopher.png?v=1.1.0" width="150" />
<img alt="Rhino Logo" src="https://raw.githubusercontent.com/clivern/Rhino/master/assets/img/gopher.png?v=1.2.0" width="150" />
<h3 align="center">Rhino</h3>
<p align="center">HTTP Mocking & Debugging Service</p>
<p align="center">
<a href="https://travis-ci.com/Clivern/Rhino"><img src="https://travis-ci.com/Clivern/Rhino.svg?branch=master"></a>
<a href="https://github.com/Clivern/Rhino/releases"><img src="https://img.shields.io/badge/Version-1.1.0-red.svg"></a>
<a href="https://goreportcard.com/report/github.com/Clivern/Rhino"><img src="https://goreportcard.com/badge/github.com/clivern/Rhino?v=1.1.0"></a>
<a href="https://github.com/Clivern/Rhino/releases"><img src="https://img.shields.io/badge/Version-1.2.0-red.svg"></a>
<a href="https://goreportcard.com/report/github.com/Clivern/Rhino"><img src="https://goreportcard.com/badge/github.com/clivern/Rhino?v=1.2.0"></a>
<a href="https://hub.docker.com/r/clivern/rhino"><img src="https://img.shields.io/badge/Docker-Latest-green"></a>
<a href="https://github.com/Clivern/Rhino/blob/master/LICENSE"><img src="https://img.shields.io/badge/LICENSE-MIT-orange.svg"></a>
</p>
Expand Down Expand Up @@ -69,7 +69,7 @@ Create the config file `config.prod.json`
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "@json:/path/to/service2/route.response.json"
"body": "@json:@config_dir/route.response.json"
},
"chaos": {
"latency": "0s",
Expand Down
2 changes: 1 addition & 1 deletion config.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"headers": [
{"key": "Content-Type", "value": "application/json"}
],
"body": "@json:/path/to/service2/route.response.json"
"body": "@json:@config_dir/route.response.json"
},
"chaos": {
"latency": "0s",
Expand Down
2 changes: 2 additions & 0 deletions core/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ var serveCmd = &cobra.Command{
))
}

viper.SetDefault("configPath", filepath.Dir(config))

if viper.GetString("log.output") != "stdout" {
fs := module.FileSystem{}
dir, _ := filepath.Split(viper.GetString("log.output"))
Expand Down
2 changes: 2 additions & 0 deletions core/controller/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

// Mock controller
Expand Down Expand Up @@ -76,6 +77,7 @@ func Mock(c *gin.Context) {

if strings.Contains(route.Response.Body, "@json:") {
path := strings.Replace(route.Response.Body, "@json:", "", -1)
path = strings.Replace(path, "@config_dir", viper.GetString("configPath"), -1)
content, err := ioutil.ReadFile(path)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion deployment/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
rhino:
image: 'clivern/rhino:release-1.1.0'
image: 'clivern/rhino:release-1.2.0'
ports:
- "8080:8080"
command: '/app/rhino serve -c /app/configs/config.prod.json'
Expand Down

0 comments on commit bedf663

Please sign in to comment.