All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.nacos.common.model.RestResultUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.nacos.common.model;

import com.alibaba.nacos.common.model.core.IResultCode;

/**
 * Rest result utils.
 *
 * @author liaochuntao
 */
public class RestResultUtils {
    
    public static  RestResult success() {
        return RestResult.builder().withCode(200).build();
    }
    
    public static  RestResult success(T data) {
        return RestResult.builder().withCode(200).withData(data).build();
    }
    
    public static  RestResult success(String msg, T data) {
        return RestResult.builder().withCode(200).withMsg(msg).withData(data).build();
    }
    
    public static  RestResult success(int code, T data) {
        return RestResult.builder().withCode(code).withData(data).build();
    }
    
    public static  RestResult failed() {
        return RestResult.builder().withCode(500).build();
    }
    
    public static  RestResult failed(String errMsg) {
        return RestResult.builder().withCode(500).withMsg(errMsg).build();
    }
    
    public static  RestResult failed(int code, T data) {
        return RestResult.builder().withCode(code).withData(data).build();
    }
    
    public static  RestResult failed(int code, T data, String errMsg) {
        return RestResult.builder().withCode(code).withData(data).withMsg(errMsg).build();
    }
    
    public static  RestResult failedWithMsg(int code, String errMsg) {
        return RestResult.builder().withCode(code).withMsg(errMsg).build();
    }

    public static  RestResult buildResult(IResultCode resultCode, T data) {
        return RestResult.builder().withCode(resultCode.getCode()).withMsg(resultCode.getCodeMsg()).withData(data).build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy