mirror of https://github.com/openspug/spug
A 配置中心API新增format=env生成可作为环境变量的配置
parent
c82f41709c
commit
708ed4119c
|
@ -42,6 +42,8 @@ def get_configs(request):
|
|||
fmt = request.GET.get('format', 'kv')
|
||||
if fmt == 'kv':
|
||||
return _kv_response(data)
|
||||
elif fmt == 'env':
|
||||
return _env_response(data)
|
||||
elif fmt == 'json':
|
||||
return _json_response(data)
|
||||
else:
|
||||
|
@ -55,6 +57,13 @@ def _kv_response(data):
|
|||
return HttpResponse(output, content_type='text/plain; charset=utf-8')
|
||||
|
||||
|
||||
def _env_response(data):
|
||||
output = ''
|
||||
for k, v in sorted(data.items()):
|
||||
output += f'{k}={v}\n'
|
||||
return HttpResponse(output, content_type='text/plain; charset=utf-8')
|
||||
|
||||
|
||||
def _json_response(data):
|
||||
data = dict(sorted(data.items()))
|
||||
return HttpResponse(json.dumps(data), content_type='application/json')
|
||||
|
|
Loading…
Reference in New Issue