定义服务以及uri的数据结构
This commit is contained in:
		
							
								
								
									
										68
									
								
								define.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								define.go
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,68 @@ | ||||
| // Package rpc ... | ||||
| // | ||||
| // Description : rpc ... | ||||
| // | ||||
| // Author : go_developer@163.com<白茶清欢> | ||||
| // | ||||
| // Date : 2022-06-29 14:08 | ||||
| package rpc | ||||
|  | ||||
| // Service 服务配置结构的定义 | ||||
| // | ||||
| // Author : go_developer@163.com<白茶清欢> | ||||
| // | ||||
| // Date : 14:08 2022/6/29 | ||||
| type Service struct { | ||||
| 	Flag            string                 `json:"flag" yaml:"flag"`                           // 服务标识, 全局唯一 | ||||
| 	Domain          string                 `json:"domain" yaml:"domain"`                       // 域名服务 | ||||
| 	CodeField       string                 `json:"code_field" yaml:"code_field"`               // 状态码字段 | ||||
| 	MessageField    string                 `json:"message_field" yaml:"message_field"`         // 消息字段 | ||||
| 	DataField       string                 `json:"data_field" yaml:"data_field"`               // 数据字段 | ||||
| 	SuccessCodeList []string               `json:"success_code_list" yaml:"success_code_list"` // 成功的值 | ||||
| 	ApiTable        map[string]interface{} `json:"api_table" yaml:"api_table"`                 // api列表 | ||||
| 	ApiRetry        ApiRetry               `json:"api_retry" yaml:"api_retry"`                 // 重试策略 | ||||
| } | ||||
|  | ||||
| // Api 接口的数据结构 | ||||
| // | ||||
| // Author : go_developer@163.com<白茶清欢> | ||||
| // | ||||
| // Date : 14:18 2022/6/29 | ||||
| type Api struct { | ||||
| 	URI                 string            `json:"uri" yaml:"uri"`                                       // 接口地址 | ||||
| 	Method              string            `json:"method" yaml:"method"`                                 // 请求方法 GET / POST / PUT 等 | ||||
| 	CodeField           string            `json:"code_field" yaml:"code_field"`                         // 状态码字段 | ||||
| 	MessageField        string            `json:"message_field" yaml:"message_field"`                   // 消息字段 | ||||
| 	DataField           string            `json:"data_field" yaml:"data_field"`                         // 数据字段(优先级高, 会覆盖) | ||||
| 	SuccessCodeList     []string          `json:"success_code_list" yaml:"success_code_list"`           // 成功的值(优先级高, 会覆盖) | ||||
| 	SuccessHttpCodeList []int             `json:"success_http_code_list" yaml:"success_http_code_list"` // 任务成功的http状态码, 不配置默认只有200(优先级高, 会覆盖) | ||||
| 	Header              map[string]string `json:"header" yaml:"header"`                                 // 传入的header | ||||
| 	Cookie              map[string]string `json:"cookie" yaml:"cookie"`                                 // 传入的cookie | ||||
| 	BindURIParamList    []string          `json:"bind_uri_param_list" yaml:"bind_uri_param_list"`       // 绑定到URI的参数列表 | ||||
| 	Timeout             ApiTimeout        `json:"timeout" yaml:"timeout"` | ||||
| 	Retry               ApiRetry          `json:"retry" yaml:"retry"` // 重试策略 | ||||
| } | ||||
|  | ||||
| // ApiTimeout 超时配置 | ||||
| // | ||||
| // Author : go_developer@163.com<白茶清欢> | ||||
| // | ||||
| // Date : 15:08 2022/6/29 | ||||
| type ApiTimeout struct { | ||||
| 	Read    int `json:"read" yaml:"read"`       // 读取超时时间 | ||||
| 	Connect int `json:"connect" yaml:"connect"` // 连接超时时间 | ||||
| } | ||||
|  | ||||
| // ApiRetry 接口重试 | ||||
| // | ||||
| // Author : go_developer@163.com<白茶清欢> | ||||
| // | ||||
| // Date : 15:10 2022/6/29 | ||||
| type ApiRetry struct { | ||||
| 	ConnectTimeout   bool `json:"connect_timeout" yaml:"connect_timeout"`       // 连接超时是否重试 | ||||
| 	ReadTimeout      bool `json:"read_timeout" yaml:"read_timeout"`             // 读取超时是否重试 | ||||
| 	BusinessCodeFail bool `json:"business_code_fail" yaml:"business_code_fail"` // 业务状态码错误是否重试 | ||||
| 	HttpCodeFail     bool `json:"http_code_fail"`                               // http状态码异常是否重试 | ||||
| 	Count            int  `json:"count" yaml:"count"`                           // 重试次数 | ||||
| 	Frequency        int  `json:"frequency" yaml:"frequency"`                   // 重试频率, 单位 : ms | ||||
| } | ||||
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @ -1,3 +1,5 @@ | ||||
| module git.zhangdeman.cn/zhangdeman/rpc | ||||
|  | ||||
| go 1.17 | ||||
|  | ||||
| require github.com/ddliu/go-httpclient v0.6.9 // indirect | ||||
|  | ||||
		Reference in New Issue
	
	Block a user