Skip to content

Instantly share code, notes, and snippets.

@zhu327
Last active March 26, 2018 02:27
Show Gist options
  • Save zhu327/24c8262dc40c5de7eeaddbfc572f4215 to your computer and use it in GitHub Desktop.
Save zhu327/24c8262dc40c5de7eeaddbfc572f4215 to your computer and use it in GitHub Desktop.
simple doge json gateway
# coding: utf-8
import argparse
from gevent import monkey
monkey.patch_socket()
import logging
logging.basicConfig(level=logging.DEBUG)
from gevent.wsgi import WSGIServer
from doge.rpc.client import Cluster
from bottle import post, request, abort, app
global cluster
@post('/<service>/<method>')
def gateway(service, method):
params = request.json
if params is None:
abort(400)
global cluster
try:
client = cluster.get_client(service)
res = client.call(method, *params)
return {"errcode": 0, "errmsg": None, "result": res}
except Exception as e:
logging.exception('Error')
return {"errcode": 1, "errmsg": str(e), "result": None}
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('conf',
type=str,
help='doge client json config file path')
args = parser.parse_args()
logging.info('Init doge cluster from conf {}.'.format(args.conf))
global cluster
cluster = Cluster(args.conf)
logging.info('Start doge gateway server.')
WSGIServer(('', 8000), app()).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment