├── .editorconfig ├── .github └── workflows │ └── go.yml ├── .gitignore ├── LICENSE ├── README.md ├── collector ├── company │ ├── company_collector.go │ ├── hk_company_collector.go │ ├── hk_company_collector_test.go │ ├── sh_company_collector.go │ ├── sh_company_collector_test.go │ ├── sz_company_collector.go │ └── sz_company_collector_test.go ├── company_info_collector.go ├── data │ ├── data_collector.go │ ├── hk_data_collector.go │ ├── hk_data_collector_test.go │ ├── sh_data_collector.go │ ├── sh_data_collector_test.go │ ├── sz_data_collector.go │ └── sz_data_collector_test.go ├── data_collector.go └── token │ ├── common.go │ ├── hk_token.go │ └── hk_token_test.go ├── config ├── config.go └── config_test.go ├── enums ├── enums.go ├── plate_enums.go └── stock_exchange_enum.go ├── go.mod ├── go.sum ├── model ├── company.go ├── config_define.go └── data.go ├── persistent ├── company-2021-01-31.json ├── company_file_persistent.go ├── company_file_persistent_test.go ├── constant.go ├── data_file_persistent.go ├── file.go └── persistent.go ├── project_config.yml ├── s-logger ├── logger.go └── logger_test.go ├── stock_data.go └── tool ├── date.go ├── date_test.go ├── file.go ├── json.go └── json_test.go /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 4 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | 15 | [*.json] 16 | indent_style = space 17 | indent_size = 2 18 | 19 | [*.yml] 20 | indent_style = space 21 | indent_size = 2 22 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.16 20 | 21 | - name: Test 22 | run: go test -failfast ./... 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | 3 | *.log 4 | 5 | nohup.out 6 | 7 | stock 8 | stock.exe 9 | 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 项目说明 2 | 3 | 收集上市公司股票价格数据,项目只支持收集国内交易所的当天的股票价格数据。 4 | 5 | 用于闭市之后收集当天的股票价格数据。 6 | 7 | **配置 project_config.yml:** 8 | 9 | * `datasavepath`:数据文件保存路径,需要配置。 10 | 11 | **数据文件命名:** 12 | 13 | * 公司数据: `company-年-月-日.json` 14 | 15 | ```json 16 | [ 17 | { 18 | "stock_exchange": 100, 19 | "code": "000001", 20 | "plate": "100", 21 | "short_name": "平安银行", 22 | "full_name": "平安银行股份有限公司", 23 | "industry_code": "J", 24 | "industry_name": "金融业" 25 | }, 26 | ... 27 | ] 28 | ``` 29 | 30 | * 股票数据: `data-年-月-日.json` 31 | 32 | ```json 33 | [ 34 | { 35 | "stock_exchange": 100, 36 | "code": "000001", 37 | "plate": "100", 38 | "data": [ 39 | { 40 | "date": "2020-06-11 09:30", 41 | "price": "13.38" 42 | }, 43 | ... 44 | ] 45 | }, 46 | { 47 | "stock_exchange": 100, 48 | "code": "000002", 49 | "plate": "100", 50 | "data": [ 51 | { 52 | "date": "2020-06-11 09:30", 53 | "price": "13.38" 54 | }, 55 | ... 56 | ] 57 | } 58 | ... 59 | ] 60 | ``` 61 | 62 | ### 运行项目 63 | 64 | 需要先修改 `project_config.yml` 中的 `datasavepath` 为实际路径。 65 | 66 | ``` 67 | Windows: datasavepath: 'd:/data/' 68 | Linux: datasavepath: '/home/xiaotian/data' 69 | ``` 70 | 71 | 1. 直接运行 72 | 73 | ``` 74 | git clone https://github.com/sunfeilong/stock-data.git 75 | cd stock-data 76 | go run stock_data.go 77 | ``` 78 | 79 | 2. 打包之后运行 80 | 81 | ``` 82 | git clone https://github.com/sunfeilong/stock-data.git 83 | cd stock-data 84 | go build 85 | ./stock 86 | ``` 87 | 88 | ### 注意事项 89 | 90 | 为了不影响数据源网站正常运行,使用时请不要删除限速的代码。 91 | 92 | ## 功能列表 93 | 94 | ### 已完成 95 | 96 | * [深圳证券交易所](http://www.szse.cn/)数据收集。 97 | * [上海证券交易所](http://www.sse.com.cn/)数据收集。 98 | * [香港交易所](https://sc.hkex.com.hk/TuniS/www.hkex.com.hk/?sc_lang=zh-cn)数据收集。 99 | 100 | ### 正在做 101 | 102 | * 无 103 | 104 | ### 下一步 105 | 106 | * 无 107 | 108 | ### 已废弃的功能 109 | 110 | * 每天16:30定时执行数据收集任务。收集完成之后自动推送数据到该仓库。 111 | 112 | 废弃原因:随着收集次数的变多,收集的数据文件慢慢变大,代码仓库开始变的很大,拉取代码开始变得很慢,而且总有一天本地磁盘会不够用,所以废弃了该功能。 113 | 114 | -------------------------------------------------------------------------------- /collector/company/company_collector.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "github.com/xiaotian/stock/model" 5 | ) 6 | 7 | type Collector interface { 8 | //获取收集器对应的交易所 9 | GetStockExchange() int 10 | //获取所有公司信息 11 | FetchAll(config model.StockConfig) []model.Company 12 | } 13 | -------------------------------------------------------------------------------- /collector/company/hk_company_collector.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/xiaotian/stock/collector/token" 6 | "github.com/xiaotian/stock/enums" 7 | "github.com/xiaotian/stock/model" 8 | "io/ioutil" 9 | "math/rand" 10 | "net/http" 11 | "strconv" 12 | "strings" 13 | "time" 14 | ) 15 | 16 | //香港交易所上市公司信息收集器 17 | type HKCompanyCollector struct { 18 | } 19 | 20 | type HKResponse struct { 21 | Data HKStockList `json:"data"` 22 | Error string `json:"qid"` 23 | } 24 | 25 | type HKStockList struct { 26 | LastUpDate string `json:"lastupd"` 27 | ResponseCode string `json:"responsecode"` 28 | ResponseMsg string `json:"responsemsg"` 29 | StockList []HKResponseData `json:"stocklist"` 30 | } 31 | 32 | type HKResponseData struct { 33 | Suspend bool `json:"suspend"` 34 | CompanyFullName string `json:"nm"` 35 | StockCode string `json:"sym"` 36 | } 37 | 38 | func (s HKCompanyCollector) String() string { 39 | return "HKCompanyCollector" 40 | } 41 | 42 | func (s HKCompanyCollector) GetStockExchange() int { 43 | return enums.HK 44 | } 45 | 46 | func (s HKCompanyCollector) FetchAll(conf model.StockConfig) []model.Company { 47 | logger.Infow("收集港交所所有公司信息,开始.", "stockExchangeCode", s.GetStockExchange(), "configInfo", conf) 48 | result := make([]model.Company, 0) 49 | allPlate := enums.GetByStockExchange(conf) 50 | hkToken := token.GetHKToken(conf.TokenUrl) 51 | for _, plate := range allPlate { 52 | result = append(result, HKGetPlateData(conf, plate, hkToken)...) 53 | } 54 | logger.Infow("收集港交所所有公司信息,结束.", "stockExchangeCode", s.GetStockExchange(), "configInfo", conf, "length", len(result)) 55 | return result 56 | } 57 | 58 | //获取每个板块的数据 59 | func HKGetPlateData(conf model.StockConfig, plate enums.PlateEnum, hkToken string) []model.Company { 60 | logger.Infow("收集所有公司信息,收集指定板块信息,开始.", "stockExchangeCode", conf.StockExchangeCode, "plate", plate) 61 | data := HKReadPageData(conf, plate, hkToken) 62 | logger.Infow("收集所有公司信息,收集指定板块信息,结束.", "stockExchangeCode", conf.StockExchangeCode, "plate", plate) 63 | return data 64 | } 65 | 66 | //读取每页的数据 67 | func HKReadPageData(conf model.StockConfig, plate enums.PlateEnum, hkToken string) []model.Company { 68 | time.Sleep(time.Millisecond * 500) 69 | requestUrl := conf.CompanyInfoUrl + "&market=" + plate.Tab + "&qid=" + strconv.Itoa(rand.Int()) + "&_=" + strconv.Itoa(rand.Int()) 70 | requestUrl = strings.ReplaceAll(requestUrl, "{token}", hkToken) 71 | logger.Infow("获取港交所公司列表.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl) 72 | response, err := http.Get(requestUrl) 73 | if nil != err { 74 | logger.Errorw("获取港交所公司列表数据异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 75 | return nil 76 | } 77 | responseDataByte, err := ioutil.ReadAll(response.Body) 78 | if nil != err { 79 | logger.Errorw("读取港交所公司列表数据异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 80 | return nil 81 | } 82 | responseDataPoint := HKResponse{} 83 | tempStr := string(responseDataByte) 84 | tempStr = tempStr[strings.Index(tempStr, "(")+1 : strings.LastIndex(tempStr, ")")] 85 | logger.Infow("读取港交所公司列表,解析数据", "str:", tempStr) 86 | err = json.Unmarshal([]byte(tempStr), &responseDataPoint) 87 | if err != nil { 88 | logger.Errorw("读取港交所公司列表,解析数据出现异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 89 | return nil 90 | } 91 | return HKResponseToCompanyMapper(responseDataPoint, plate) 92 | } 93 | 94 | func HKResponseToCompanyMapper(response HKResponse, plate enums.PlateEnum) []model.Company { 95 | result := make([]model.Company, 0) 96 | if response.Data.ResponseCode != "000" { 97 | return result 98 | } 99 | for _, d := range response.Data.StockList { 100 | if d.Suspend { 101 | logger.Infow("港交所公司列表数据转换,公司已停牌", "股票代码: ", d.StockCode, " 公司名字: ", d.CompanyFullName) 102 | continue 103 | } 104 | company := model.Company{ 105 | StockExchange: plate.StockExchange, 106 | Code: d.StockCode, 107 | Plate: plate.Code, 108 | ShortName: "-", 109 | FullName: d.CompanyFullName, 110 | IndustryCode: "-", 111 | IndustryName: "-", 112 | } 113 | result = append(result, company) 114 | } 115 | logger.Infow("港交所公司列表数据转换", "length", len(response.Data.StockList), "resultLength", len(result)) 116 | return result 117 | } 118 | -------------------------------------------------------------------------------- /collector/company/hk_company_collector_test.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "github.com/xiaotian/stock/config" 6 | "github.com/xiaotian/stock/enums" 7 | "testing" 8 | ) 9 | 10 | func TestHKCompanyDataFetch(t *testing.T) { 11 | shCollector := HKCompanyCollector{} 12 | 13 | getConfig := config.GetStockConfig(enums.HK) 14 | 15 | companies := shCollector.FetchAll(getConfig) 16 | 17 | assert.NotEmpty(t, companies, "") 18 | } 19 | -------------------------------------------------------------------------------- /collector/company/sh_company_collector.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/xiaotian/stock/enums" 6 | "github.com/xiaotian/stock/model" 7 | "io/ioutil" 8 | "math/rand" 9 | "net/http" 10 | "strconv" 11 | "time" 12 | ) 13 | 14 | //上海交易所上市公司信息收集器 15 | type SHCompanyCollector struct { 16 | } 17 | 18 | const ( 19 | COOKIE string = "yfx_c_g_u_id_10000042=_ck18012900250116338392357618947; VISITED_MENU=%5B%228528%22%5D; yfx_f_l_v_t_10000042=f_t_1517156701630__r_t_1517314287296__v_t_1517320502571__r_c_2" 20 | USERAGENT string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36" 21 | Referer string = "http://www.sse.com.cn/assortment/stock/list/share/" 22 | ) 23 | 24 | type SHResponse struct { 25 | Data []SHResponseData `json:"result"` 26 | Error string `json:"csrcCode"` 27 | } 28 | 29 | type SHResponseData struct { 30 | CompanySimpleName string `json:"COMPANY_ABBR"` 31 | StockCode string `json:"COMPANY_CODE"` 32 | ListingDate string `json:"LISTING_DATE"` 33 | } 34 | 35 | func (s SHCompanyCollector) String() string { 36 | return "SHCompanyCollector" 37 | } 38 | 39 | func (s SHCompanyCollector) GetStockExchange() int { 40 | return enums.SH 41 | } 42 | 43 | func (s SHCompanyCollector) FetchAll(conf model.StockConfig) []model.Company { 44 | logger.Infow("收集上交所公司信息,开始.", "stockExchangeCode", s.GetStockExchange(), "configInfo", conf) 45 | result := make([]model.Company, 0) 46 | plates := enums.GetByStockExchange(conf) 47 | for _, plate := range plates { 48 | result = append(result, SHGetPlateData(conf, plate)...) 49 | } 50 | logger.Infow("收集上交所公司信息,结束.", "stockExchangeCode", s.GetStockExchange(), "configInfo", conf, "length", len(result)) 51 | return result 52 | } 53 | 54 | //获取每个板块的数据 55 | func SHGetPlateData(conf model.StockConfig, plate enums.PlateEnum) []model.Company { 56 | logger.Infow("收集上交所公司信息,收集指定板块信息,开始.", "stockExchangeCode", conf.StockExchangeCode, "plate", plate) 57 | result := make([]model.Company, 0) 58 | page := 1 59 | for pageData := SHReadPageData(conf, page, plate); pageData != nil; { 60 | result = append(result, pageData...) 61 | page = page + 1 62 | pageData = SHReadPageData(conf, page, plate) 63 | } 64 | logger.Infow("收集上交所公司信息,收集指定板块信息,结束.", "stockExchangeCode", conf.StockExchangeCode, "plate", plate) 65 | return result 66 | } 67 | 68 | //读取每页的数据 69 | func SHReadPageData(conf model.StockConfig, page int, plate enums.PlateEnum) []model.Company { 70 | time.Sleep(time.Millisecond * 500) 71 | client := &http.Client{} 72 | pageStr := strconv.Itoa(page) 73 | requestUrl := conf.CompanyInfoUrl + "&pageHelp.beginPage=" + pageStr + "&pageHelp.pageNo=" + pageStr + "&stockType=" + plate.Tab + "&_=" + strconv.Itoa(rand.Int()) 74 | logger.Infow("获取上交所公司列表.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl) 75 | request, err := http.NewRequest("GET", requestUrl, nil) 76 | if err != nil { 77 | logger.Errorw("获取上交所公司列表构造请求参数异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 78 | return nil 79 | } 80 | request.Header.Add("Cookie", COOKIE) 81 | request.Header.Add("User-Agent", USERAGENT) 82 | request.Header.Add("Referer", Referer) 83 | response, err := client.Do(request) 84 | if nil != err { 85 | logger.Errorw("获取上交所公司列表数据异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 86 | return nil 87 | } 88 | responseDataByte, err := ioutil.ReadAll(response.Body) 89 | if nil != err { 90 | logger.Errorw("读取上交所公司列表数据异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 91 | return nil 92 | } 93 | responseDataPoint := &SHResponse{} 94 | err = json.Unmarshal(responseDataByte, &responseDataPoint) 95 | if err != nil { 96 | logger.Errorw("读取上交所公司列表,解析数据出现异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 97 | return nil 98 | } 99 | if nil == responseDataPoint || len(responseDataPoint.Data) == 0 { 100 | return nil 101 | } 102 | return SHResponseToCompanyMapper(*responseDataPoint, plate) 103 | } 104 | 105 | func SHResponseToCompanyMapper(response SHResponse, plate enums.PlateEnum) []model.Company { 106 | result := make([]model.Company, 0) 107 | for _, d := range response.Data { 108 | company := model.Company{ 109 | StockExchange: plate.StockExchange, 110 | Code: d.StockCode, 111 | Plate: plate.Code, 112 | ShortName: d.CompanySimpleName, 113 | FullName: "-", 114 | IndustryCode: "-", 115 | IndustryName: "-", 116 | ListingDate: d.ListingDate, 117 | } 118 | result = append(result, company) 119 | } 120 | logger.Infow("数据转换", "length", len(response.Data), "resultLength", len(result)) 121 | return result 122 | } 123 | -------------------------------------------------------------------------------- /collector/company/sh_company_collector_test.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "github.com/xiaotian/stock/config" 6 | "github.com/xiaotian/stock/enums" 7 | "log" 8 | "testing" 9 | ) 10 | 11 | func TestSHCompanyDataFetch(t *testing.T) { 12 | shCollector := SHCompanyCollector{} 13 | 14 | getConfig := config.GetStockConfig(enums.SH) 15 | 16 | companies := shCollector.FetchAll(getConfig) 17 | log.Println("数据: ", companies) 18 | log.Println("数据长度: ", len(companies)) 19 | assert.NotEmpty(t, companies, "") 20 | } 21 | -------------------------------------------------------------------------------- /collector/company/sz_company_collector.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/xiaotian/stock/enums" 6 | "github.com/xiaotian/stock/model" 7 | "github.com/xiaotian/stock/s-logger" 8 | "io/ioutil" 9 | "math/rand" 10 | "net/http" 11 | "regexp" 12 | "strconv" 13 | "strings" 14 | "time" 15 | ) 16 | 17 | var simpleNameReg = regexp.MustCompile("(.*)(.*)(.*)") 18 | var logger = s_logger.New() 19 | 20 | //深圳交易所上市公司信息收集器 21 | type SZCompanyCollector struct { 22 | } 23 | 24 | type Response struct { 25 | Data []ResponseData `json:"data"` 26 | Error string `json:"error"` 27 | } 28 | 29 | type ResponseData struct { 30 | CompanySimpleName string `json:"gsjc"` 31 | CompanyFullName string `json:"gsqc"` 32 | CompanyWebSite string `json:"http"` 33 | IndustryCodeAndName string `json:"sshymc"` 34 | StockCode string `json:"zqdm"` 35 | } 36 | 37 | func (s SZCompanyCollector) String() string { 38 | return "SZCompanyCollector" 39 | } 40 | 41 | func (s SZCompanyCollector) GetStockExchange() int { 42 | return enums.SZ 43 | } 44 | 45 | func (s SZCompanyCollector) FetchAll(conf model.StockConfig) []model.Company { 46 | logger.Infow("收集深交所所有公司信息,开始.", "stockExchangeCode", s.GetStockExchange(), "configInfo", conf) 47 | result := make([]model.Company, 0) 48 | allPlate := enums.GetByStockExchange(conf) 49 | for _, plate := range allPlate { 50 | result = append(result, GetPlateData(conf, plate)...) 51 | } 52 | logger.Infow("收集深交所所有公司信息,结束.", "stockExchangeCode", s.GetStockExchange(), "configInfo", conf, "length", len(result)) 53 | return result 54 | } 55 | 56 | //获取每个板块的数据 57 | func GetPlateData(conf model.StockConfig, plate enums.PlateEnum) []model.Company { 58 | logger.Infow("收集所有公司信息,收集指定板块信息,开始.", "stockExchangeCode", conf.StockExchangeCode, "plate", plate) 59 | result := make([]model.Company, 0) 60 | page := 1 61 | for pageData := readPageData(conf, page, plate); pageData != nil; { 62 | result = append(result, pageData...) 63 | page = page + 1 64 | pageData = readPageData(conf, page, plate) 65 | } 66 | logger.Infow("收集所有公司信息,收集指定板块信息,结束.", "stockExchangeCode", conf.StockExchangeCode, "plate", plate) 67 | return result 68 | } 69 | 70 | //读取每页的数据 71 | func readPageData(conf model.StockConfig, page int, plate enums.PlateEnum) []model.Company { 72 | time.Sleep(time.Millisecond * 500) 73 | requestUrl := conf.CompanyInfoUrl + "&TABKEY=" + plate.Tab + "&random=" + strconv.Itoa(rand.Int()) + "&PAGENO=" + strconv.Itoa(page) 74 | logger.Infow("获取深交所公司列表.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl) 75 | response, err := http.Get(requestUrl) 76 | if nil != err { 77 | logger.Errorw("获取深交所公司列表数据异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 78 | return nil 79 | } 80 | responseDataByte, err := ioutil.ReadAll(response.Body) 81 | if nil != err { 82 | logger.Errorw("读取深交所公司列表数据异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 83 | return nil 84 | } 85 | responseDataPoint := &[]Response{} 86 | err = json.Unmarshal(responseDataByte, &responseDataPoint) 87 | if err != nil { 88 | logger.Errorw("读取深交所公司列表,解析数据出现异常.", "stockExchange", plate.StockExchange, "plate", plate.Tab, "url", requestUrl, "err", err) 89 | return nil 90 | } 91 | 92 | if r := (*responseDataPoint)[plate.Index-1]; len(r.Data) > 0 { 93 | return responseToCompanyMapper(r, plate) 94 | } 95 | return nil 96 | } 97 | 98 | func responseToCompanyMapper(response Response, plate enums.PlateEnum) []model.Company { 99 | result := make([]model.Company, 0) 100 | for _, d := range response.Data { 101 | split := strings.Split(d.IndustryCodeAndName, " ") 102 | company := model.Company{ 103 | StockExchange: plate.StockExchange, 104 | Code: d.StockCode, 105 | Plate: plate.Code, 106 | ShortName: getSimpleName(d.CompanySimpleName), 107 | FullName: d.CompanyFullName, 108 | IndustryCode: split[0], 109 | IndustryName: split[1], 110 | } 111 | result = append(result, company) 112 | } 113 | logger.Infow("深交所公司列表数据转换", "length", len(response.Data), "resultLength", len(result)) 114 | return result 115 | } 116 | 117 | func getSimpleName(htmlStr string) string { 118 | return string(simpleNameReg.FindAllSubmatch([]byte(htmlStr), 1)[0][2]) 119 | } 120 | -------------------------------------------------------------------------------- /collector/company/sz_company_collector_test.go: -------------------------------------------------------------------------------- 1 | package company 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "github.com/xiaotian/stock/config" 6 | "github.com/xiaotian/stock/enums" 7 | "log" 8 | "testing" 9 | ) 10 | 11 | func TestName(t *testing.T) { 12 | szCollector := SZCompanyCollector{} 13 | 14 | getConfig := config.GetStockConfig(enums.SZ) 15 | 16 | companies := szCollector.FetchAll(getConfig) 17 | log.Println("数据: ", companies) 18 | log.Println("数据长度: ", len(companies)) 19 | assert.NotEmpty(t, companies, "") 20 | } 21 | -------------------------------------------------------------------------------- /collector/company_info_collector.go: -------------------------------------------------------------------------------- 1 | package collector 2 | 3 | import ( 4 | "github.com/xiaotian/stock/collector/company" 5 | "github.com/xiaotian/stock/config" 6 | "github.com/xiaotian/stock/model" 7 | "github.com/xiaotian/stock/s-logger" 8 | ) 9 | 10 | var logger = s_logger.New() 11 | var collectors map[int]company.Collector = make(map[int]company.Collector) 12 | 13 | func init() { 14 | logger.Infow("初始化收集器容器") 15 | addToMap(company.SZCompanyCollector{}) 16 | addToMap(company.SHCompanyCollector{}) 17 | addToMap(company.HKCompanyCollector{}) 18 | } 19 | 20 | func addToMap(collector company.Collector) { 21 | collectors[collector.GetStockExchange()] = collector 22 | } 23 | 24 | func CollectCompanyInfo() []model.Company { 25 | logger.Infow("收集公司信息开始") 26 | tempData := make([]model.Company, 0) 27 | for key, collector := range collectors { 28 | logger.Infow("收集公司信息.", "stockCode", key, "collector", collector) 29 | all := collector.FetchAll(config.GetStockConfig(collector.GetStockExchange())) 30 | tempData = append(tempData, all...) 31 | } 32 | logger.Infow("收集公司信息结束") 33 | return tempData 34 | } 35 | -------------------------------------------------------------------------------- /collector/data/data_collector.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import "github.com/xiaotian/stock/model" 4 | 5 | type Collector interface { 6 | GetStockExchange() int 7 | FetchAll(company []model.Company, conf model.StockConfig) []model.Data 8 | } 9 | -------------------------------------------------------------------------------- /collector/data/hk_data_collector.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "github.com/xiaotian/stock/collector/token" 8 | "github.com/xiaotian/stock/enums" 9 | "github.com/xiaotian/stock/model" 10 | "io/ioutil" 11 | "math/rand" 12 | "net/http" 13 | "strconv" 14 | "strings" 15 | "time" 16 | ) 17 | 18 | type HKDataCollector struct { 19 | } 20 | 21 | type HKResponse struct { 22 | Data HKResponseData `json:"data"` 23 | } 24 | 25 | type HKResponseData struct { 26 | ResponseCode string `json:"responsecode"` 27 | ResponseMsg string `json:"responsemsg"` 28 | DataList [][]interface{} `json:"datalist"` 29 | } 30 | 31 | func (s HKDataCollector) GetStockExchange() int { 32 | return enums.HK 33 | } 34 | 35 | func (s HKDataCollector) FetchAll(company []model.Company, conf model.StockConfig) []model.Data { 36 | logger.Infow("获取港交所上市公司股票价格数据,", "company count", len(company), "conf", conf) 37 | result := make([]model.Data, 0) 38 | hkToken := token.GetHKToken(conf.TokenUrl) 39 | for _, c := range company { 40 | if s.GetStockExchange() != c.StockExchange { 41 | logger.Infow("获取港交所上市公司股票价格数据,收集器不能处理对应公司数据,跳过", 42 | "company", c, "conf", conf, 43 | "collectorStockExchange", c.StockExchange, "companyStockExchange", c.StockExchange) 44 | continue 45 | } 46 | logger.Infow("获取港交所上市公司股票价格数据", "company", c, "conf", conf) 47 | data, err := HKGetData(c, conf, hkToken) 48 | if err != nil { 49 | logger.Errorw("获取港交所上市公司股票价格数据,获取数据异常", "company", c, "conf", conf, "err", err) 50 | continue 51 | } 52 | result = append(result, data) 53 | } 54 | return result 55 | } 56 | 57 | func HKGetData(company model.Company, config model.StockConfig, hkToken string) (model.Data, error) { 58 | time.Sleep(time.Millisecond * 500) 59 | data := &model.Data{} 60 | data.StockExchange = company.StockExchange 61 | data.Code = company.Code 62 | data.Plate = company.Plate 63 | url := strings.Replace(config.RealTimeInfoUrl, "{code}", fmt.Sprintf("%04s", company.Code), -1) 64 | url = strings.Replace(url, "{token}", hkToken, -1) 65 | url = url + "&qid=" + strconv.Itoa(rand.Int()) + "&_=" + strconv.Itoa(rand.Int()) 66 | logger.Infow("获取港交所上市公司股票数据,开始", "code", company.Code, "company", company.ShortName, "url", url) 67 | client := &http.Client{} 68 | request, err := http.NewRequest("GET", url, nil) 69 | if err != nil { 70 | logger.Errorw("获取港交所上市公司股票数据,构造请求出现异常", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 71 | return *data, errors.New("构造请求出现异常") 72 | } 73 | request.Header.Add("Cookie", COOKIE) 74 | request.Header.Add("User-Agent", USERAGENT) 75 | request.Header.Add("Referer", Referer) 76 | response, err := client.Do(request) 77 | if err != nil { 78 | logger.Errorw("获取港交所上市公司股票数据,请求数据出现异常", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 79 | return *data, errors.New("请求数据出现异常") 80 | } 81 | responseData, err := ioutil.ReadAll(response.Body) 82 | if err != nil { 83 | logger.Errorw("获取港交所上市公司股票数据,读取响应数据出错", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 84 | return *data, errors.New("读取响应数据出错") 85 | } 86 | tempStr := string(responseData) 87 | tempStr = tempStr[strings.Index(tempStr, "(")+1 : strings.LastIndex(tempStr, ")")] 88 | responseDataPointer := &HKResponse{} 89 | if err = json.Unmarshal([]byte(tempStr), responseDataPointer); err != nil { 90 | logger.Errorw("获取港交所上市公司股票数据,解析数据出错", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 91 | return *data, errors.New("解析数据出错") 92 | } 93 | HKCopyData(data, responseDataPointer) 94 | logger.Infow("获取港交所上市公司股票数据,结束", "code", company.Code, "company", company.ShortName, "url", url) 95 | return *data, nil 96 | } 97 | 98 | func HKCopyData(data *model.Data, response *HKResponse) { 99 | for _, p := range response.Data.DataList { 100 | if p[1] == nil { 101 | continue 102 | } 103 | unixTime := time.Unix(int64(p[0].(float64))/1000, 0).Format("2006-01-02 15:04") 104 | if p[4] == nil { 105 | return 106 | } 107 | data.AddInnerData(unixTime, fmt.Sprintf("%.2f", p[4])) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /collector/data/hk_data_collector_test.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/stretchr/testify/assert" 6 | "github.com/xiaotian/stock/config" 7 | "github.com/xiaotian/stock/enums" 8 | "github.com/xiaotian/stock/model" 9 | "testing" 10 | ) 11 | 12 | func TestHKFetchOne(t *testing.T) { 13 | 14 | conf := config.GetStockConfig(enums.HK) 15 | company := &[]model.Company{} 16 | 17 | var companyJson = "[{\"stock_exchange\": 160,\"code\": \"700\",\"plate\": \"2000\",\"short_name\": \"腾讯\",\"full_name\": \"-\",\"industry_code\": \"-\",\"industry_name\": \"-\"}]" 18 | err := json.Unmarshal([]byte(companyJson), company) 19 | assert.Nil(t, err, err) 20 | 21 | collector := HKDataCollector{} 22 | Data := collector.FetchAll(*company, conf) 23 | 24 | logger.Infow("Data", Data) 25 | assert.Equal(t, 1, len(Data)) 26 | } 27 | -------------------------------------------------------------------------------- /collector/data/sh_data_collector.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "github.com/xiaotian/stock/enums" 8 | "github.com/xiaotian/stock/model" 9 | "github.com/xiaotian/stock/tool" 10 | "io/ioutil" 11 | "net/http" 12 | "strings" 13 | "time" 14 | ) 15 | 16 | const ( 17 | COOKIE string = "yfx_c_g_u_id_10000042=_ck18012900250116338392357618947; VISITED_MENU=%5B%228528%22%5D; yfx_f_l_v_t_10000042=f_t_1517156701630__r_t_1517314287296__v_t_1517320502571__r_c_2" 18 | USERAGENT string = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36" 19 | Referer string = "http://www.sse.com.cn/assortment/stock/list/share/" 20 | ) 21 | 22 | type SHDataCollector struct { 23 | } 24 | 25 | type SHResponse struct { 26 | Data [][]interface{} `json:"line"` 27 | } 28 | 29 | func (s SHDataCollector) GetStockExchange() int { 30 | return enums.SH 31 | } 32 | 33 | func (s SHDataCollector) FetchAll(company []model.Company, conf model.StockConfig) []model.Data { 34 | logger.Infow("获取上交所上市公司股票价格数据,", "company count", len(company), "conf", conf) 35 | result := make([]model.Data, 0) 36 | for _, c := range company { 37 | if s.GetStockExchange() != c.StockExchange { 38 | logger.Infow("获取上交所上市公司股票价格数据,收集器不能处理对应公司数据,跳过", 39 | "company", c, "conf", conf, 40 | "collectorStockExchange", c.StockExchange, "companyStockExchange", c.StockExchange) 41 | continue 42 | } 43 | logger.Infow("获取上交所上市公司股票价格数据", "company", c, "conf", conf) 44 | data, err := SHGetData(c, conf) 45 | if err != nil { 46 | logger.Errorw("获取上交所上市公司股票价格数据,获取数据异常", "company", c, "conf", conf, "err", err) 47 | continue 48 | } 49 | result = append(result, data) 50 | } 51 | return result 52 | } 53 | 54 | func SHGetData(company model.Company, config model.StockConfig) (model.Data, error) { 55 | time.Sleep(time.Millisecond * 100) 56 | data := &model.Data{} 57 | data.StockExchange = company.StockExchange 58 | data.Code = company.Code 59 | data.Plate = company.Plate 60 | 61 | url := strings.Replace(config.RealTimeInfoUrl, "{code}", company.Code, -1) 62 | logger.Infow("获取上交所上市公司股票数据,开始", "code", company.Code, "company", company.ShortName, "url", url) 63 | 64 | client := &http.Client{} 65 | request, err := http.NewRequest("GET", url, nil) 66 | if err != nil { 67 | logger.Errorw("获取上交所上市公司股票数据,构造请求出现异常", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 68 | return *data, errors.New("构造请求出现异常") 69 | } 70 | request.Header.Add("Cookie", COOKIE) 71 | request.Header.Add("User-Agent", USERAGENT) 72 | request.Header.Add("Referer", Referer) 73 | response, err := client.Do(request) 74 | if err != nil { 75 | logger.Errorw("获取上交所上市公司股票数据,请求数据出现异常", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 76 | return *data, errors.New("请求数据出现异常") 77 | } 78 | responseData, err := ioutil.ReadAll(response.Body) 79 | if err != nil { 80 | logger.Errorw("获取上交所上市公司股票数据,读取响应数据出错", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 81 | return *data, errors.New("读取响应数据出错") 82 | } 83 | responseDataPointer := &SHResponse{} 84 | if err = json.Unmarshal(responseData, responseDataPointer); err != nil { 85 | logger.Errorw("获取上交所上市公司股票数据,解析数据出错", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 86 | return *data, errors.New("解析数据出错") 87 | } 88 | SHCopyData(data, responseDataPointer) 89 | logger.Infow("获取上交所上市公司股票数据,结束", "code", company.Code, "company", company.ShortName, "url", url) 90 | return *data, nil 91 | } 92 | 93 | func SHCopyData(data *model.Data, response *SHResponse) { 94 | for _, p := range response.Data { 95 | t := fmt.Sprintf("%.0f", p[0]) 96 | if len(t) == 5 { 97 | t = "0" + t 98 | } 99 | data.AddInnerData(tool.NowDate()+" "+t[:2]+":"+t[2:4], fmt.Sprintf("%.0f", p[1])) 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /collector/data/sh_data_collector_test.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/stretchr/testify/assert" 6 | "github.com/xiaotian/stock/config" 7 | "github.com/xiaotian/stock/enums" 8 | "github.com/xiaotian/stock/model" 9 | "testing" 10 | ) 11 | 12 | func TestSHFetchOne(t *testing.T) { 13 | 14 | conf := config.GetStockConfig(enums.SH) 15 | company := &[]model.Company{} 16 | 17 | var companyJson = "[{\"stock_exchange\": 130,\"code\": \"600000\",\"plate\": \"1000\",\"short_name\": \"浦发银行\",\"full_name\": \"-\",\"industry_code\": \"-\",\"industry_name\": \"-\"}]" 18 | err := json.Unmarshal([]byte(companyJson), company) 19 | assert.Nil(t, err, err) 20 | 21 | collector := SHDataCollector{} 22 | Data := collector.FetchAll(*company, conf) 23 | 24 | logger.Infow("Data", Data) 25 | assert.Equal(t, 1, len(Data)) 26 | } 27 | -------------------------------------------------------------------------------- /collector/data/sz_data_collector.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "github.com/xiaotian/stock/enums" 7 | "github.com/xiaotian/stock/model" 8 | "github.com/xiaotian/stock/s-logger" 9 | "github.com/xiaotian/stock/tool" 10 | "io/ioutil" 11 | "net/http" 12 | "time" 13 | ) 14 | 15 | var logger = s_logger.New() 16 | 17 | type SZDataCollector struct { 18 | } 19 | 20 | type Response struct { 21 | Code string `json:"code"` 22 | Data ResponseData `json:"data"` 23 | Error string `json:"error"` 24 | } 25 | 26 | type ResponseData struct { 27 | PicUpData [][]interface{} `json:"picupdata"` 28 | } 29 | 30 | func (s SZDataCollector) GetStockExchange() int { 31 | return enums.SZ 32 | } 33 | 34 | func (s SZDataCollector) FetchAll(company []model.Company, conf model.StockConfig) []model.Data { 35 | logger.Infow("获取深交所上市公司股票价格数据,", "company count", len(company), "conf", conf) 36 | result := make([]model.Data, 0) 37 | for _, c := range company { 38 | if s.GetStockExchange() != c.StockExchange { 39 | logger.Infow("获取深交所上市公司股票价格数据,收集器不能处理对应公司数据,跳过", 40 | "company", c, "conf", conf, 41 | "collectorStockExchange", c.StockExchange, "companyStockExchange", c.StockExchange) 42 | continue 43 | } 44 | logger.Infow("获取深交所上市公司股票价格数据", "company", c, "conf", conf) 45 | data, err := getData(c, conf) 46 | if err != nil { 47 | logger.Errorw("获取深交所上市公司股票价格数据,获取数据异常", "company", c, "conf", conf, "err", err) 48 | continue 49 | } 50 | result = append(result, data) 51 | } 52 | return result 53 | } 54 | 55 | func getData(company model.Company, config model.StockConfig) (model.Data, error) { 56 | time.Sleep(time.Millisecond * 500) 57 | data := &model.Data{} 58 | data.StockExchange = company.StockExchange 59 | data.Code = company.Code 60 | data.Plate = company.Plate 61 | 62 | url := config.RealTimeInfoUrl + "&code=" + company.Code 63 | logger.Infow("获取深交所上市公司股票数据,开始", "code", company.Code, "company", company.ShortName, "url", url) 64 | response, err := http.Get(url) 65 | if err != nil { 66 | logger.Errorw("获取深交所上市公司股票数据,请求数据出现异常", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 67 | return *data, errors.New("请求数据出现异常") 68 | } 69 | responseData, err := ioutil.ReadAll(response.Body) 70 | if err != nil { 71 | logger.Errorw("获取深交所上市公司股票数据,读取响应数据出错", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 72 | return *data, errors.New("读取响应数据出错") 73 | } 74 | responseDataPointer := &Response{} 75 | if err = json.Unmarshal(responseData, responseDataPointer); err != nil { 76 | logger.Errorw("获取深交所上市公司股票数据,解析数据出错", "code", company.Code, "company", company.ShortName, "url", url, "error", err) 77 | return *data, errors.New("解析数据出错") 78 | } 79 | copyData(data, responseDataPointer) 80 | logger.Infow("获取深交所上市公司股票数据,结束", "code", company.Code, "company", company.ShortName, "url", url) 81 | return *data, nil 82 | } 83 | 84 | func copyData(data *model.Data, response *Response) { 85 | for _, p := range response.Data.PicUpData { 86 | data.AddInnerData(tool.NowDate()+" "+p[0].(string), p[1].(string)) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /collector/data/sz_data_collector_test.go: -------------------------------------------------------------------------------- 1 | package data 2 | 3 | import ( 4 | "encoding/json" 5 | "github.com/stretchr/testify/assert" 6 | "github.com/xiaotian/stock/config" 7 | "github.com/xiaotian/stock/enums" 8 | "github.com/xiaotian/stock/model" 9 | "testing" 10 | ) 11 | 12 | func TestFetchOne(t *testing.T) { 13 | 14 | conf := config.GetStockConfig(enums.SZ) 15 | company := &[]model.Company{} 16 | 17 | var companyJson = "[{\"stock_exchange\": 100,\"code\": \"000001\",\"plate\": \"100\",\"short_name\": \"平安银行\",\"full_name\": \"平安银行股份有限公司\",\"industry_code\": \"J\",\"industry_name\": \"金融业\"}]" 18 | err := json.Unmarshal([]byte(companyJson), company) 19 | assert.Nil(t, err, err) 20 | 21 | collector := SZDataCollector{} 22 | Data := collector.FetchAll(*company, conf) 23 | 24 | logger.Infow("Data", Data) 25 | assert.Equal(t, 1, len(Data)) 26 | } 27 | -------------------------------------------------------------------------------- /collector/data_collector.go: -------------------------------------------------------------------------------- 1 | package collector 2 | 3 | import ( 4 | "github.com/xiaotian/stock/collector/data" 5 | "github.com/xiaotian/stock/config" 6 | "github.com/xiaotian/stock/model" 7 | ) 8 | 9 | var dataCollectors map[int]data.Collector = make(map[int]data.Collector) 10 | 11 | func init() { 12 | logger.Infow("初始化数据收集器容器") 13 | addDataCollectorToMap(data.SZDataCollector{}) 14 | addDataCollectorToMap(data.SHDataCollector{}) 15 | addDataCollectorToMap(data.HKDataCollector{}) 16 | } 17 | 18 | func addDataCollectorToMap(collector data.Collector) { 19 | dataCollectors[collector.GetStockExchange()] = collector 20 | } 21 | 22 | func CollectData(company []model.Company) []model.Data { 23 | logger.Infow("收集公司数据开始") 24 | tempData := make([]model.Data, 0) 25 | for key, collector := range dataCollectors { 26 | logger.Infow("收集公司数据.", "stockCode", key, "collector", collector) 27 | all := collector.FetchAll(company, config.GetStockConfig(collector.GetStockExchange())) 28 | tempData = append(tempData, all...) 29 | } 30 | logger.Infow("收集公司数据结束") 31 | return tempData 32 | } 33 | -------------------------------------------------------------------------------- /collector/token/common.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import s_logger "github.com/xiaotian/stock/s-logger" 4 | 5 | var logger = s_logger.New() 6 | 7 | const TokenLineIndex string = "getToken = function" 8 | -------------------------------------------------------------------------------- /collector/token/hk_token.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | "io/ioutil" 5 | "net/http" 6 | "strings" 7 | ) 8 | 9 | func GetHKToken(url string) string { 10 | 11 | response, err := http.Get(url) 12 | if err != nil { 13 | logger.Panicw("Get HangKong Stock Market Data Exception", "err", err) 14 | } 15 | allBytes, err := ioutil.ReadAll(response.Body) 16 | if err != nil { 17 | logger.Panicw("Get HangKong Stock Market Read Data Exception", "err", err) 18 | } 19 | 20 | split := strings.Split(string(allBytes), "\n") 21 | startGetToken := false 22 | for _, line := range split { 23 | if strings.Contains(line, TokenLineIndex) { 24 | startGetToken = true 25 | continue 26 | } 27 | if startGetToken { 28 | line = strings.TrimSpace(line) 29 | if strings.HasPrefix(line, "return") { 30 | line = strings.ReplaceAll(line, "return", "") 31 | line = strings.ReplaceAll(line, "\"", "") 32 | line = strings.ReplaceAll(line, ";", "") 33 | line = strings.ReplaceAll(line, " ", "") 34 | line = strings.TrimSpace(line) 35 | return line 36 | } 37 | } 38 | } 39 | return "" 40 | } 41 | -------------------------------------------------------------------------------- /collector/token/hk_token_test.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func TestGetHKToken(t *testing.T) { 9 | token := GetHKToken("https://www.hkex.com.hk/Market-Data/Securities-Prices/Equities?sc_lang=zh-HK") 10 | assert.NotEmpty(t, token, "GET TOKEN FAILED") 11 | } 12 | -------------------------------------------------------------------------------- /config/config.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "github.com/spf13/viper" 5 | "github.com/xiaotian/stock/model" 6 | ) 7 | 8 | //配置文件名字 9 | const ( 10 | defaultConfigFileName string = "project_config" 11 | ) 12 | 13 | var projectViper *viper.Viper 14 | var stockConfigMap = make(map[int]model.StockConfig) 15 | var dataSaveFilePath string 16 | var skipIfNoData bool 17 | 18 | func init() { 19 | //项目配置文件 20 | projectViper = viper.New() 21 | projectViper.SetConfigType("yaml") 22 | projectViper.AddConfigPath(".") 23 | projectViper.AddConfigPath("../") 24 | projectViper.AddConfigPath("../../") 25 | projectViper.AddConfigPath("../../../") 26 | projectViper.SetConfigName(defaultConfigFileName) 27 | if err := projectViper.ReadInConfig(); nil != err { 28 | panic(err) 29 | } 30 | //股票信息配置 31 | var P *model.StockConfigs 32 | if err := projectViper.UnmarshalKey("stock", &P); nil != err { 33 | panic(err) 34 | } 35 | for _, stockConfig := range P.Configs { 36 | stockConfigMap[stockConfig.StockExchangeCode] = stockConfig 37 | } 38 | dataSaveFilePath = P.DataSavePath 39 | skipIfNoData = P.SkipIfNoData 40 | } 41 | 42 | func GetStockConfig(s int) model.StockConfig { 43 | return stockConfigMap[s] 44 | } 45 | 46 | func GetDataSaveFilePath() string { 47 | return dataSaveFilePath 48 | } 49 | 50 | func SkipNoData() bool { 51 | return skipIfNoData 52 | } 53 | -------------------------------------------------------------------------------- /config/config_test.go: -------------------------------------------------------------------------------- 1 | package config 2 | 3 | import ( 4 | "fmt" 5 | "github.com/stretchr/testify/assert" 6 | "github.com/xiaotian/stock/enums" 7 | "testing" 8 | ) 9 | 10 | func TestGetStockExchangeConfig(t *testing.T) { 11 | HKConfig := GetStockConfig(enums.HK) 12 | 13 | assert.NotEmpty(t, HKConfig, "配置信息为空,没有获取到配置信息") 14 | fmt.Println(HKConfig) 15 | assert.Equal(t, "HK", HKConfig.StockExchange, "配置信息不正确") 16 | 17 | filePath := GetDataSaveFilePath() 18 | assert.NotEmpty(t, filePath) 19 | 20 | skipNoData := SkipNoData() 21 | assert.Equal(t, skipNoData, true) 22 | } 23 | -------------------------------------------------------------------------------- /enums/enums.go: -------------------------------------------------------------------------------- 1 | package enums 2 | 3 | type enum interface { 4 | CodeToName(code string) string 5 | NameToCode(name string) string 6 | } 7 | -------------------------------------------------------------------------------- /enums/plate_enums.go: -------------------------------------------------------------------------------- 1 | package enums 2 | 3 | import ( 4 | "github.com/xiaotian/stock/model" 5 | ) 6 | 7 | type PlateEnum struct { 8 | StockExchange int 9 | Code string 10 | Name string 11 | Tab string 12 | Index int 13 | } 14 | 15 | var SZMainPlate = PlateEnum{StockExchange: SZ, Code: "100", Name: "主板", Tab: "tab2", Index: 2} 16 | var SZMiddleOrLittlePlate = PlateEnum{StockExchange: SZ, Code: "200", Name: "中小企业版", Tab: "tab3", Index: 3} 17 | var SZPioneerPlatePlate = PlateEnum{StockExchange: SZ, Code: "300", Name: "创业版", Tab: "tab4", Index: 4} 18 | var SHAPlate = PlateEnum{StockExchange: SH, Code: "1000", Name: "A股", Tab: "1", Index: 0} 19 | var SHBPlate = PlateEnum{StockExchange: SH, Code: "1100", Name: "B股", Tab: "2", Index: 0} 20 | var SHTechnologyPlate = PlateEnum{StockExchange: SH, Code: "1200", Name: "科创版", Tab: "8", Index: 0} 21 | var HKMainPlate = PlateEnum{StockExchange: HK, Code: "2000", Name: "主板", Tab: "MAIN", Index: 0} 22 | var HKGemPlate = PlateEnum{StockExchange: HK, Code: "2100", Name: "GEM", Tab: "GEM", Index: 0} 23 | 24 | var result = []PlateEnum{SZMainPlate, SZMiddleOrLittlePlate, SZPioneerPlatePlate, SHAPlate, SHBPlate, SHTechnologyPlate, HKMainPlate, HKGemPlate} 25 | 26 | func GetAll() []PlateEnum { 27 | return result 28 | } 29 | 30 | func GetByStockExchange(sc model.StockConfig) []PlateEnum { 31 | temp := make([]PlateEnum, 0) 32 | for _, r := range result { 33 | if r.StockExchange == sc.StockExchangeCode { 34 | temp = append(temp, r) 35 | } 36 | } 37 | return temp 38 | } 39 | 40 | func (p PlateEnum) CodeToName(code string) string { 41 | for _, r := range result { 42 | if r.Code == code { 43 | return r.Name 44 | } 45 | } 46 | return "" 47 | 48 | } 49 | 50 | func (p PlateEnum) NameToCode(name string) string { 51 | for _, r := range result { 52 | if r.Name == name { 53 | return r.Code 54 | } 55 | } 56 | return "" 57 | } 58 | -------------------------------------------------------------------------------- /enums/stock_exchange_enum.go: -------------------------------------------------------------------------------- 1 | package enums 2 | 3 | const ( 4 | SZ int = 100 5 | SH int = 130 6 | HK int = 160 7 | ) 8 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xiaotian/stock 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/bittygarden/lilac v1.1.7 7 | github.com/fsnotify/fsnotify v1.4.9 // indirect 8 | github.com/magiconair/properties v1.8.4 // indirect 9 | github.com/mitchellh/mapstructure v1.4.1 // indirect 10 | github.com/pelletier/go-toml v1.8.1 // indirect 11 | github.com/spf13/afero v1.5.1 // indirect 12 | github.com/spf13/cast v1.3.1 // indirect 13 | github.com/spf13/jwalterweatherman v1.1.0 // indirect 14 | github.com/spf13/pflag v1.0.5 // indirect 15 | github.com/spf13/viper v1.7.1 16 | github.com/stretchr/testify v1.6.1 17 | go.uber.org/multierr v1.6.0 // indirect 18 | go.uber.org/zap v1.16.0 19 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect 20 | golang.org/x/text v0.3.5 // indirect 21 | gopkg.in/ini.v1 v1.62.0 // indirect 22 | gopkg.in/natefinch/lumberjack.v2 v2.0.0 23 | gopkg.in/yaml.v2 v2.2.8 // indirect 24 | ) 25 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 3 | cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= 4 | cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= 5 | cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= 6 | cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= 7 | cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= 8 | cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= 9 | cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= 10 | cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= 11 | cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= 12 | cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= 13 | dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= 14 | github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= 15 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 16 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 17 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 18 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 19 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 20 | github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= 21 | github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= 22 | github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= 23 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 24 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 25 | github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= 26 | github.com/bittygarden/lilac v1.1.7 h1:W5w72l7iqVLNfke6o7WzKMOSY82/RopDOydxxMzBvx0= 27 | github.com/bittygarden/lilac v1.1.7/go.mod h1:WtPu5yiYq3LiOO1qfwMc8XyKO0lsXwRCr82oq61ZGM4= 28 | github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= 29 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 30 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 31 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 32 | github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 33 | github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 34 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 35 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 36 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 37 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 38 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 39 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 40 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 41 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 42 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 43 | github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= 44 | github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= 45 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 46 | github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= 47 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 48 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 49 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 50 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 51 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 52 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 53 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 54 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 55 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 56 | github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 57 | github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= 58 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 59 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 60 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 61 | github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 62 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 63 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 64 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 65 | github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= 66 | github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 67 | github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= 68 | github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= 69 | github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= 70 | github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= 71 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= 72 | github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= 73 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= 74 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 75 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 76 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 77 | github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= 78 | github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= 79 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= 80 | github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= 81 | github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= 82 | github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM= 83 | github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 84 | github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= 85 | github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= 86 | github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= 87 | github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 88 | github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= 89 | github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= 90 | github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 91 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 92 | github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= 93 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 94 | github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= 95 | github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= 96 | github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= 97 | github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= 98 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 99 | github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 100 | github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= 101 | github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= 102 | github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= 103 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 104 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 105 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 106 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 107 | github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= 108 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 109 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 110 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 111 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 112 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 113 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 114 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 115 | github.com/magiconair/properties v1.8.4 h1:8KGKTcQQGm0Kv7vEbKFErAoAOFyyacLStRtQSeYtvkY= 116 | github.com/magiconair/properties v1.8.4/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= 117 | github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= 118 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 119 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 120 | github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= 121 | github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= 122 | github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 123 | github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= 124 | github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= 125 | github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= 126 | github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 127 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 128 | github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag= 129 | github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= 130 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 131 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 132 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 133 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 134 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= 135 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 136 | github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= 137 | github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= 138 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 139 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 140 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 141 | github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= 142 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 143 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 144 | github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= 145 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 146 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 147 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 148 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 149 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 150 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 151 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 152 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 153 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 154 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 155 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= 156 | github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= 157 | github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= 158 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 159 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= 160 | github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= 161 | github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= 162 | github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= 163 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 164 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 165 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 166 | github.com/spf13/afero v1.5.1 h1:VHu76Lk0LSP1x254maIu2bplkWpfBWI+B+6fdoZprcg= 167 | github.com/spf13/afero v1.5.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I= 168 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 169 | github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= 170 | github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 171 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 172 | github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk= 173 | github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= 174 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 175 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 176 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 177 | github.com/spf13/viper v1.7.1 h1:pM5oEahlgWv/WnHXpgbKz7iLIxRf65tye2Ci+XFK5sk= 178 | github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= 179 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 180 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 181 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 182 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 183 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 184 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= 185 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 186 | github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= 187 | github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= 188 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 189 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 190 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 191 | go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= 192 | go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= 193 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 194 | go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= 195 | go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= 196 | go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 197 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 198 | go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= 199 | go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= 200 | go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= 201 | go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= 202 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 203 | go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM= 204 | go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ= 205 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 206 | golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 207 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 208 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 209 | golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 210 | golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 211 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 212 | golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 213 | golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= 214 | golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= 215 | golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= 216 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 217 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 218 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 219 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 220 | golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 221 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 222 | golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 223 | golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 224 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= 225 | golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 226 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 227 | golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= 228 | golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= 229 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 230 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 231 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 232 | golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 233 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 234 | golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 235 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 236 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 237 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 238 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 239 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 240 | golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 241 | golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 242 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 243 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 244 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 245 | golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 246 | golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 247 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 248 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 249 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 250 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 251 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 252 | golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 253 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 254 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 255 | golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 256 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 257 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 258 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 259 | golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 260 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 261 | golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 262 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 263 | golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 264 | golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 265 | golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 266 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c h1:VwygUrnw9jn88c4u8GD3rZQbqrP/tgas88tPUbBxQrk= 267 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 268 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 269 | golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 270 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 271 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 272 | golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= 273 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 274 | golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 275 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 276 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 277 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 278 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 279 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 280 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 281 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 282 | golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 283 | golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 284 | golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 285 | golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 286 | golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 287 | golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 288 | golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 289 | golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 290 | golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 291 | golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 292 | golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 293 | golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 294 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc h1:NCy3Ohtk6Iny5V/reW2Ktypo4zIpWBdRJ1uFMjBxdg8= 295 | golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 296 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 297 | google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= 298 | google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= 299 | google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 300 | google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= 301 | google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= 302 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 303 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 304 | google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 305 | google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= 306 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 307 | google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 308 | google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 309 | google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 310 | google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= 311 | google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 312 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 313 | google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= 314 | google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= 315 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 316 | google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= 317 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 318 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 319 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 320 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 321 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 322 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= 323 | gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 324 | gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU= 325 | gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= 326 | gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= 327 | gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= 328 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 329 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 330 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 331 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 332 | gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 333 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 334 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 335 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 336 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 337 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 338 | honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 339 | honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 340 | honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM= 341 | honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= 342 | rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= 343 | -------------------------------------------------------------------------------- /model/company.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | //股票公司 4 | type Company struct { 5 | StockExchange int `json:"stock_exchange"` 6 | Code string `json:"code"` 7 | Plate string `json:"plate"` 8 | ShortName string `json:"short_name"` 9 | FullName string `json:"full_name"` 10 | IndustryCode string `json:"industry_code"` 11 | IndustryName string `json:"industry_name"` 12 | ListingDate string `json:"listing_date"` 13 | } 14 | -------------------------------------------------------------------------------- /model/config_define.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | //配置信息定义 8 | type StockConfig struct { 9 | StockExchangeCode int 10 | StockExchange string 11 | CompanyInfoUrl string 12 | StockInfoUrl string 13 | RealTimeInfoUrl string 14 | TokenUrl string 15 | } 16 | 17 | type StockConfigs struct { 18 | Configs []StockConfig 19 | DataSavePath string 20 | SkipIfNoData bool 21 | } 22 | 23 | func (s StockConfig) String() string { 24 | return fmt.Sprintf("StockExchangeCode: %d, StockExchange: %s, CompanyInfoUrl: %s, StockInfoUrl: %s, RealTimeInfoUrl: %s", 25 | s.StockExchangeCode, s.StockExchange, s.CompanyInfoUrl, s.StockInfoUrl, s.RealTimeInfoUrl) 26 | } 27 | -------------------------------------------------------------------------------- /model/data.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | type Data struct { 4 | StockExchange int `json:"stock_exchange"` 5 | Code string `json:"code"` 6 | Plate string `json:"plate"` 7 | Data []InnerData `json:"sample"` 8 | } 9 | 10 | func (d *Data) AddInnerData(date string, price string) { 11 | d.Data = append(d.Data, InnerData{Date: date, Price: price}) 12 | } 13 | 14 | type InnerData struct { 15 | Date string `json:"date"` 16 | Price string `json:"price"` 17 | } 18 | -------------------------------------------------------------------------------- /persistent/company-2021-01-31.json: -------------------------------------------------------------------------------- 1 | [{"stock_exchange":0,"code":"1","plate":"","short_name":"","full_name":"","industry_code":"","industry_name":"","listing_date":""},{"stock_exchange":0,"code":"2","plate":"","short_name":"","full_name":"","industry_code":"","industry_name":"","listing_date":""}] -------------------------------------------------------------------------------- /persistent/company_file_persistent.go: -------------------------------------------------------------------------------- 1 | package persistent 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "github.com/xiaotian/stock/config" 7 | "github.com/xiaotian/stock/model" 8 | "github.com/xiaotian/stock/s-logger" 9 | "github.com/xiaotian/stock/tool" 10 | "io/ioutil" 11 | ) 12 | 13 | var logger = s_logger.New() 14 | 15 | type CompanyFilePreserver struct{} 16 | 17 | func (c CompanyFilePreserver) Save(data []model.Company) error { 18 | pathName := config.GetDataSaveFilePath() 19 | marshal, err := json.Marshal(data) 20 | if nil != err { 21 | logger.Infow("保存数据到文件,数据格式化异常", "pathName", pathName, "err", err) 22 | return errors.New("保存数据到文件,数据格式化异常") 23 | } 24 | err = ioutil.WriteFile(pathName+c.getFullFileName(tool.NowDate()), marshal, 0664) 25 | if nil != err { 26 | logger.Infow("保存数据到文件,写入文件数据异常", "pathName", pathName, "err", err) 27 | return errors.New("保存数据到文件,写入文件数据异常") 28 | } 29 | return nil 30 | } 31 | 32 | func (c CompanyFilePreserver) Read() ([]model.Company, error) { 33 | pathName := config.GetDataSaveFilePath() 34 | file, err := ioutil.ReadFile(pathName + c.getFullFileName(tool.NowDate())) 35 | if nil != err { 36 | logger.Infow("从文件读取数据,读取数据异常", "pathName", pathName, "err", err) 37 | return nil, errors.New("从文件读取数据,读取数据异常") 38 | } 39 | 40 | d := &[]model.Company{} 41 | err = json.Unmarshal(file, &d) 42 | if nil != err { 43 | logger.Infow("从文件读取数据,解析数据异常", "pathName", pathName, "err", err) 44 | return nil, errors.New("从文件读取数据,读取数据异常") 45 | } 46 | return *d, nil 47 | } 48 | 49 | func (c CompanyFilePreserver) getFullFileName(append string) string { 50 | return c.getPrefix() + append + c.getSuffix() 51 | } 52 | 53 | func (c CompanyFilePreserver) getPrefix() string { 54 | return "company-" 55 | } 56 | 57 | func (c CompanyFilePreserver) getSuffix() string { 58 | return ".json" 59 | } 60 | -------------------------------------------------------------------------------- /persistent/company_file_persistent_test.go: -------------------------------------------------------------------------------- 1 | package persistent 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "github.com/xiaotian/stock/model" 6 | "testing" 7 | ) 8 | 9 | func TestName(t *testing.T) { 10 | d := make([]model.Company, 0) 11 | d = append(d, model.Company{Code: "1"}) 12 | d = append(d, model.Company{Code: "2"}) 13 | 14 | cfp := CompanyFilePreserver{} 15 | 16 | err := cfp.Save(d) 17 | 18 | assert.Nil(t, err, "") 19 | 20 | read, err := cfp.Read() 21 | assert.Empty(t, err) 22 | assert.NotEmpty(t, read, "") 23 | assert.Equal(t, "1", read[0].Code) 24 | assert.Equal(t, "2", read[1].Code) 25 | } 26 | -------------------------------------------------------------------------------- /persistent/constant.go: -------------------------------------------------------------------------------- 1 | package persistent 2 | 3 | const ( 4 | maxLevel int = 10 5 | ) 6 | -------------------------------------------------------------------------------- /persistent/data_file_persistent.go: -------------------------------------------------------------------------------- 1 | package persistent 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "github.com/xiaotian/stock/config" 7 | "github.com/xiaotian/stock/model" 8 | "github.com/xiaotian/stock/tool" 9 | "io/ioutil" 10 | ) 11 | 12 | type DataFilePreserver struct{} 13 | 14 | func (c DataFilePreserver) Save(data []model.Data) error { 15 | pathName := config.GetDataSaveFilePath() 16 | marshal, err := json.Marshal(data) 17 | if nil != err { 18 | logger.Infow("保存数据到文件,数据格式化异常", "pathName", pathName, "err", err) 19 | return errors.New("保存数据到文件,数据格式化异常") 20 | } 21 | err = ioutil.WriteFile(pathName+c.getFullFileName(tool.NowDate()), marshal, 0664) 22 | if nil != err { 23 | logger.Infow("保存数据到文件,写入文件数据异常", "pathName", pathName, "err", err) 24 | return errors.New("保存数据到文件,写入文件数据异常") 25 | } 26 | return nil 27 | } 28 | 29 | func (c DataFilePreserver) Read() ([]model.Data, error) { 30 | pathName := config.GetDataSaveFilePath() 31 | file, err := ioutil.ReadFile(pathName + c.getFullFileName(tool.NowDate())) 32 | if nil != err { 33 | logger.Infow("从文件读取数据,读取数据异常", "pathName", pathName, "err", err) 34 | return nil, errors.New("从文件读取数据,读取数据异常") 35 | } 36 | 37 | d := &[]model.Data{} 38 | err = json.Unmarshal(file, d) 39 | if nil != err { 40 | logger.Infow("从文件读取数据,解析数据异常", "pathName", pathName, "err", err) 41 | return nil, errors.New("从文件读取数据,读取数据异常") 42 | } 43 | return *d, nil 44 | } 45 | 46 | func (c DataFilePreserver) getFullFileName(append string) string { 47 | return c.getPrefix() + append + c.getSuffix() 48 | } 49 | 50 | func (c DataFilePreserver) getPrefix() string { 51 | return "data-" 52 | } 53 | 54 | func (c DataFilePreserver) getSuffix() string { 55 | return ".json" 56 | } 57 | -------------------------------------------------------------------------------- /persistent/file.go: -------------------------------------------------------------------------------- 1 | package persistent 2 | 3 | //文件接口 4 | type File interface { 5 | getPrefix() string 6 | getSuffix() string 7 | } 8 | -------------------------------------------------------------------------------- /persistent/persistent.go: -------------------------------------------------------------------------------- 1 | package persistent 2 | 3 | import "github.com/xiaotian/stock/model" 4 | 5 | //持久接口 6 | type Preserver interface { 7 | Save(data []model.Company) error 8 | Read() ([]model.Company, error) 9 | } 10 | -------------------------------------------------------------------------------- /project_config.yml: -------------------------------------------------------------------------------- 1 | stock: 2 | skipifnodata: true 3 | # windows 4 | # datasavepath: 'd:/data/' 5 | # linux 6 | datasavepath: './' 7 | configs: 8 | - stockexchange: "SZ" 9 | stockexchangecode: 100 10 | companyinfourl: "http://www.szse.cn/api/report/ShowReport/data?SHOWTYPE=JSON&CATALOGID=1110x" 11 | stockinfourl: "http://www.szse.cn/api/market/ssjjhq/getTimeData?random=0.20171192356322387&marketId=1" 12 | realtimeinfourl: "http://www.szse.cn/api/market/ssjjhq/getTimeData?random=0.20171192356322387&marketId=1" 13 | - stockexchange: "SH" 14 | stockexchangecode: 130 15 | companyinfourl: "http://query.sse.com.cn/security/stock/getStockListData.do?isPagination=true&stockCode=&csrcCode=&areaName=&pageHelp.cacheSize=1&pageHelp.pageSize=100" 16 | stockinfourl: "" 17 | realtimeinfourl: "http://yunhq.sse.com.cn:32041//v1/sh1/line/{code}?begin=0&end=-1&select=time%2Cprice%2Cvolume&_=1592540108264" 18 | - stockexchange: "HK" 19 | stockexchangecode: 160 20 | companyinfourl: "https://www1.hkex.com.hk/hkexwidget/data/getequityfilter?lang=chn&token={token}&sort=5&order=0&all=1&callback=jQuery31102693108676392699_1592557858914" 21 | stockinfourl: "" 22 | realtimeinfourl: "https://www1.hkex.com.hk/hkexwidget/data/getchartdata2?hchart=1&span=0&int=0&ric={code}.HK&token={token}&callback=jQuery311028459911169776264_1592561666530" 23 | tokenurl: "https://www.hkex.com.hk/Market-Data/Securities-Prices/Equities?sc_lang=zh-HK" 24 | -------------------------------------------------------------------------------- /s-logger/logger.go: -------------------------------------------------------------------------------- 1 | package s_logger 2 | 3 | import ( 4 | "go.uber.org/zap" 5 | "go.uber.org/zap/zapcore" 6 | "gopkg.in/natefinch/lumberjack.v2" 7 | "os" 8 | "time" 9 | ) 10 | 11 | var logger *zap.SugaredLogger 12 | 13 | func init() { 14 | GTEError := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { 15 | return lvl >= zapcore.ErrorLevel 16 | }) 17 | 18 | GETDebug := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { 19 | return lvl > zapcore.DebugLevel 20 | }) 21 | 22 | infoOutput := zapcore.AddSync(&lumberjack.Logger{ 23 | Filename: "log-info.log", 24 | MaxSize: 10, 25 | MaxBackups: 30, 26 | MaxAge: 28, 27 | }) 28 | 29 | errorOutput := zapcore.AddSync(&lumberjack.Logger{ 30 | Filename: "log-error.log", 31 | MaxSize: 10, 32 | MaxBackups: 30, 33 | MaxAge: 28, 34 | }) 35 | 36 | console := zapcore.Lock(os.Stdout) 37 | prodEncoder := zapcore.NewJSONEncoder(NewEncoderConfig()) 38 | devEncoder := zapcore.NewConsoleEncoder(NewEncoderConfig()) 39 | 40 | core := zapcore.NewTee( 41 | zapcore.NewCore(devEncoder, console, GETDebug), 42 | 43 | zapcore.NewCore(prodEncoder, infoOutput, GETDebug), 44 | zapcore.NewCore(prodEncoder, errorOutput, GTEError), 45 | ) 46 | l := zap.New(core, zap.AddCaller()) 47 | logger = l.Sugar() 48 | } 49 | 50 | func NewEncoderConfig() zapcore.EncoderConfig { 51 | return zapcore.EncoderConfig{ 52 | TimeKey: "Time", 53 | LevelKey: "Level", 54 | NameKey: "Name", 55 | CallerKey: "Caller", 56 | MessageKey: "Message", 57 | StacktraceKey: "Stack", 58 | LineEnding: zapcore.DefaultLineEnding, 59 | EncodeLevel: zapcore.CapitalLevelEncoder, 60 | EncodeTime: TimeEncoder, 61 | EncodeDuration: zapcore.StringDurationEncoder, 62 | EncodeCaller: zapcore.ShortCallerEncoder, 63 | } 64 | } 65 | 66 | func New() *zap.SugaredLogger { 67 | return logger 68 | } 69 | 70 | func TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) { 71 | enc.AppendString(t.Format("2006-01-02 15:04:05.000")) 72 | } 73 | -------------------------------------------------------------------------------- /s-logger/logger_test.go: -------------------------------------------------------------------------------- 1 | package s_logger 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "sync" 6 | "testing" 7 | ) 8 | 9 | func TestName(t *testing.T) { 10 | logger := New() 11 | 12 | logger.Info("Info") 13 | logger.Error("Error") 14 | defer logger.Sync() 15 | assert.NotEmpty(t, logger, "日志信息不能为空") 16 | } 17 | 18 | func TestMultiSingle(t *testing.T) { 19 | logger := New() 20 | times := 1024 21 | for i := 0; i < times; i++ { 22 | logger.Infow("测试打印日志", "name", "name") 23 | } 24 | } 25 | 26 | func TestMultiOpen(t *testing.T) { 27 | waitGroup := sync.WaitGroup{} 28 | waitGroup.Add(2) 29 | go func() { 30 | logger := New() 31 | times := 1024 32 | for i := 0; i < times; i++ { 33 | logger.Infow("1111111111", "name", "name") 34 | } 35 | waitGroup.Done() 36 | }() 37 | 38 | go func() { 39 | logger := New() 40 | times := 1024 41 | for i := 0; i < times; i++ { 42 | logger.Infow("2222222222", "name", "name") 43 | } 44 | waitGroup.Done() 45 | }() 46 | 47 | waitGroup.Wait() 48 | } 49 | -------------------------------------------------------------------------------- /stock_data.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/bittygarden/lilac/io_tool" 5 | "github.com/xiaotian/stock/collector" 6 | "github.com/xiaotian/stock/config" 7 | "github.com/xiaotian/stock/persistent" 8 | "github.com/xiaotian/stock/s-logger" 9 | ) 10 | 11 | var logger = s_logger.New() 12 | var companyFile = persistent.CompanyFilePreserver{} 13 | var dataFile = persistent.DataFilePreserver{} 14 | 15 | func main() { 16 | logger.Infow("检查配置信息") 17 | path := config.GetDataSaveFilePath() 18 | if path == "" || io_tool.FileNotExists(path) { 19 | logger.Errorw("项目运行前检查配置信息,文件保存路径不存在。请在project_config.yml中配置。", "当前配置", path) 20 | return 21 | } 22 | 23 | logger.Infow("项目启动") 24 | companyInfos := collector.CollectCompanyInfo() 25 | if err := companyFile.Save(companyInfos); err != nil { 26 | logger.Errorw("保存数据失败", "error", err) 27 | return 28 | } 29 | 30 | dataList := collector.CollectData(companyInfos) 31 | if err := dataFile.Save(dataList); err != nil { 32 | logger.Errorw("保存数据失败", "error", err) 33 | return 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tool/date.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import "time" 4 | 5 | var GMT = time.FixedZone("GMT", +8*60*60) 6 | 7 | func NowDateTime() string { 8 | return DateTime(time.Now().In(GMT)) 9 | } 10 | 11 | func NowDate() string { 12 | return Date(time.Now().In(GMT)) 13 | } 14 | 15 | func NowTime() string { 16 | return Time(time.Now().In(GMT)) 17 | } 18 | 19 | func DateTime(time time.Time) string { 20 | return time.Format("2006-01-02 15:04:05") 21 | } 22 | 23 | func Date(time time.Time) string { 24 | return time.Format("2006-01-02") 25 | } 26 | 27 | func Time(time time.Time) string { 28 | return time.Format("15:04:05") 29 | } 30 | 31 | func NowDateTimeWithLabel() (string, string) { 32 | return "date", DateTime(time.Now().In(GMT)) 33 | } 34 | 35 | func ParseDateTime(timeStr string) time.Time { 36 | result, err := time.ParseInLocation("2006-01-02 15:04:05", timeStr, GMT) 37 | if nil != err { 38 | panic(err) 39 | } 40 | return result 41 | } 42 | 43 | func ParseDate(str string) time.Time { 44 | result, err := time.ParseInLocation("2006-01-02", str, GMT) 45 | if nil != err { 46 | panic(err) 47 | } 48 | return result 49 | } 50 | 51 | func ParseTime(str string) time.Time { 52 | result, err := time.ParseInLocation("15:04:05", str, GMT) 53 | 54 | if nil != err { 55 | panic(err) 56 | } 57 | return result 58 | } 59 | -------------------------------------------------------------------------------- /tool/date_test.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | "time" 7 | ) 8 | 9 | const ( 10 | dateTimeStr = "2006-01-02 15:04:05" 11 | dateStr = "2006-01-02" 12 | timeStr = "15:04:05" 13 | ) 14 | 15 | func TestNowDateTime(t *testing.T) { 16 | dateTime := NowDateTime() 17 | assert.NotEmpty(t, dateTime) 18 | assert.Equal(t, 19, len(dateTime)) 19 | } 20 | 21 | func TestNowDate(t *testing.T) { 22 | date := NowDate() 23 | assert.NotEmpty(t, date) 24 | assert.Equal(t, 10, len(date)) 25 | } 26 | 27 | func TestNowTime(t *testing.T) { 28 | nowTime := NowTime() 29 | assert.NotEmpty(t, nowTime) 30 | assert.Equal(t, 8, len(nowTime)) 31 | } 32 | 33 | func TestParseNowDateTime(t *testing.T) { 34 | dateTime := ParseDateTime(dateTimeStr) 35 | assert.NotEmpty(t, dateTime) 36 | date, month, day := dateTime.Date() 37 | clock, min, sec := dateTime.Clock() 38 | assert.Equal(t, date, 2006) 39 | assert.Equal(t, time.January, month) 40 | assert.Equal(t, 2, day) 41 | assert.Equal(t, 15, clock) 42 | assert.Equal(t, 4, min) 43 | assert.Equal(t, 5, sec) 44 | } 45 | 46 | func TestParseNowDate(t *testing.T) { 47 | d := ParseDate(dateStr) 48 | assert.NotEmpty(t, d) 49 | date, month, day := d.Date() 50 | assert.Equal(t, date, 2006) 51 | assert.Equal(t, time.January, month) 52 | assert.Equal(t, 2, day) 53 | } 54 | 55 | func TestParseNowTime(t *testing.T) { 56 | nowTime := ParseTime(timeStr) 57 | assert.NotEmpty(t, nowTime) 58 | clock, min, sec := nowTime.Clock() 59 | assert.Equal(t, 15, clock) 60 | assert.Equal(t, 4, min) 61 | assert.Equal(t, 5, sec) 62 | } 63 | -------------------------------------------------------------------------------- /tool/file.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "errors" 5 | "github.com/xiaotian/stock/s-logger" 6 | "os" 7 | ) 8 | 9 | var logger = s_logger.New() 10 | 11 | func GetConfigFilePath(fileName string, level int, maxLevel int) (string, error) { 12 | logger.Infow("查找文件,配置文件路径", "fileName", fileName, "up level", maxLevel-level) 13 | _, err := os.Open(fileName) 14 | if level < 0 { 15 | logger.Infow("查找文件,未找到配置文件", "fileName", fileName, "up level", maxLevel-level) 16 | return "", errors.New("查找文件,未找到配置文件") 17 | } 18 | if nil == err { 19 | return fileName, nil 20 | } else { 21 | return GetConfigFilePath("../"+fileName, level-1, maxLevel) 22 | } 23 | } 24 | 25 | func GetPath(pathName string, level int, maxLevel int) (string, error) { 26 | logger.Infow("查找文件,配置文件路径", "fileName", pathName, "up level", maxLevel-level) 27 | if level < 0 { 28 | logger.Infow("查找文件,未找到配置文件", "fileName", pathName, "up level", maxLevel-level) 29 | return "", errors.New("查找文件,未找到配置文件") 30 | } 31 | _, err := os.Open(pathName) 32 | if nil == err { 33 | return pathName, nil 34 | } else { 35 | return GetPath("../"+pathName, level-1, maxLevel) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /tool/json.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import "encoding/json" 4 | 5 | func JSONToString(data interface{}) string { 6 | if marshal, err := json.Marshal(data); err == nil { 7 | return string(marshal) 8 | } 9 | return "" 10 | } 11 | -------------------------------------------------------------------------------- /tool/json_test.go: -------------------------------------------------------------------------------- 1 | package tool 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "testing" 6 | ) 7 | 8 | func TestJSONToString(t *testing.T) { 9 | 10 | toString := JSONToString("123") 11 | assert.NotEmpty(t, toString) 12 | assert.Equal(t, "\"123\"", toString) 13 | 14 | toString = JSONToString(Data{Name: "123", age: "456"}) 15 | 16 | assert.NotEmpty(t, toString) 17 | assert.Equal(t, "{\"Name\":\"123\"}", toString) 18 | } 19 | 20 | type Data struct { 21 | Name string 22 | age string 23 | } 24 | --------------------------------------------------------------------------------