Skip to content

Latest commit

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Rabbit Go

一个设计为通用的强类型客户端。
目前只提供了Http的支持
NuGet:https://www.nuget.org/packages/Rabbit.Go.Core

1. 一个简单的示例

1.1 声明

[Go("http://api.com/user")][DefaultHeader("access_token","xxxxxxxxxx")][DefaultQuery("project","samples")]publicinterfaceIUserGoClient{[GoGet("/{id}")]Task<UserModel>GetAsync(longid);[GoDelete("/{id}")]TaskDeleteAsync(longid);[GoPost]Task<long>PostAsync([GoBody]PostUserModelmodel);[GoPut("/{id}")]TaskPutAsync(longid,[GoBody]PutUserModelmodel);}publicclassUserModel{[KeyName("user_name")]publicstringUserName{get;set;}[CustomFormatter(typeof(PasswordFormatter))]publicstringPassword{get;set;}publicint?Age{get;set;}[PropertyIgnore]publicboolIsAdult{get;set;}}publicclassPasswordFormatter:IKeyValueFormatter{
#region Implementation of IKeyValueFormatter
publicTaskFormatAsync(KeyValueFormatterContextcontext){varpassword=context.Model?.ToString();if(!string.IsNullOrEmpty(password))password=Encoding.UTF8.GetString(Convert.FromBase64String(password));context.Result[context.BinderModelName]=password;returnTask.CompletedTask;}
#endregion Implementation of IKeyValueFormatter
}publicclassPostUserModel:UserModel{}publicclassPutUserModel:UserModel{}

1.2 调用

varservices=newServiceCollection().AddOptions().AddLogging().AddGoClient().BuildServiceProvider();varuserGoClient=services.GetService<IUserGoClient>();varuser=awaituserGoClient.GetAsync(1);awaituserGoClient.PutAsync(1,newPutUserModel{Age=20});

食谱

特性

  • 丰富的拦截器
  • 全局请求拦截器和模型公约拦截器
  • 良好的抽象与实现拆分,扩展非常容易
  • 支持url模板
  • 可扩展的请求程序(默认 HttpGoClient)
  • 不只为Http而设计(针对Grpc、dubbo等其它服务提供者进行了扩展考虑)

文档

待补充

下一步

  1. 在不使用DI的情况下使用
  2. 提供服务发现、重试、限流、断路器的支持(集成 Rabbit Cloud)
  3. 提供对Grpc的调用支持
  4. 提供对dubbo的调用支持

联系方式

About

A generic, strongly typed client.

Resources

Stars

31 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages