import json
import hashlib


def get_md5(obj, trans_func=None):
    """get a object md5, if this obj is not supported by `json.dumps` please provide a trains_func.

    Args:
        obj (object): obj to get md5
        trans_func (function, optional): use this to trans obj to str. Defaults to None.
    """
    if trans_func is None:
        trans_func = json.dumps
    obj_str = trans_func(obj)
    hl = hashlib.md5()
    hl.update(obj_str.encode(encoding='utf-8'))
    return hl.hexdigest()