Coder Social home page Coder Social logo

qstubserver's Introduction

Q Stub Server

GO言語で作成しております。

いろいろな開発においてAPIへのアクセスやテスト等で自分自身がほしいな〜と思ったスタブサーバを作成しました。

機能

  • 特定URLからローカルファイルを転送します。
  • 特定URLから情報を別サーバへ転送します。
  • リクエスト、レスポンスの内容をファイル出力します。
  • URLだけでなくヘッダ、ボディの内容でフィルタリングも可能です。

特定のURLからローカルファイルを転送する。

Setting.jsonの内容を編集します。

アクセスを全て/user/hoge/webroot/配下のローカルファイルのアクセスに変換する。
正規表現で対応します。

{
  "convertList": [
    {
      "srcURL" : "/(.*)",
      "destPath" : "/user/hoge/webroot/$1"
    }
  ]
}

/へのアクセスにindex.htmlを返却する。その他は上記と同じに。
上から順に処理されていくため、優先するものは上位に設定します。�

{
  "convertList": [
    {
      "srcURL" : "/",
      "destPath" : "/user/hoge/webroot/index.html"
    },
    {
      "srcURL" : "/(.*)",
      "destPath" : "/user/hoge/webroot/$1"
    }
  ]
}

ファイルに別途ContentTypeを指定する。
index.htmlの場合Content-Type: application/octet-streamが指定される。
省略時はContentTypeList.jsonから拡張子で自動で設定されます。

{
  "convertList": [
    {
      "srcURL" : "/",
      "destPath" : "/user/hoge/webroot/index.html",
      "contentType" : "application/octet-stream"
    },
    {
      "srcURL" : "/(.*)",
      "destPath" : "/user/hoge/webroot/$1"
    }
  ]
}

特定のURLを別サーバへ転送する。

アクセスを全てhttp://192.168.1.10:9999/に転送する。

{
  "convertList": [
    {
      "srcURL" : "/(.*)",
      "destURL" : "http://192.168.1.10:9999/$1"
    }
  ]
}

/hoge/の場合ローカルファイルにアクセスする。その他は上記と同じに。

{
  "convertList": [
    {
      "srcURL" : "/hoge/(.*)",
      "destPath" : "/user/hoge/webroot/$1"
    },
    {
      "srcURL" : "/(.*)",
      "destURL" : "http://192.168.1.10:9999/$1"
    }
  ]
}

ヘッダ情報でフィルタリングする。

文字コードがutf-8ならばローカルファイルにアクセスし、それ以外は別サイトへ転送する(フィルタリングの正規表現は適当です)。

{
  "convertList": [
    {
      "srcURL" : "/(.*)",
      "destPath" : "/user/hoge/webroot/$1",
      "filterList" : [
        {
          "type" : "header",
          "condition" : "Content-Type: ([\\S]+); charset=utf-8"
        }
      ]
    },
    {
      "srcURL" : "/(.*)",
      "destURL" : "http://192.168.1.10:9999/$1"
    }
  ]
}

文字コードがutf-8でボディ情報がOKならばローカルファイルにアクセスし、それ以外は別サイトへ転送する(フィルタリングの正規表現は適当です)。

{
  "convertList": [
    {
      "srcURL" : "/(.*)",
      "destPath" : "/user/hoge/webroot/$1",
      "filterList" : [
        {
          "type" : "header",
          "condition" : "Content-Type: ([\\S]+); charset=utf-8"
        },
        {
          "type" : "body",
          "condition" : "OK"
        }
      ]
    },
    {
      "srcURL" : "/(.*)",
      "destURL" : "http://192.168.1.10:9999/$1"
    }
  ]
}

現在typeに指定できるのはheaderbodyのみです。

コマンドについて

ポートを9999に設定する。(デフォルトは8080)

> QStubServer -port 9999

Setting.jsonのパスを指定する。(デフォルトは[カレントディレクトリ]+Setting.json)

> QStubServer -setting /usr/hoge/QStubServer/Setting.json

ContentTypeList.jsonのパスを指定する。(デフォルトは[カレントディレクトリ]+ContentTypeList.json)

> QStubServer -contenttype /usr/hoge/QStubServer/ContentTypeList.json

リクエスト、レスポンス内容をファイルに出力する。
/usr/hoge/QStubServer/log配下へ内容を出力します。

> QStubServer -outputlog /usr/hoge/QStubServer/log

ビルド環境について

このライブラリのビルドは
https://github.com/constabulary/gb
で行っております。

qstubserver's People

Stargazers

tesang avatar

Watchers

James Cloos avatar momons avatar

qstubserver's Issues

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.