package org.jeecg.modules.adweb.common.util;

import com.google.common.net.InternetDomainName;

import lombok.extern.slf4j.Slf4j;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * 常用工具类
 *
 * @author wfansh
 */
@Slf4j
public class CommonUtil {

    /**
     * 解析URL的顶级域名
     *
     * @param url 例如 https://www.essaynerdie.com, www.essaynerdie.com,
     *     https://www.essaynerdie.com/products
     * @return essaynerdie.com
     */
    public static String getTopPrivateDomain(String url) {
        String host = url;
        try {
            host = new URL(url).getHost();
        } catch (MalformedURLException e) {
        } finally {
            return InternetDomainName.from(host).topPrivateDomain().toString();
        }
    }
}
