# Rabbit Go **Repository Path**: nygula/Rabbit-Go ## Basic Information - **Project Name**: Rabbit Go - **Description**: Rabbit Go - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-05-10 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Rabbit Go 一个设计为通用的强类型客户端。 目前只提供了Http的支持 **NuGet:** https://www.nuget.org/packages/Rabbit.Go.Core # 1. 一个简单的示例 ## 1.1 声明 ```c# [Go("http://api.com/user")] [DefaultHeader("access_token", "xxxxxxxxxx")] [DefaultQuery("project", "samples")] public interface IUserGoClient { [GoGet("/{id}")] Task GetAsync(long id); [GoDelete("/{id}")] Task DeleteAsync(long id); [GoPost] Task PostAsync([GoBody]PostUserModel model); [GoPut("/{id}")] Task PutAsync(long id, [GoBody]PutUserModel model); } public class UserModel { [KeyName("user_name")] public string UserName { get; set; } [CustomFormatter(typeof(PasswordFormatter))] public string Password { get; set; } public int? Age { get; set; } [PropertyIgnore] public bool IsAdult { get; set; } } public class PasswordFormatter : IKeyValueFormatter { #region Implementation of IKeyValueFormatter public Task FormatAsync(KeyValueFormatterContext context) { var password = context.Model?.ToString(); if (!string.IsNullOrEmpty(password)) password = Encoding.UTF8.GetString(Convert.FromBase64String(password)); context.Result[context.BinderModelName] = password; return Task.CompletedTask; } #endregion Implementation of IKeyValueFormatter } public class PostUserModel : UserModel { } public class PutUserModel : UserModel { } ``` ## 1.2 调用 ```c# var services = new ServiceCollection() .AddOptions() .AddLogging() .AddGoClient() .BuildServiceProvider(); var userGoClient = services.GetService(); var user = await userGoClient.GetAsync(1); await userGoClient.PutAsync(1, new PutUserModel { Age = 20 }); ``` # 食谱 * [DingTalk(钉钉sdk)](https://github.com/RabbitTeam/go/tree/master/recipes/DingTalk) # 特性 * 丰富的拦截器 * 全局请求拦截器和模型公约拦截器 * 良好的抽象与实现拆分,扩展非常容易 * 支持url模板 * 可扩展的请求程序(默认 HttpGoClient) * 不只为Http而设计(针对Grpc、dubbo等其它服务提供者进行了扩展考虑) # 文档 待补充 # 下一步 1. 在不使用DI的情况下使用 2. 提供服务发现、重试、限流、断路器的支持(集成 Rabbit Cloud) 3. 提供对Grpc的调用支持 4. 提供对dubbo的调用支持 # 联系方式 * QQ群:384413261 点击加入 [.NET Group](http://shang.qq.com/wpa/qunwpa?idkey=623e0bb6e02e7716ee6340cf7330be611e64d8ce7869862d9d9981f3d702bc8c) * Email:majian159@live.com