#coding=utf-8

from rest_framework import status
from rest_framework.response import Response

def response_error(msg, errcode=None):
    code = 1
    if errcode:
        code = errcode
    return Response({"code":code, "msg": msg}, status=status.HTTP_200_OK)

def response_ok(data=None):
    if data != None:
        return Response({"code":0, 'data': data})
    else:
        return Response({"code":0})

def get_remote_addr(request):
    x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = request.META.get('REMOTE_ADDR')
    return ip