using linker.libs.websocket; using System; using System.Text.Json.Serialization; namespace linker.libs.api { /// /// 前段接口 /// public interface IApiController { } /// /// 前段接口response /// public sealed class ApiControllerResponseInfo { /// /// 路径 /// public string Path { get; set; } = string.Empty; /// /// 请求id /// public long RequestId { get; set; } = 0; /// /// 状态码 /// public ApiControllerResponseCodes Code { get; set; } = ApiControllerResponseCodes.Success; /// /// 数据 /// public object Content { get; set; } = string.Empty; } /// /// 前端接口request /// public sealed class ApiControllerRequestInfo { [JsonIgnore] public WebsocketConnection Connection { get; set; } /// /// 路径 /// public string Path { get; set; } = string.Empty; /// /// 请求id /// public uint RequestId { get; set; } = 0; /// /// 数据 /// public string Content { get; set; } = string.Empty; } /// /// 前端接口执行参数 /// public sealed class ApiControllerParamsInfo { public WebsocketConnection Connection { get; set; } /// /// 请求id /// public uint RequestId { get; set; } = 0; /// /// 数据 /// public string Content { get; set; } = string.Empty; /// /// 状态码 /// public ApiControllerResponseCodes Code { get; private set; } = ApiControllerResponseCodes.Success; /// /// 错误信息 /// public string ErrorMessage { get; private set; } = string.Empty; /// /// 设置状态码 /// /// /// public void SetCode(ApiControllerResponseCodes code, string errormsg = "") { Code = code; ErrorMessage = errormsg; } /// /// 设置错误信息 /// /// public void SetErrorMessage(string msg) { Code = ApiControllerResponseCodes.Error; ErrorMessage = msg; } } /// /// 前端接口状态码 /// public enum ApiControllerResponseCodes : byte { /// /// 成功 /// Success = 0, /// /// 没找到 /// NotFound = 1, /// /// 失败 /// Error = 0xff, } /// /// 前端接口标识特性 /// [AttributeUsage(AttributeTargets.Method)] public class ApiControllerAttribute : Attribute { /// /// 参数类型 /// public Type Param { get; set; } public ApiControllerAttribute(Type param) { Param = param; } } }