├── .gitignore ├── CHANGELOG.yml ├── LICENSE.txt ├── README.md ├── build.yml ├── go-interfaces.en.md ├── go-interfaces.md ├── go.mod └── gointerfaces.go /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /.vscode/ 3 | -------------------------------------------------------------------------------- /CHANGELOG.yml: -------------------------------------------------------------------------------- 1 | # Semantic ChangeLog (see https://github.com/c4s4/changelog/) 2 | 3 | - version: 1.13.3 4 | date: 2019-10-21 5 | summary: Updated for Go 1.13.2 6 | 7 | - version: 1.13.2 8 | date: 2019-09-29 9 | summary: Updated for Go 1.13.1 10 | 11 | - version: 1.13.1 12 | date: 2019-09-10 13 | summary: Exclude vendor packages 14 | 15 | - version: 1.13.0 16 | date: 2019-09-10 17 | summary: Updated for Go 1.13 18 | 19 | - version: 1.12.3 20 | date: 2019-07-12 21 | summary: Reordered Go versions 22 | 23 | - version: 1.12.2 24 | date: 2019-07-09 25 | summary: Updated for Go 1.11.12 and 1.12.7 26 | 27 | - version: 1.12.1 28 | date: 2019-05-09 29 | summary: Updated for Go 1.11.10 and 1.12.5 30 | 31 | - version: 1.12.0 32 | date: 2019-03-15 33 | summary: Updated for Go 1.12 34 | 35 | - version: 1.11.1 36 | date: 2018-12-14 37 | summary: Updated for Go release 1.11.3 and 1.10.6 38 | 39 | - version: 1.11 40 | date: 2018-08-25 41 | summary: Updated for Go release 1.11 and 1.10.4 42 | 43 | - version: 1.10.3 44 | date: 2018-05-02 45 | summary: Updated for Go release 1.10.2 46 | 47 | - version: 1.10.2 48 | date: 2018-04-08 49 | summary: Fixed bug 50 | fixed: 51 | - "Unexported interfaces (such as net/http/I) are not listed anymore." 52 | 53 | - version: 1.10.1 54 | date: 2018-02-22 55 | summary: Fixed all warnings 56 | fixed: 57 | - "All warnings were fixed." 58 | 59 | - version: 1.10.0 60 | date: 2018-02-18 61 | summary: Updated for Go release 1.10 62 | 63 | - version: 1.9.1 64 | date: 2018-02-08 65 | summary: Updated for Go 1.8.7, 1.9.4 and 1.10rc2 66 | 67 | - version: 1.9.0 68 | date: 2017-07-27 69 | summary: Updated for GO release 1.9rc1 70 | 71 | - version: 1.8.4 72 | date: 2017-05-24 73 | summary: Updated for GO releases 1.7.6 and 1.8.3 74 | 75 | - version: 1.8.3 76 | date: 2017-02-17 77 | summary: Updated for GO release 1.8 78 | 79 | - version: 1.8.2 80 | date: 2017-01-26 81 | summary: Updated for GO releases 1.7.5 and 1.8rc2 82 | 83 | - version: 1.8.1 84 | date: 2017-01-10 85 | summary: Updated for GO release 1.8rc1 86 | 87 | - version: 1.8.0 88 | date: 2017-01-05 89 | summary: Updated for GO release 1.8beta2 90 | 91 | - version: 1.7.3 92 | date: 2016-12-19 93 | summary: Updated for GO releases 1.6.4 and 1.7.4 94 | 95 | - version: 1.7.2 96 | date: 2016-08-16 97 | summary: Updated for GO release 1.7 98 | 99 | - version: 1.7.1 100 | date: 2016-07-19 101 | summary: Updated versions to 1.6.3 and 1.7rc2 102 | 103 | - version: 1.7.0 104 | date: 2016-07-08 105 | summary: Added version 1.7rc1 106 | 107 | - version: 1.6.2 108 | date: 2016-04-21 109 | summary: Version updated to 1.6.2 110 | 111 | - version: 1.6.1 112 | date: 2016-04-13 113 | summary: Versions updated to 1.5.4 and 1.6.1 114 | 115 | - version: 1.6.0 116 | date: 2016-02-18 117 | summary: Added version 1.6 118 | 119 | - version: 1.5.5 120 | date: 2016-02-12 121 | summary: Updated version 1.5.2 -> 1.5.3 122 | 123 | - version: 1.5.4 124 | date: 2015-09-24 125 | summary: Changed tags in articles 126 | 127 | - version: 1.5.3 128 | date: 2015-09-24 129 | summary: Set update date in generated articles 130 | 131 | - version: 1.5.2 132 | date: 2015-09-24 133 | summary: Updated for GO release 1.4.3 134 | 135 | - version: 1.5.1 136 | date: 2015-09-15 137 | summary: Fixed article tables for blackfriday parser 138 | 139 | - version: 1.5.0 140 | date: 2015-09-10 141 | summary: Added article generation 142 | added: 143 | - "Added article generation in markdown format." 144 | 145 | - version: 1.4.1 146 | date: 2015-08-28 147 | summary: Fixed interface regexp 148 | fixed: 149 | - "Fixed interface regexp so that it takes empty interfaces." 150 | 151 | - version: 1.4.0 152 | date: 2015-08-27 153 | summary: Updated for GO 1.5 154 | fixed: 155 | - "Fixed interface regexp so that it doesn't take definitions in comments 156 | (such as https://github.com/golang/go/blob/go1.5/src/go/types/predicates.go#L223)." 157 | 158 | - version: 1.3.0 159 | date: 2015-03-28 160 | summary: Improved release process 161 | fixed: 162 | - "Files renamed to implement standard." 163 | - "Articles moved in relevant project." 164 | added: 165 | - "Automated release regarding branch." 166 | 167 | - version: 1.2.1 168 | date: 2015-01-16 169 | summary: Updated for GO 1.4.1 170 | 171 | - version: 1.2.0 172 | date: 2015-01-12 173 | summary: Added generation for a list of versions 174 | 175 | - version: 1.1.0 176 | date: 2014-12-24 177 | summary: Fixed for GO 1.4 and links point to sources on Github 178 | 179 | - version: 1.0.0 180 | date: 2014-10-29 181 | summary: First release 182 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GO Interfaces 2 | ============= 3 | 4 | 7 | [![Code Quality](https://goreportcard.com/badge/github.com/c4s4/gointerfaces)](https://goreportcard.com/report/github.com/c4s4/gointerfaces) 8 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 9 | 12 | 13 | - Project : . 14 | - Downloads : . 15 | 16 | This program lists all public GO interfaces. To run it, just type: 17 | 18 | go run gointerfaces.go 19 | 20 | Where *<versions>* is a list of GO versions, for instance *1.0.3 1.1.2 1.2.2 1.3.3 1.4*. 21 | 22 | This compiles and runs the program that will: 23 | 24 | - Download the GO source tarballs. 25 | - Parse all GO source files. 26 | - Extract all interface declarations for GO versions. 27 | - Print them on the console in markdown table format. 28 | 29 | To get result in HTML, you can pipe the output to *pandoc*: 30 | 31 | ``` 32 | $ go run gointerfaces.go 1.4.1 | pandoc -f markdown -t html 33 | ``` 34 | 35 | You may see the result on this page: . 36 | 37 | *Enjoy!* 38 | -------------------------------------------------------------------------------- /build.yml: -------------------------------------------------------------------------------- 1 | # NeON build file (http://github.com/c4s4/neon) 2 | 3 | extends: golang 4 | default: [clean, check, articles] 5 | configuration: '~/.neon/github.yml' 6 | 7 | properties: 8 | SWEETOHM: '../sweetohm/content/article' 9 | GO_VERSIONS: 10 | - '1.21.5' 11 | - '1.20.12' 12 | # - '1.19.13' 13 | # - '1.18.10' 14 | # - '1.17.13' 15 | - '1.16.14' 16 | # - '1.15.15' 17 | # - '1.14.15' 18 | # - '1.13.15' 19 | - '1.12.17' 20 | # - '1.11.13' 21 | # - '1.10.8' 22 | # - '1.9.7' 23 | - '1.8.7' 24 | # - '1.7.6' 25 | # - '1.6.4' 26 | # - '1.5.4' 27 | - '1.4.3' 28 | # - '1.3.3' 29 | # - '1.2.2' 30 | # - '1.1.2' 31 | - '1.0.3' 32 | 33 | targets: 34 | 35 | articles: 36 | doc: Generate articles 37 | steps: 38 | - mkdir: "#{BUILD_DIR}" 39 | - $: ['go', 'run', 'gointerfaces.go'] 40 | +: GO_VERSIONS 41 | 1>: '={BUILD_DIR}/interfaces.md' 42 | 1x: true 43 | - copy: 'go-interfaces*.md' 44 | todir: '={BUILD_DIR}' 45 | - read: '={BUILD_DIR}/interfaces.md' 46 | to: 'interfaces' 47 | - for: 'file' 48 | in: 'find(BUILD_DIR, "go-interfaces*.md")' 49 | do: 50 | - replace: '#{BUILD_DIR}/#{file}' 51 | with: 52 | 'INTERFACES': =interfaces 53 | 'UPDATE': '={now()[0:10]}' 54 | - copy: 'go-interfaces*.md' 55 | dir: =BUILD_DIR 56 | todir: =SWEETOHM 57 | -------------------------------------------------------------------------------- /go-interfaces.en.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: List of all Go Interfaces 3 | author: Michel Casabianca 4 | date: 2014-10-28 5 | updated: UPDATE 6 | categories: [articles] 7 | tags: [golang] 8 | id: go-interfaces.en 9 | email: casa@sweetohm.net 10 | lang: en 11 | toc: no 12 | --- 13 | 14 | While attending dotGo, where the buzzword was clearly *the interface*, I was wondering where I could find a list of all interfaces defined in the GO language. I found nowhere. 15 | 16 | Thus I decided to write a little GO program that would; 17 | 18 | - Downloads the GO source tarball for a given version. 19 | - Parses source files to extract the interface names and line number where they are defined. 20 | - Write this list on the console in the markdown format. 21 | 22 | 23 | 24 | The project is on Github: . 25 | 26 | Here is the result: 27 | 28 | INTERFACES 29 | 30 | You may find a discussion on these interfaces on this page: . 31 | 32 | *Enjoy!* 33 | -------------------------------------------------------------------------------- /go-interfaces.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Les interfaces du Go 3 | author: Michel Casabianca 4 | date: 2014-10-28 5 | updated: UPDATE 6 | categories: [articles] 7 | tags: [golang] 8 | id: go-interfaces 9 | email: casa@sweetohm.net 10 | lang: fr 11 | toc: no 12 | --- 13 | 14 | En assistant à la dotGo, où le buzzword était clairement *l'interface*, je me suis demandé où l'on pouvait se procurer la liste de toutes les interfaces définies dans le langage. J'ai cherché et n'ai trouvé cette information nulle part. 15 | 16 | Je me suis donc décidé à écrire un petit programme qui : 17 | 18 | - Télécharge le tarball des sources d'une version donnée. 19 | - Parse les fichiers sources pour en extraire les interfaces ainsi que le numéro de ligne où elles sont définies. 20 | - Affiche sur la console la liste de ces interfaces sous la forme d'un tableau markdown. 21 | 22 | 23 | 24 | Le projet se trouve sur Github : . 25 | 26 | Voici le résultat : 27 | 28 | INTERFACES 29 | 30 | On pourra trouver une discussion sur ces interfaces dans l'article suivant (en anglais) : . 31 | 32 | *Enjoy!* 33 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/c4s4/gointerfaces 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /gointerfaces.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "archive/tar" 5 | "bufio" 6 | "compress/gzip" 7 | "fmt" 8 | "io" 9 | "net/http" 10 | "os" 11 | "regexp" 12 | "sort" 13 | "strconv" 14 | "strings" 15 | ) 16 | 17 | const ( 18 | oldSrcURL = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/go/" 19 | newSrcURL = "https://storage.googleapis.com/golang/" 20 | oldSrcDir = "src/pkg" 21 | newSrcDir = "src" 22 | // expects go version, source file and line number 23 | sourceURL = "https://github.com/golang/go/blob/go%s/%s#L%s" 24 | interfaceRegexp = `^type\s+([A-Z]\w*)\s+interface\s*{` 25 | ) 26 | 27 | // Interface is an interface 28 | type Interface struct { 29 | Name string 30 | Package string 31 | } 32 | 33 | // Location is the location in sources 34 | type Location struct { 35 | SourceFile string 36 | LineNumber string 37 | Link string 38 | } 39 | 40 | // InterfaceList is a map of interfaces to their location 41 | type InterfaceList map[Interface]map[string]Location 42 | 43 | // NewInterfaceList builds a list of interfaces 44 | func NewInterfaceList() InterfaceList { 45 | return make(map[Interface]map[string]Location) 46 | } 47 | 48 | // AddInterface adds an interface to a list 49 | func (il InterfaceList) AddInterface(name, pkg, version, sourceFile, lineNumber string) { 50 | interf := Interface{ 51 | Name: name, 52 | Package: pkg, 53 | } 54 | link := fmt.Sprintf(sourceURL, version, sourceFile, lineNumber) 55 | location := Location{ 56 | SourceFile: sourceFile, 57 | LineNumber: lineNumber, 58 | Link: link, 59 | } 60 | if il[interf] == nil { 61 | il[interf] = make(map[string]Location) 62 | } 63 | il[interf][version] = location 64 | } 65 | 66 | // ByName is a list of interfaces 67 | type ByName []Interface 68 | 69 | // Len returns the length of the list 70 | func (b ByName) Len() int { return len(b) } 71 | 72 | // Swap swaps two interfaces 73 | func (b ByName) Swap(i, j int) { b[i], b[j] = b[j], b[i] } 74 | 75 | // Less tells if i is less than j 76 | func (b ByName) Less(i, j int) bool { return b[i].Name < b[j].Name } 77 | 78 | // srcDirUrl returns the URL of source directory 79 | func srcDirURL(v string) (string, string) { 80 | array := strings.Split(strings.Split(strings.Split(v, "beta")[0], "rc")[0], ".") 81 | major, err := strconv.Atoi(array[0]) 82 | if err != nil { 83 | major = 0 84 | } 85 | minor, err := strconv.Atoi(array[1]) 86 | if err != nil { 87 | minor = 0 88 | } 89 | srcDir := "" 90 | srcURL := "" 91 | if major <= 1 && minor < 4 { 92 | srcDir = oldSrcDir 93 | } else { 94 | srcDir = newSrcDir 95 | } 96 | if major <= 1 && minor < 2 { 97 | srcURL = oldSrcURL 98 | } else { 99 | srcURL = newSrcURL 100 | } 101 | return srcDir, srcURL 102 | } 103 | 104 | // parseSourceFile parses a source file and populates the interface list 105 | func parseSourceFile(filename string, source io.Reader, sourceDir string, version string, interfaces InterfaceList) { 106 | regexpInterface := regexp.MustCompile(interfaceRegexp) 107 | reader := bufio.NewReader(source) 108 | pack := filename[len(sourceDir)+4 : strings.LastIndex(filename, "/")] 109 | if strings.HasSuffix(pack, "testdata") || strings.HasPrefix(pack, "cmd") || 110 | strings.HasPrefix(pack, "vendor") || strings.HasPrefix(pack, "internal") { 111 | return 112 | } 113 | lineNumber := 1 114 | for { 115 | line, err := reader.ReadBytes('\n') 116 | if err != nil && err != io.EOF { 117 | panic("Error parsing source file") 118 | } 119 | matches := regexpInterface.FindSubmatch(line) 120 | if len(matches) > 0 { 121 | name := string(matches[1]) 122 | pkg := string(pack) 123 | sourceFile := filename[3:] 124 | lineNumber := strconv.Itoa(lineNumber) 125 | interfaces.AddInterface(name, pkg, version, sourceFile, lineNumber) 126 | } 127 | if err == io.EOF { 128 | break 129 | } 130 | lineNumber++ 131 | } 132 | } 133 | 134 | // addInterfaces generates interface list for given version 135 | func addInterfaces(version string, interfaces InterfaceList) { 136 | println(fmt.Sprintf("Generating interface list for version %s...", version)) 137 | srcDir, srcURL := srcDirURL(version) 138 | // download compressed archive 139 | response, err := http.Get(srcURL + "go" + version + ".src.tar.gz") 140 | if err != nil { 141 | panic(err) 142 | } 143 | reader := response.Body 144 | defer response.Body.Close() 145 | // gunzip the archive stream 146 | gzipReader, err := gzip.NewReader(reader) 147 | if err != nil { 148 | panic(err) 149 | } 150 | // parse tar source files in source dir 151 | tarReader := tar.NewReader(gzipReader) 152 | for { 153 | header, err := tarReader.Next() 154 | if err != nil { 155 | break 156 | } 157 | if strings.HasPrefix(header.Name, "go/"+srcDir) && 158 | strings.HasSuffix(header.Name, ".go") && 159 | !strings.HasSuffix(header.Name, "doc.go") && 160 | !strings.HasSuffix(header.Name, "_test.go") { 161 | parseSourceFile(header.Name, tarReader, srcDir, version, interfaces) 162 | } 163 | } 164 | } 165 | 166 | // printInterfaces prints interfaces for given versions 167 | func printInterfaces(interfaceList InterfaceList, versions []string) { 168 | interfaces := make([]Interface, 0) 169 | for i := range interfaceList { 170 | interfaces = append(interfaces, i) 171 | } 172 | sort.Sort(ByName(interfaces)) 173 | lenName := 0 174 | lenPackage := 0 175 | lenVersions := make(map[string]int) 176 | for _, i := range interfaces { 177 | if len(i.Name) > lenName { 178 | lenName = len(i.Name) 179 | } 180 | if len(i.Package) > lenPackage { 181 | lenPackage = len(i.Package) 182 | } 183 | for _, version := range versions { 184 | loc := interfaceList[i][version] 185 | lenVersion := len(loc.Link) + 10 186 | if lenVersions[version] < lenVersion { 187 | lenVersions[version] = lenVersion 188 | } 189 | } 190 | } 191 | formatLine := "%-" + strconv.Itoa(lenName) + "s" + " | %-" + strconv.Itoa(lenPackage) + "s" 192 | for _, v := range versions { 193 | formatLine += " | %-" + strconv.Itoa(lenVersions[v]) + "s" 194 | } 195 | args := []interface{}{"Interface", "Package"} 196 | for _, v := range versions { 197 | args = append(args, v) 198 | } 199 | fmt.Println(fmt.Sprintf(formatLine, args...)) 200 | separator := ":" + strings.Repeat("-", lenName-1) + " | :" + strings.Repeat("-", lenPackage-1) 201 | for _, v := range versions { 202 | separator += " | " + strings.Repeat("-", lenVersions[v]) 203 | } 204 | fmt.Println(separator) 205 | for _, i := range interfaces { 206 | versionLink := make(map[string]string) 207 | for _, v := range versions { 208 | if len(interfaceList[i][v].SourceFile) > 0 { 209 | versionLink[v] = "[source](" + interfaceList[i][v].Link + ")" 210 | } else { 211 | versionLink[v] = "-" 212 | } 213 | } 214 | args := []interface{}{i.Name, i.Package} 215 | for _, v := range versions { 216 | args = append(args, versionLink[v]) 217 | } 218 | fmt.Println(fmt.Sprintf(formatLine, args...)) 219 | } 220 | } 221 | 222 | // main is the program entry point 223 | func main() { 224 | // read versions on command line 225 | if len(os.Args) < 2 { 226 | panic("Must pass go version(s) on command line") 227 | } 228 | versions := os.Args[1:] 229 | // iterate on versions 230 | interfaces := NewInterfaceList() 231 | for _, version := range versions { 232 | addInterfaces(version, interfaces) 233 | } 234 | // print the result 235 | println("Printing table...") 236 | printInterfaces(interfaces, versions) 237 | } 238 | --------------------------------------------------------------------------------