Просмотр исходного кода

1. 让Http处理方法,支持async。

Yinmany 7 лет назад
Родитель
Сommit
f132a347f6

+ 47 - 47
Server/Hotfix/Module/Http/HttpTest.cs

@@ -4,53 +4,53 @@ using System.Threading.Tasks;
 
 namespace ETHotfix
 {
-  [HttpHandler(AppType.Gate, "/")]
-  public class HttpTest : AHttpHandler
-  {
-    [Get] // url-> /Login?name=11&age=1111
-    public string Login(string name, int age, HttpListenerRequest req, HttpListenerResponse resp)
+    [HttpHandler(AppType.Gate, "/")]
+    public class HttpTest : AHttpHandler
     {
-      Log.Info(name);
-      Log.Info($"{age}");
-      return "ok";
+        [Get] // url-> /Login?name=11&age=1111
+        public string Login(string name, int age, HttpListenerRequest req, HttpListenerResponse resp)
+        {
+            Log.Info(name);
+            Log.Info($"{age}");
+            return "ok";
+        }
+
+        [Get("t")] // url-> /t
+        public int Test()
+        {
+            return 1;
+        }
+
+        [Post] // url-> /Test1
+        public int Test1(HttpListenerRequest req)
+        {
+            return 1;
+        }
+
+        [Get] // url-> /Test2
+        public int Test2(HttpListenerResponse resp)
+        {
+            return 1;
+        }
+
+        [Get] // url-> /GetRechargeRecord
+        public async Task<HttpResult> GetRechargeRecord(long id)
+        {
+            // var db = Game.Scene.GetComponent<DBProxyComponent>();
+
+            // var info = await db.Query<RechargeRecord>(id);
+
+            await Task.Delay(1000); // 用于测试
+
+            object info = null;
+            if (info != null)
+            {
+                return Ok(data: info);
+            }
+            else
+            {
+                return Error("ID不存在!");
+            }
+        }
     }
-
-    [Get("t")] // url-> /t
-    public int Test()
-    {
-      return 1;
-    }
-
-    [Post] // url-> /Test1
-    public int Test1(HttpListenerRequest req)
-    {
-      return 1;
-    }
-
-    [Get] // url-> /Test2
-    public int Test2(HttpListenerResponse resp)
-    {
-      return 1;
-    }
-
-    [Get] // url-> /GetRechargeRecord
-    public async Task<HttpResult> GetRechargeRecord(long id)
-    {
-     // var db = Game.Scene.GetComponent<DBProxyComponent>();
-
-     // var info = await db.Query<RechargeRecord>(id);
-
-      await Task.Delay(1000); // 用于测试
-
-      object info = null;
-      if (info != null)
-      {
-        return Ok(data: info);
-      }
-      else
-      {
-        return Error("ID不存在!");
-      }
-    }
-  }
 }

+ 35 - 35
Server/Model/Entity/Http.cs

@@ -1,47 +1,47 @@
 namespace ETModel
 {
-  // 充值流水
-  public sealed class RechargeRecord : Entity
-  {
-    // 充值玩家
-    public int PlayerNO { get; set; }
+    // 充值流水
+    public sealed class RechargeRecord : Entity
+    {
+        // 充值玩家
+        public int PlayerNO { get; set; }
 
-    // 充值数量
-    public int CardNumber { get; set; }
+        // 充值数量
+        public int CardNumber { get; set; }
 
-    // 充值时间
-    public long Time { get; set; }
+        // 充值时间
+        public long Time { get; set; }
 
-    public RechargeRecord(long id) : base(id)
-    {
+        public RechargeRecord(long id) : base(id)
+        {
+        }
     }
-  }
 
-  // 保存玩家充值记录, 每个玩家只有一条
-  public sealed class Recharge : Entity
-  {
-    public int CardNumber { get; set; }
+    // 保存玩家充值记录, 每个玩家只有一条
+    public sealed class Recharge : Entity
+    {
+        public int CardNumber { get; set; }
+
+        public long UpdateTime { get; set; }
 
-    public long UpdateTime { get; set; }
+        public Recharge(long id) : base(id)
+        {
+        }
+    }
+
+    public class HttpResult
+    {
+        public int code;
+        public bool status;
+        public string msg = "";
+        [MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
+        public object data;
+    }
 
-    public Recharge(long id) : base(id)
+    public static class HttpErrorCode
     {
+        public const int Exception = 999;
+        public const int Success = 1000;
+        public const int RpcFail = 1002;
     }
-  }
-
-  public class HttpResult
-  {
-    public int code;
-    public bool status;
-    public string msg = "";
-    [MongoDB.Bson.Serialization.Attributes.BsonIgnoreIfNull]
-    public object data;
-  }
-
-  public static class HttpErrorCode
-  {
-    public const int Exception = 999;
-    public const int Success = 1000;
-    public const int RpcFail = 1002;
-  }
 }

+ 274 - 274
Server/Model/Module/Http/HttpComponent.cs

@@ -7,334 +7,334 @@ using System.Threading.Tasks;
 
 namespace ETModel
 {
-  [ObjectSystem]
-  public class HttpComponentComponentAwakeSystem : AwakeSystem<HttpComponent>
-  {
-    public override void Awake(HttpComponent self)
+    [ObjectSystem]
+    public class HttpComponentComponentAwakeSystem : AwakeSystem<HttpComponent>
     {
-      self.Awake();
+        public override void Awake(HttpComponent self)
+        {
+            self.Awake();
+        }
     }
-  }
 
-  [ObjectSystem]
-  public class HttpComponentComponentLoadSystem : LoadSystem<HttpComponent>
-  {
-    public override void Load(HttpComponent self)
+    [ObjectSystem]
+    public class HttpComponentComponentLoadSystem : LoadSystem<HttpComponent>
     {
-      self.Load();
+        public override void Load(HttpComponent self)
+        {
+            self.Load();
+        }
     }
-  }
 
-  [ObjectSystem]
-  public class HttpComponentComponentStartSystem : StartSystem<HttpComponent>
-  {
-    public override void Start(HttpComponent self)
+    [ObjectSystem]
+    public class HttpComponentComponentStartSystem : StartSystem<HttpComponent>
     {
-      self.Start();
-    }
-  }
-
-  /// <summary>
-  /// http请求分发器
-  /// </summary>
-  public class HttpComponent : Component
-  {
-    public AppType appType;
-    public HttpListener listener;
-    public HttpConfig HttpConfig;
-    public Dictionary<string, IHttpHandler> dispatcher;
-
-    // 处理方法
-    private Dictionary<MethodInfo, IHttpHandler> handlersMapping;
-
-    // Get处理
-    private Dictionary<string, MethodInfo> getHandlers;
-    private Dictionary<string, MethodInfo> postHandlers;
-
-    public void Awake()
-    {
-      StartConfig startConfig = Game.Scene.GetComponent<StartConfigComponent>().StartConfig;
-      this.appType = startConfig.AppType;
-      this.HttpConfig = startConfig.GetComponent<HttpConfig>();
-
-      this.Load();
+        public override void Start(HttpComponent self)
+        {
+            self.Start();
+        }
     }
 
-    public void Load()
+    /// <summary>
+    /// http请求分发器
+    /// </summary>
+    public class HttpComponent : Component
     {
-      this.dispatcher = new Dictionary<string, IHttpHandler>();
-      this.handlersMapping = new Dictionary<MethodInfo, IHttpHandler>();
-      this.getHandlers = new Dictionary<string, MethodInfo>();
-      this.postHandlers = new Dictionary<string, MethodInfo>();
+        public AppType appType;
+        public HttpListener listener;
+        public HttpConfig HttpConfig;
+        public Dictionary<string, IHttpHandler> dispatcher;
 
-      Type[] types = DllHelper.GetMonoTypes();
+        // 处理方法
+        private Dictionary<MethodInfo, IHttpHandler> handlersMapping;
 
-      foreach (Type type in types)
-      {
-        object[] attrs = type.GetCustomAttributes(typeof(HttpHandlerAttribute), false);
-        if (attrs.Length == 0)
-        {
-          continue;
-        }
+        // Get处理
+        private Dictionary<string, MethodInfo> getHandlers;
+        private Dictionary<string, MethodInfo> postHandlers;
 
-        HttpHandlerAttribute httpHandlerAttribute = (HttpHandlerAttribute)attrs[0];
-        if (!httpHandlerAttribute.AppType.Is(this.appType))
+        public void Awake()
         {
-          continue;
-        }
-
-        object obj = Activator.CreateInstance(type);
+            StartConfig startConfig = Game.Scene.GetComponent<StartConfigComponent>().StartConfig;
+            this.appType = startConfig.AppType;
+            this.HttpConfig = startConfig.GetComponent<HttpConfig>();
 
-        IHttpHandler ihttpHandler = obj as IHttpHandler;
-        if (ihttpHandler == null)
-        {
-          throw new Exception($"HttpHandler handler not inherit IHttpHandler class: {obj.GetType().FullName}");
+            this.Load();
         }
 
-        this.dispatcher.Add(httpHandlerAttribute.Path, ihttpHandler);
+        public void Load()
+        {
+            this.dispatcher = new Dictionary<string, IHttpHandler>();
+            this.handlersMapping = new Dictionary<MethodInfo, IHttpHandler>();
+            this.getHandlers = new Dictionary<string, MethodInfo>();
+            this.postHandlers = new Dictionary<string, MethodInfo>();
 
-        LoadMethod(type, httpHandlerAttribute, ihttpHandler);
-      }
-    }
+            Type[] types = DllHelper.GetMonoTypes();
 
-    public void Start()
-    {
-      try
-      {
-        this.listener = new HttpListener();
+            foreach (Type type in types)
+            {
+                object[] attrs = type.GetCustomAttributes(typeof(HttpHandlerAttribute), false);
+                if (attrs.Length == 0)
+                {
+                    continue;
+                }
 
-        if (this.HttpConfig.Url == null)
-        {
-          this.HttpConfig.Url = "";
-        }
+                HttpHandlerAttribute httpHandlerAttribute = (HttpHandlerAttribute)attrs[0];
+                if (!httpHandlerAttribute.AppType.Is(this.appType))
+                {
+                    continue;
+                }
 
-        foreach (string s in this.HttpConfig.Url.Split(';'))
-        {
-          if (s.Trim() == "")
-          {
-            continue;
-          }
+                object obj = Activator.CreateInstance(type);
 
-          this.listener.Prefixes.Add(s);
-        }
+                IHttpHandler ihttpHandler = obj as IHttpHandler;
+                if (ihttpHandler == null)
+                {
+                    throw new Exception($"HttpHandler handler not inherit IHttpHandler class: {obj.GetType().FullName}");
+                }
 
-        this.listener.Start();
+                this.dispatcher.Add(httpHandlerAttribute.Path, ihttpHandler);
 
-        this.Accept();
-      }
-      catch (HttpListenerException e)
-      {
-        throw new Exception($"http server error: {e.ErrorCode}", e);
-      }
-    }
+                LoadMethod(type, httpHandlerAttribute, ihttpHandler);
+            }
+        }
 
-    public void LoadMethod(Type type, HttpHandlerAttribute httpHandlerAttribute, IHttpHandler httpHandler)
-    {
-      // 扫描这个类里面的方法
-      MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance);
-      foreach (MethodInfo method in methodInfos)
-      {
-        object[] getAttrs = method.GetCustomAttributes(typeof(GetAttribute), false);
-        if (getAttrs.Length != 0)
+        public void Start()
         {
-          GetAttribute get = (GetAttribute)getAttrs[0];
+            try
+            {
+                this.listener = new HttpListener();
 
-          string path = method.Name;
-          if (!string.IsNullOrEmpty(get.Path))
-          {
-            path = get.Path;
-          }
+                if (this.HttpConfig.Url == null)
+                {
+                    this.HttpConfig.Url = "";
+                }
 
-          getHandlers.Add(httpHandlerAttribute.Path + path, method);
-          //Log.Debug($"add handler[{httpHandler}.{method.Name}] path {httpHandlerAttribute.Path + path}");
-        }
+                foreach (string s in this.HttpConfig.Url.Split(';'))
+                {
+                    if (s.Trim() == "")
+                    {
+                        continue;
+                    }
 
-        object[] postAttrs = method.GetCustomAttributes(typeof(PostAttribute), false);
-        if (postAttrs.Length != 0)
-        {
-          // Post处理方法
-          PostAttribute post = (PostAttribute)postAttrs[0];
+                    this.listener.Prefixes.Add(s);
+                }
 
-          string path = method.Name;
-          if (!string.IsNullOrEmpty(post.Path))
-          {
-            path = post.Path;
-          }
+                this.listener.Start();
 
-          postHandlers.Add(httpHandlerAttribute.Path + path, method);
-          //Log.Debug($"add handler[{httpHandler}.{method.Name}] path {httpHandlerAttribute.Path + path}");
+                this.Accept();
+            }
+            catch (HttpListenerException e)
+            {
+                throw new Exception($"http server error: {e.ErrorCode}", e);
+            }
         }
 
-        if (getAttrs.Length == 0 && postAttrs.Length == 0)
+        public void LoadMethod(Type type, HttpHandlerAttribute httpHandlerAttribute, IHttpHandler httpHandler)
         {
-          continue;
+            // 扫描这个类里面的方法
+            MethodInfo[] methodInfos = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance);
+            foreach (MethodInfo method in methodInfos)
+            {
+                object[] getAttrs = method.GetCustomAttributes(typeof(GetAttribute), false);
+                if (getAttrs.Length != 0)
+                {
+                    GetAttribute get = (GetAttribute)getAttrs[0];
+
+                    string path = method.Name;
+                    if (!string.IsNullOrEmpty(get.Path))
+                    {
+                        path = get.Path;
+                    }
+
+                    getHandlers.Add(httpHandlerAttribute.Path + path, method);
+                    //Log.Debug($"add handler[{httpHandler}.{method.Name}] path {httpHandlerAttribute.Path + path}");
+                }
+
+                object[] postAttrs = method.GetCustomAttributes(typeof(PostAttribute), false);
+                if (postAttrs.Length != 0)
+                {
+                    // Post处理方法
+                    PostAttribute post = (PostAttribute)postAttrs[0];
+
+                    string path = method.Name;
+                    if (!string.IsNullOrEmpty(post.Path))
+                    {
+                        path = post.Path;
+                    }
+
+                    postHandlers.Add(httpHandlerAttribute.Path + path, method);
+                    //Log.Debug($"add handler[{httpHandler}.{method.Name}] path {httpHandlerAttribute.Path + path}");
+                }
+
+                if (getAttrs.Length == 0 && postAttrs.Length == 0)
+                {
+                    continue;
+                }
+
+                handlersMapping.Add(method, httpHandler);
+            }
         }
 
-        handlersMapping.Add(method, httpHandler);
-      }
-    }
-
-    public async void Accept()
-    {
-      while (true)
-      {
-        if (this.IsDisposed)
+        public async void Accept()
         {
-          return;
-        }
-
-        HttpListenerContext context = await this.listener.GetContextAsync();
-        await InvokeHandler(context);
-        context.Response.Close();
-      }
-    }
-
-    /// <summary>
-    /// 调用处理方法
-    /// </summary>
-    /// <param name="context"></param>
-    private async Task InvokeHandler(HttpListenerContext context)
-    {
-      context.Response.StatusCode = 404;
-
-      MethodInfo methodInfo = null;
-      IHttpHandler httpHandler = null;
-      string postbody = "";
-      switch (context.Request.HttpMethod)
-      {
-        case "GET":
-          this.getHandlers.TryGetValue(context.Request.Url.AbsolutePath, out methodInfo);
-          if (methodInfo != null)
-          {
-            this.handlersMapping.TryGetValue(methodInfo, out httpHandler);
-          }
-          break;
-        case "POST":
-          this.postHandlers.TryGetValue(context.Request.Url.AbsolutePath, out methodInfo);
-          if (methodInfo != null)
-          {
-            this.handlersMapping.TryGetValue(methodInfo, out httpHandler);
-
-            using (StreamReader sr = new StreamReader(context.Request.InputStream))
+            while (true)
             {
-              postbody = sr.ReadToEnd();
+                if (this.IsDisposed)
+                {
+                    return;
+                }
+
+                HttpListenerContext context = await this.listener.GetContextAsync();
+                await InvokeHandler(context);
+                context.Response.Close();
             }
-          }
-          break;
-        default:
-          context.Response.StatusCode = 405;
-          break;
-      }
-
-      if (httpHandler != null)
-      {
-        object[] args = InjectParameters(context, methodInfo, postbody);
-
-        // 自动把返回值,以json方式响应。
-        object resp = methodInfo.Invoke(httpHandler, args);
-        object result = resp;
-        if (resp is Task t)
-        {
-          await t;
-          result = t.GetType().GetProperty("Result").GetValue(t, null);
         }
 
-        if (result != null)
+        /// <summary>
+        /// 调用处理方法
+        /// </summary>
+        /// <param name="context"></param>
+        private async Task InvokeHandler(HttpListenerContext context)
         {
-          using (StreamWriter sw = new StreamWriter(context.Response.OutputStream))
-          {
-            if (result.GetType() == typeof(string))
+            context.Response.StatusCode = 404;
+
+            MethodInfo methodInfo = null;
+            IHttpHandler httpHandler = null;
+            string postbody = "";
+            switch (context.Request.HttpMethod)
             {
-              sw.Write(result.ToString());
+                case "GET":
+                    this.getHandlers.TryGetValue(context.Request.Url.AbsolutePath, out methodInfo);
+                    if (methodInfo != null)
+                    {
+                        this.handlersMapping.TryGetValue(methodInfo, out httpHandler);
+                    }
+                    break;
+                case "POST":
+                    this.postHandlers.TryGetValue(context.Request.Url.AbsolutePath, out methodInfo);
+                    if (methodInfo != null)
+                    {
+                        this.handlersMapping.TryGetValue(methodInfo, out httpHandler);
+
+                        using (StreamReader sr = new StreamReader(context.Request.InputStream))
+                        {
+                            postbody = sr.ReadToEnd();
+                        }
+                    }
+                    break;
+                default:
+                    context.Response.StatusCode = 405;
+                    break;
             }
-            else
+
+            if (httpHandler != null)
             {
-              sw.Write(JsonHelper.ToJson(result));
+                object[] args = InjectParameters(context, methodInfo, postbody);
+
+                // 自动把返回值,以json方式响应。
+                object resp = methodInfo.Invoke(httpHandler, args);
+                object result = resp;
+                if (resp is Task t)
+                {
+                    await t;
+                    result = t.GetType().GetProperty("Result").GetValue(t, null);
+                }
+
+                if (result != null)
+                {
+                    using (StreamWriter sw = new StreamWriter(context.Response.OutputStream))
+                    {
+                        if (result.GetType() == typeof(string))
+                        {
+                            sw.Write(result.ToString());
+                        }
+                        else
+                        {
+                            sw.Write(JsonHelper.ToJson(result));
+                        }
+                    }
+                }
             }
-          }
         }
-      }
-    }
 
-    /// <summary>
-    /// 注入参数
-    /// </summary>
-    /// <param name="context"></param>
-    /// <param name="methodInfo"></param>
-    /// <param name="postbody"></param>
-    /// <returns></returns>
-    private static object[] InjectParameters(HttpListenerContext context, MethodInfo methodInfo, string postbody)
-    {
-      context.Response.StatusCode = 200;
-      ParameterInfo[] parameterInfos = methodInfo.GetParameters();
-      object[] args = new object[parameterInfos.Length];
-      for (int i = 0; i < parameterInfos.Length; i++)
-      {
-        ParameterInfo item = parameterInfos[i];
-
-        if (item.ParameterType == typeof(HttpListenerRequest))
+        /// <summary>
+        /// 注入参数
+        /// </summary>
+        /// <param name="context"></param>
+        /// <param name="methodInfo"></param>
+        /// <param name="postbody"></param>
+        /// <returns></returns>
+        private static object[] InjectParameters(HttpListenerContext context, MethodInfo methodInfo, string postbody)
         {
-          args[i] = context.Request;
-          continue;
-        }
+            context.Response.StatusCode = 200;
+            ParameterInfo[] parameterInfos = methodInfo.GetParameters();
+            object[] args = new object[parameterInfos.Length];
+            for (int i = 0; i < parameterInfos.Length; i++)
+            {
+                ParameterInfo item = parameterInfos[i];
+
+                if (item.ParameterType == typeof(HttpListenerRequest))
+                {
+                    args[i] = context.Request;
+                    continue;
+                }
+
+                if (item.ParameterType == typeof(HttpListenerResponse))
+                {
+                    args[i] = context.Response;
+                    continue;
+                }
+
+                try
+                {
+                    switch (context.Request.HttpMethod)
+                    {
+                        case "POST":
+                            if (item.Name == "postBody") // 约定参数名称为postBody,只传string类型。本来是byte[],有需求可以改。
+                            {
+                                args[i] = postbody;
+                            }
+                            else if (item.ParameterType.IsClass && item.ParameterType != typeof(string) && !string.IsNullOrEmpty(postbody))
+                            {
+                                object entity = JsonHelper.FromJson(item.ParameterType, postbody);
+                                args[i] = entity;
+                            }
+
+                            break;
+                        case "GET":
+                            string query = context.Request.QueryString[item.Name];
+                            if (query != null)
+                            {
+                                object value = Convert.ChangeType(query, item.ParameterType);
+                                args[i] = value;
+                            }
+
+                            break;
+                        default:
+                            args[i] = null;
+                            break;
+                    }
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                    args[i] = null;
+                }
+            }
 
-        if (item.ParameterType == typeof(HttpListenerResponse))
-        {
-          args[i] = context.Response;
-          continue;
+            return args;
         }
 
-        try
-        {
-          switch (context.Request.HttpMethod)
-          {
-            case "POST":
-              if (item.Name == "postBody") // 约定参数名称为postBody,只传string类型。本来是byte[],有需求可以改。
-              {
-                args[i] = postbody;
-              }
-              else if (item.ParameterType.IsClass && item.ParameterType != typeof(string) && !string.IsNullOrEmpty(postbody))
-              {
-                object entity = JsonHelper.FromJson(item.ParameterType, postbody);
-                args[i] = entity;
-              }
-
-              break;
-            case "GET":
-              string query = context.Request.QueryString[item.Name];
-              if (query != null)
-              {
-                object value = Convert.ChangeType(query, item.ParameterType);
-                args[i] = value;
-              }
-
-              break;
-            default:
-              args[i] = null;
-              break;
-          }
-        }
-        catch (Exception e)
+        public override void Dispose()
         {
-          Log.Error(e);
-          args[i] = null;
-        }
-      }
-
-      return args;
-    }
-
-    public override void Dispose()
-    {
-      if (this.IsDisposed)
-      {
-        return;
-      }
+            if (this.IsDisposed)
+            {
+                return;
+            }
 
-      base.Dispose();
+            base.Dispose();
 
-      this.listener.Stop();
-      this.listener.Close();
+            this.listener.Stop();
+            this.listener.Close();
+        }
     }
-  }
 }

+ 42 - 42
Server/Model/Module/Http/HttpHandlerAttribute.cs

@@ -2,46 +2,46 @@
 
 namespace ETModel
 {
-	public class HttpHandlerAttribute: Attribute
-	{
-		public AppType AppType { get; }
-
-		public string Path { get; }
-
-		public HttpHandlerAttribute(AppType appType, string path)
-		{
-			this.AppType = appType;
-			this.Path = path;
-		}
-	}
-
-	[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
-	public class GetAttribute: Attribute
-	{
-		public string Path { get; }
-
-		public GetAttribute()
-		{
-		}
-
-		public GetAttribute(string path)
-		{
-			this.Path = path;
-		}
-	}
-
-	[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
-	public class PostAttribute: Attribute
-	{
-		public string Path { get; }
-
-		public PostAttribute()
-		{
-		}
-
-		public PostAttribute(string path)
-		{
-			this.Path = path;
-		}
-	}
+    public class HttpHandlerAttribute : Attribute
+    {
+        public AppType AppType { get; }
+
+        public string Path { get; }
+
+        public HttpHandlerAttribute(AppType appType, string path)
+        {
+            this.AppType = appType;
+            this.Path = path;
+        }
+    }
+
+    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
+    public class GetAttribute : Attribute
+    {
+        public string Path { get; }
+
+        public GetAttribute()
+        {
+        }
+
+        public GetAttribute(string path)
+        {
+            this.Path = path;
+        }
+    }
+
+    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)]
+    public class PostAttribute : Attribute
+    {
+        public string Path { get; }
+
+        public PostAttribute()
+        {
+        }
+
+        public PostAttribute(string path)
+        {
+            this.Path = path;
+        }
+    }
 }

+ 26 - 26
Server/Model/Module/Http/IHttpHandler.cs

@@ -2,35 +2,35 @@
 
 namespace ETModel
 {
-  public interface IHttpHandler
-  {
-    void Handle(HttpListenerContext context);
-  }
-
-  public abstract class AHttpHandler : IHttpHandler
-  {
-    public virtual void Handle(HttpListenerContext context)
-    {
-    }
-    public virtual HttpResult Ok(string msg = "", object data = null)
+    public interface IHttpHandler
     {
-      return new HttpResult
-      {
-        code = HttpErrorCode.Success,
-        msg = msg,
-        status = true,
-        data = data
-      };
+        void Handle(HttpListenerContext context);
     }
 
-    public virtual HttpResult Error(string msg = "")
+    public abstract class AHttpHandler : IHttpHandler
     {
-      return new HttpResult
-      {
-        code = HttpErrorCode.Exception,
-        msg = msg,
-        status = false
-      };
+        public virtual void Handle(HttpListenerContext context)
+        {
+        }
+        public virtual HttpResult Ok(string msg = "", object data = null)
+        {
+            return new HttpResult
+            {
+                code = HttpErrorCode.Success,
+                msg = msg,
+                status = true,
+                data = data
+            };
+        }
+
+        public virtual HttpResult Error(string msg = "")
+        {
+            return new HttpResult
+            {
+                code = HttpErrorCode.Exception,
+                msg = msg,
+                status = false
+            };
+        }
     }
-  }
 }