├── .air.toml ├── .data └── demo.gif ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .vscode └── settings.json ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── asset └── asset.go ├── controller ├── asset.go ├── controller.go └── image.go ├── entrypoint.sh ├── go.mod ├── go.sum ├── log └── log.go ├── main.go ├── router └── router.go ├── runner.conf ├── schedule └── schedule.go ├── service ├── image.go └── service.go ├── util ├── context.go └── string.go └── web ├── .gitignore ├── README.md ├── package.json ├── public ├── favicon.ico ├── index.html └── manifest.json ├── src ├── App.css ├── App.js ├── App.test.js ├── FileTree.css ├── FileTree.js ├── FileTypeProportion.js ├── LOGO.zip ├── image.js ├── index.css ├── index.js ├── logo.png ├── serviceWorker.js └── util.js └── yarn.lock /.air.toml: -------------------------------------------------------------------------------- 1 | # Config file for [Air](https://github.com/cosmtrek/air) in TOML format 2 | 3 | # Working directory 4 | # . or absolute path, please note that the directories following must be under root. 5 | root = "." 6 | tmp_dir = "tmp" 7 | 8 | [build] 9 | # Just plain old shell command. You could use `make` as well. 10 | cmd = "go build -tags=swagger -o ./tmp/main ." 11 | # Binary file yields from `cmd`. 12 | bin = "tmp/main" 13 | # Customize binary. 14 | full_bin = "GO_ENV=dev ./tmp/main" 15 | # Watch these filename extensions. 16 | include_ext = ["go", "yml"] 17 | # Ignore these filename extensions or directories. 18 | exclude_dir = ["assets", "tmp", "vendor", "web"] 19 | # Watch these directories if you specified. 20 | include_dir = [] 21 | # Exclude files. 22 | exclude_file = [] 23 | # Exclude unchanged files. 24 | exclude_unchanged = true 25 | # This log file places in your tmp_dir. 26 | log = "air.log" 27 | # It's not necessary to trigger build each time file changes if it's too frequent. 28 | delay = 1000 # ms 29 | # Stop running old binary when build errors occur. 30 | stop_on_error = true 31 | # Send Interrupt signal before killing process (windows does not support this feature) 32 | send_interrupt = true 33 | # Delay after sending Interrupt signal 34 | kill_delay = 500 # ms 35 | 36 | [log] 37 | # Show log time 38 | time = false 39 | 40 | [color] 41 | # Customize each part's color. If no color found, use the raw app log. 42 | main = "magenta" 43 | watcher = "cyan" 44 | build = "yellow" 45 | runner = "green" 46 | 47 | [misc] 48 | # Delete tmp directory on exit 49 | clean_on_exit = true -------------------------------------------------------------------------------- /.data/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicanso/diving/e419563b7f0fb31f86a573b8f840808eb920603f/.data/demo.gif -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build on tag 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | docker: 11 | runs-on: ubuntu-latest 12 | name: Build 13 | steps: 14 | - name: Check out code into the Go module directory 15 | uses: actions/checkout@v2 16 | - name: Set output 17 | id: vars 18 | run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} 19 | - name: Set up QEMU 20 | uses: docker/setup-qemu-action@v2 21 | - name: Set up Docker Buildx 22 | uses: docker/setup-buildx-action@v2 23 | - name: Login to Docker Hub 24 | uses: docker/login-action@v2 25 | with: 26 | username: ${{ secrets.DOCKER_HUB_USERNAME }} 27 | password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} 28 | - name: Build and push 29 | id: docker_build 30 | uses: docker/build-push-action@v3 31 | with: 32 | platforms: linux/amd64, linux/arm64 33 | push: true 34 | tags: ${{ secrets.DOCKER_HUB_USERNAME }}/diving 35 | - name: Image digest 36 | run: echo ${{ steps.docker_build.outputs.digest }} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | 3 | vendor 4 | tmp 5 | tmp/* 6 | *.out 7 | *.log 8 | diving 9 | asset/dist 10 | 11 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 12 | 13 | # dependencies 14 | web/node_modules 15 | web/.pnp 16 | .pnp.js 17 | 18 | # testing 19 | web/coverage 20 | 21 | # production 22 | web/build 23 | 24 | # misc 25 | .DS_Store 26 | .env.local 27 | .env.development.local 28 | .env.test.local 29 | .env.production.local 30 | 31 | npm-debug.log* 32 | yarn-debug.log* 33 | yarn-error.log* -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "go.formatTool": "goimports" 3 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:18-alpine as webbuilder 2 | 3 | ADD ./ /diving 4 | 5 | ENV NODE_OPTIONS=--openssl-legacy-provider 6 | 7 | RUN cd /diving/web \ 8 | && npm i \ 9 | && npm run build \ 10 | && rm -rf node_module 11 | 12 | FROM golang:1.18-alpine as builder 13 | 14 | COPY --from=webbuilder /diving /diving 15 | 16 | RUN apk update \ 17 | && apk add docker git gcc make \ 18 | && cd /diving \ 19 | && rm -rf asset/dist \ 20 | && cp -rf web/build asset/dist \ 21 | && make build 22 | 23 | FROM alpine 24 | 25 | EXPOSE 7001 26 | 27 | COPY --from=builder /usr/bin/docker /usr/bin/docker 28 | COPY --from=builder /diving/diving /usr/local/bin/diving 29 | COPY --from=builder /diving/entrypoint.sh /entrypoint.sh 30 | 31 | CMD ["diving"] 32 | 33 | ENTRYPOINT ["/entrypoint.sh"] 34 | 35 | HEALTHCHECK --interval=10s --timeout=3s \ 36 | CMD diving --mode=check || exit 1 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | export GO111MODULE = on 2 | 3 | .PHONY: default test test-cover dev build 4 | 5 | # for dev 6 | dev: 7 | air -c .air.toml 8 | 9 | # for test 10 | test: 11 | go test -race -cover ./... 12 | 13 | test-cover: 14 | go test -race -coverprofile=test.out ./... && go tool cover --html=test.out 15 | 16 | build-web: 17 | cd web \ 18 | && npm run build 19 | 20 | list-mod: 21 | go list -m -u all 22 | 23 | bench: 24 | go test -bench=. ./... 25 | 26 | build: 27 | go build -tags netgo -o diving 28 | 29 | release: 30 | go mod tidy 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # This repo is archived, please use [diving-rs](https://github.com/vicanso/diving-rs) instead of it. It is fast and simple, develop with Rust. 3 | 4 | # diving 5 | 6 | Using diving you can analyze docker image on the website. It use [dive](https://github.com/wagoodman/dive) to get the analyzed information. 7 | 8 | 9 | The first time may be slow, because it pulls the image first. 10 | 11 | ![Image](.data/demo.gif) 12 | 13 | 14 | ## Installation 15 | 16 | ``` 17 | docker run -d --restart=always \ 18 | -v /var/run/docker.sock:/var/run/docker.sock \ 19 | -p 7001:7001 \ 20 | vicanso/diving 21 | ``` 22 | -------------------------------------------------------------------------------- /asset/asset.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 tree xie 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // 静态态文件打包 16 | 17 | package asset 18 | 19 | import ( 20 | "embed" 21 | ) 22 | 23 | //go:embed * 24 | var assetFS embed.FS 25 | 26 | // GetFS get asset embed fs 27 | func GetFS() embed.FS { 28 | return assetFS 29 | } 30 | -------------------------------------------------------------------------------- /controller/asset.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/vicanso/diving/asset" 7 | "github.com/vicanso/diving/router" 8 | "github.com/vicanso/elton" 9 | "github.com/vicanso/elton/middleware" 10 | ) 11 | 12 | // assetCtrl asset ctrl 13 | type assetCtrl struct{} 14 | 15 | var assetFS = middleware.NewEmbedStaticFS(asset.GetFS(), "dist") 16 | 17 | func init() { 18 | g := router.NewGroup("") 19 | ctrl := assetCtrl{} 20 | g.GET("/", ctrl.index) 21 | g.GET("/favicon.ico", ctrl.favIcon) 22 | 23 | g.GET("/static/*", middleware.NewStaticServe(assetFS, middleware.StaticServeConfig{ 24 | Path: "/static", 25 | // 客户端缓存一年 26 | MaxAge: 365 * 24 * time.Hour, 27 | // 缓存服务器缓存一个小时 28 | SMaxAge: time.Hour, 29 | DenyQueryString: true, 30 | DisableLastModified: true, 31 | })) 32 | } 33 | 34 | func (ctrl assetCtrl) index(c *elton.Context) (err error) { 35 | err = assetFS.SendFile(c, "index.html") 36 | if err != nil { 37 | return 38 | } 39 | c.CacheMaxAge(10 * time.Second) 40 | return 41 | } 42 | 43 | func (ctrl assetCtrl) favIcon(c *elton.Context) (err error) { 44 | err = assetFS.SendFile(c, "favicon.ico") 45 | if err != nil { 46 | return 47 | } 48 | c.CacheMaxAge(10 * time.Minute) 49 | return 50 | } 51 | -------------------------------------------------------------------------------- /controller/controller.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | "github.com/vicanso/elton" 8 | "github.com/vicanso/elton/middleware" 9 | "github.com/vicanso/hes" 10 | lruttl "github.com/vicanso/lru-ttl" 11 | ) 12 | 13 | var ( 14 | errQueryNotAllow = hes.New("query is not allowed") 15 | ) 16 | 17 | type cacheStore struct { 18 | lru *lruttl.Cache 19 | } 20 | 21 | func (c *cacheStore) Get(ctx context.Context, key string) ([]byte, error) { 22 | value, ok := c.lru.Get(key) 23 | if !ok { 24 | return nil, nil 25 | } 26 | buf, _ := value.([]byte) 27 | return buf, nil 28 | } 29 | 30 | func (c *cacheStore) Set(ctx context.Context, key string, data []byte, ttl time.Duration) error { 31 | c.lru.Add(key, data, ttl) 32 | return nil 33 | } 34 | 35 | var httpCache = middleware.NewCache(middleware.CacheConfig{ 36 | Store: &cacheStore{ 37 | lru: lruttl.New(100, 5*time.Minute), 38 | }, 39 | }) 40 | 41 | // noQuery not allow any query string 42 | func noQuery(c *elton.Context) (err error) { 43 | if c.Request.URL.RawQuery != "" { 44 | err = errQueryNotAllow 45 | return 46 | } 47 | return c.Next() 48 | } 49 | -------------------------------------------------------------------------------- /controller/image.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "context" 5 | "net/http" 6 | "strconv" 7 | "time" 8 | 9 | "github.com/vicanso/diving/log" 10 | "github.com/vicanso/diving/router" 11 | "github.com/vicanso/diving/service" 12 | "github.com/vicanso/elton" 13 | "github.com/vicanso/hes" 14 | lruttl "github.com/vicanso/lru-ttl" 15 | ) 16 | 17 | var ( 18 | // imageInfoCache image basic info 19 | imageInfoCache *lruttl.Cache 20 | ) 21 | 22 | const ( 23 | analysisDoing = iota 24 | analysisFail 25 | analysisDone 26 | ) 27 | 28 | // imageCtrl image ctrl 29 | type imageCtrl struct{} 30 | type ( 31 | imageInfo struct { 32 | // CreatedAt create time 33 | CreatedAt int64 `json:"createdAt,omitempty"` 34 | // Status status 35 | Status int `json:"status,omitempty"` 36 | // Err error 37 | Err error `json:"err,omitempty"` 38 | // TimeConsuming time consuming 39 | TimeConsuming time.Duration `json:"timeConsuming,omitempty"` 40 | // Analysis image analysis information 41 | Analysis *service.ImageAnalysis `json:"-"` 42 | } 43 | ) 44 | 45 | func init() { 46 | imageInfoCache = lruttl.New(32, 30*time.Minute) 47 | g := router.NewAPIGroup("/images") 48 | ctrl := imageCtrl{} 49 | 50 | g.GET( 51 | "/tree/*", 52 | httpCache, 53 | ctrl.getTree, 54 | ) 55 | 56 | g.GET("/detail/*", ctrl.getBasicInfo) 57 | 58 | g.GET("/caches", ctrl.getCacheList) 59 | } 60 | 61 | func doAnalyze(name string) { 62 | startedAt := time.Now() 63 | analysis, err := service.Analyze(name) 64 | if err != nil { 65 | imageInfoCache.Add(name, &imageInfo{ 66 | CreatedAt: startedAt.Unix(), 67 | Status: analysisFail, 68 | Err: err, 69 | TimeConsuming: time.Since(startedAt), 70 | }) 71 | log.Error(context.Background()). 72 | Str("name", name). 73 | Err(err). 74 | Msg("analyze fail") 75 | return 76 | } 77 | imageInfoCache.Add(name, &imageInfo{ 78 | CreatedAt: startedAt.Unix(), 79 | Status: analysisDone, 80 | Analysis: analysis, 81 | TimeConsuming: time.Since(startedAt), 82 | }) 83 | } 84 | 85 | // getBasicInfo get basic info of image 86 | func (ctrl imageCtrl) getBasicInfo(c *elton.Context) (err error) { 87 | name := c.Param("*") 88 | var info *imageInfo 89 | v, ok := imageInfoCache.Get(name) 90 | if ok { 91 | info = v.(*imageInfo) 92 | } 93 | if info == nil { 94 | info = &imageInfo{ 95 | CreatedAt: time.Now().Unix(), 96 | Status: analysisDoing, 97 | } 98 | imageInfoCache.Add(name, info) 99 | go doAnalyze(name) 100 | } 101 | // 如果正在处理中,则直接返回 102 | if info.Status == analysisDoing { 103 | c.StatusCode = http.StatusAccepted 104 | return 105 | } 106 | if info.Status == analysisFail { 107 | err = hes.NewWithError(info.Err) 108 | return 109 | } 110 | if !service.IsDev() { 111 | c.CacheMaxAge(5 * time.Minute) 112 | } 113 | c.Body = info.Analysis 114 | return 115 | } 116 | 117 | func (ctrl imageCtrl) getTree(c *elton.Context) (err error) { 118 | layer := c.QueryParam("layer") 119 | if layer == "" { 120 | err = hes.New("layer can not be null") 121 | return 122 | } 123 | index, e := strconv.Atoi(layer) 124 | if e != nil { 125 | err = hes.NewWithErrorStatusCode(e, http.StatusBadRequest) 126 | return 127 | } 128 | 129 | name := c.Param("*") 130 | v, ok := imageInfoCache.Get(name) 131 | if !ok { 132 | err = hes.New("can not get tree of image") 133 | return 134 | } 135 | info := v.(*imageInfo) 136 | if info.Err != nil { 137 | err = info.Err 138 | return 139 | } 140 | if info.Status != analysisDone { 141 | err = hes.New("the image is analysising, please wait for a moment") 142 | return 143 | } 144 | if index >= len(info.Analysis.LayerAnalysisList) { 145 | err = hes.New("the layer index is too big") 146 | return 147 | } 148 | result, err := service.GetFileAnalysis(info.Analysis, index) 149 | if err != nil { 150 | return 151 | } 152 | c.CacheMaxAge(5 * time.Minute) 153 | c.Body = result 154 | return 155 | } 156 | 157 | // getCacheList get cache list 158 | func (ctrl imageCtrl) getCacheList(c *elton.Context) (err error) { 159 | keys := imageInfoCache.Keys() 160 | result := make(map[string]*imageInfo) 161 | for _, key := range keys { 162 | v, ok := imageInfoCache.Get(key) 163 | if ok { 164 | info := v.(*imageInfo) 165 | result[key.(string)] = info 166 | } 167 | } 168 | c.Body = result 169 | return 170 | } 171 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | if [ "${1:0:1}" = '-' ]; then 5 | set -- diving "$@" 6 | fi 7 | 8 | exec "$@" -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/vicanso/diving 2 | 3 | go 1.18 4 | 5 | // related to an invalid pseudo version in github.com/docker/distribution@v0.0.0-20181126153310-93e082742a009850ac46962150b2f652a822c5ff 6 | replace github.com/docker/docker => github.com/docker/engine v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible 7 | 8 | require ( 9 | github.com/containerd/containerd v1.6.6 // indirect 10 | github.com/dustin/go-humanize v1.0.0 11 | github.com/robfig/cron/v3 v3.0.1 12 | github.com/rs/zerolog v1.27.0 13 | github.com/vicanso/elton v1.9.5 14 | github.com/vicanso/go-mask v1.0.0 15 | github.com/vicanso/hes v0.6.0 16 | github.com/vicanso/lru-ttl v1.5.1 17 | github.com/wagoodman/dive v0.10.0 18 | go.uber.org/automaxprocs v1.5.1 19 | golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b 20 | golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 // indirect 21 | ) 22 | 23 | require ( 24 | github.com/Microsoft/go-winio v0.5.2 // indirect 25 | github.com/andybalholm/brotli v1.0.4 // indirect 26 | github.com/awesome-gocui/gocui v1.1.0 // indirect 27 | github.com/cespare/xxhash v1.1.0 // indirect 28 | github.com/docker/cli v20.10.17+incompatible // indirect 29 | github.com/docker/distribution v2.8.1+incompatible // indirect 30 | github.com/docker/docker v20.10.17+incompatible // indirect 31 | github.com/docker/go-connections v0.4.0 // indirect 32 | github.com/docker/go-units v0.4.0 // indirect 33 | github.com/fatih/color v1.13.0 // indirect 34 | github.com/gdamore/encoding v1.0.0 // indirect 35 | github.com/gdamore/tcell/v2 v2.5.2 // indirect 36 | github.com/gogo/protobuf v1.3.2 // indirect 37 | github.com/golang/protobuf v1.5.2 // indirect 38 | github.com/google/uuid v1.3.0 // indirect 39 | github.com/gorilla/mux v1.7.3 // indirect 40 | github.com/hashicorp/golang-lru v0.5.4 // indirect 41 | github.com/logrusorgru/aurora v2.0.3+incompatible // indirect 42 | github.com/lucasb-eyer/go-colorful v1.2.0 // indirect 43 | github.com/mattn/go-colorable v0.1.12 // indirect 44 | github.com/mattn/go-isatty v0.0.14 // indirect 45 | github.com/mattn/go-runewidth v0.0.13 // indirect 46 | github.com/opencontainers/go-digest v1.0.0 // indirect 47 | github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect 48 | github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee // indirect 49 | github.com/pkg/errors v0.9.1 // indirect 50 | github.com/rivo/uniseg v0.3.1 // indirect 51 | github.com/sirupsen/logrus v1.9.0 // indirect 52 | github.com/tidwall/gjson v1.14.1 // indirect 53 | github.com/tidwall/match v1.1.1 // indirect 54 | github.com/tidwall/pretty v1.2.0 // indirect 55 | github.com/vicanso/intranet-ip v0.1.0 // indirect 56 | github.com/vicanso/keygrip v1.2.1 // indirect 57 | golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect 58 | golang.org/x/text v0.3.7 // indirect 59 | google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f // indirect 60 | google.golang.org/grpc v1.48.0 // indirect 61 | google.golang.org/protobuf v1.28.1 // indirect 62 | ) 63 | -------------------------------------------------------------------------------- /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 | github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= 4 | github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= 5 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 6 | github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= 7 | github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= 8 | github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= 9 | github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= 10 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 11 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 12 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 13 | github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= 14 | github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= 15 | github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= 16 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 17 | github.com/awesome-gocui/gocui v0.5.0/go.mod h1:1QikxFaPhe2frKeKvEwZEIGia3haiOxOUXKinrv17mA= 18 | github.com/awesome-gocui/gocui v0.6.0/go.mod h1:1QikxFaPhe2frKeKvEwZEIGia3haiOxOUXKinrv17mA= 19 | github.com/awesome-gocui/gocui v1.1.0 h1:db2j7yFEoHZjpQFeE2xqiatS8bm1lO3THeLwE6MzOII= 20 | github.com/awesome-gocui/gocui v1.1.0/go.mod h1:M2BXkrp7PR97CKnPRT7Rk0+rtswChPtksw/vRAESGpg= 21 | github.com/awesome-gocui/keybinding v1.0.0/go.mod h1:z0TyCwIhaT97yU+becTse8Dqh2CvYT0FLw0R0uTk0ag= 22 | github.com/awesome-gocui/termbox-go v0.0.0-20190427202837-c0aef3d18bcc/go.mod h1:tOy3o5Nf1bA17mnK4W41gD7PS3u4Cv0P0pqFcoWMy8s= 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/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= 26 | github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= 27 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 28 | github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 29 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 30 | github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= 31 | github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= 32 | github.com/cncf/udpa/go v0.0.0-20210930031921-04548b0d99d4/go.mod h1:6pvJx4me5XPnfI9Z40ddWsdw2W/uZgQLFXToKeRcDiI= 33 | github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= 34 | github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= 35 | github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs= 36 | github.com/containerd/containerd v1.6.6 h1:xJNPhbrmz8xAMDNoVjHy9YHtWwEQNS+CDkcIRh7t8Y0= 37 | github.com/containerd/containerd v1.6.6/go.mod h1:ZoP1geJldzCVY3Tonoz7b1IXk8rIX0Nltt5QE4OMNk0= 38 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 39 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 40 | github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= 41 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 42 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 43 | github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= 44 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 45 | github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= 46 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 47 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 48 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 49 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 50 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 51 | github.com/docker/cli v0.0.0-20190906153656-016a3232168d/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= 52 | github.com/docker/cli v20.10.17+incompatible h1:eO2KS7ZFeov5UJeaDmIs1NFEDRf32PaqRpvoEkKBy5M= 53 | github.com/docker/cli v20.10.17+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= 54 | github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= 55 | github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= 56 | github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= 57 | github.com/docker/engine v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible h1:nnCzIfwUkdP7f5ZYf8el5qKoWSwuQxEeTcDwWHLKsKg= 58 | github.com/docker/engine v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible/go.mod h1:3CPr2caMgTHxxIAZgEMd3uLYPDlRvPqCpyeRf6ncPcY= 59 | github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= 60 | github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= 61 | github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw= 62 | github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= 63 | github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= 64 | github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= 65 | github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 66 | github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= 67 | github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= 68 | github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= 69 | github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE= 70 | github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= 71 | github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= 72 | github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w= 73 | github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= 74 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 75 | github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= 76 | github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= 77 | github.com/gdamore/tcell/v2 v2.4.0/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU= 78 | github.com/gdamore/tcell/v2 v2.5.2 h1:tKzG29kO9p2V++3oBY2W9zUjYu7IK1MENFeY/BzJSVY= 79 | github.com/gdamore/tcell/v2 v2.5.2/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo= 80 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 81 | github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= 82 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 83 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 84 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 85 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 86 | github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= 87 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 88 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 89 | github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= 90 | github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= 91 | github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= 92 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 93 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 94 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 95 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 96 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 97 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 98 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 99 | github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= 100 | github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= 101 | github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= 102 | github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= 103 | github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= 104 | github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= 105 | github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 106 | github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= 107 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 108 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 109 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 110 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 111 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 112 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 113 | github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 114 | github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 115 | github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 116 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 117 | github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= 118 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 119 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 120 | github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 121 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 122 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 123 | github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= 124 | github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw= 125 | github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs= 126 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 127 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 128 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 129 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 130 | github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= 131 | github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= 132 | github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= 133 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 134 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 135 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 136 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 137 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 138 | github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= 139 | github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= 140 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 141 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 142 | github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 143 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 144 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 145 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 146 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 147 | github.com/logrusorgru/aurora v0.0.0-20190803045625-94edacc10f9b/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= 148 | github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8= 149 | github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= 150 | github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 151 | github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= 152 | github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= 153 | github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI= 154 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 155 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 156 | github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= 157 | github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 158 | github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= 159 | github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= 160 | github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= 161 | github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= 162 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 163 | github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= 164 | github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= 165 | github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= 166 | github.com/mattn/go-runewidth v0.0.10/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= 167 | github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= 168 | github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= 169 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 170 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 171 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 172 | github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= 173 | github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= 174 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 175 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 176 | github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= 177 | github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= 178 | github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= 179 | github.com/opencontainers/image-spec v1.0.1/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= 180 | github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 h1:rc3tiVYb5z54aKaDfakKn0dDjIyPpTtszkjuMzyt7ec= 181 | github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0= 182 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 183 | github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo= 184 | github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee h1:P6U24L02WMfj9ymZTxl7CxS73JC99x3ukk+DBkgQGQs= 185 | github.com/phayes/permbits v0.0.0-20190612203442-39d7c581d2ee/go.mod h1:3uODdxMgOaPYeWU7RzZLxVtJHZ/x1f/iHkBZuKJDzuY= 186 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 187 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 188 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 189 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 190 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 191 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 192 | github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= 193 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 194 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 195 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 196 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 197 | github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 198 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 199 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 200 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 201 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 202 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 203 | github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 204 | github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= 205 | github.com/rivo/uniseg v0.3.1 h1:SDPP7SHNl1L7KrEFCSJslJ/DM9DT02Nq2C61XrfHMmk= 206 | github.com/rivo/uniseg v0.3.1/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= 207 | github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= 208 | github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= 209 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 210 | github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= 211 | github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= 212 | github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs= 213 | github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U= 214 | github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= 215 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= 216 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 217 | github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= 218 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= 219 | github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= 220 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 221 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 222 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 223 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= 224 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 225 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 226 | github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk= 227 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 228 | github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU= 229 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 230 | github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= 231 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 232 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 233 | github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s= 234 | github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= 235 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 236 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 237 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 238 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 239 | github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= 240 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 241 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 242 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 243 | github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= 244 | github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= 245 | github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= 246 | github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= 247 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= 248 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= 249 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= 250 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 251 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 252 | github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= 253 | github.com/vicanso/elton v1.9.5 h1:vWCota4myz2BXT40RqbxMZlSTTvxiSPR06rJ/VWXEqQ= 254 | github.com/vicanso/elton v1.9.5/go.mod h1:KIEn5zohLKfKo3d/Rlww5j2/jbOXDdNlO/UTwxrc+wk= 255 | github.com/vicanso/go-mask v1.0.0 h1:ydxDGuc63JLJuBRDhF49s7gG/a4DRdmJjdwrBSiGCwM= 256 | github.com/vicanso/go-mask v1.0.0/go.mod h1:LvZ98VripV5UP3XTBYyPnfnFYrvqE+yCOrfV8JmRtfI= 257 | github.com/vicanso/hes v0.6.0 h1:rmLhJw1PkZ+BTlJXt91i12mr7vpIC65S5KRCD4uF9HU= 258 | github.com/vicanso/hes v0.6.0/go.mod h1:bO1pAVgzuwBJAv76LXx8YN6jXLWcCYVyNx4qzPw9h6Y= 259 | github.com/vicanso/intranet-ip v0.1.0 h1:UeoxilO2VDIkeZZxmu6aT+f5o79mfGdsSdwoEv75nYo= 260 | github.com/vicanso/intranet-ip v0.1.0/go.mod h1:N1yrHdDYWNsOs5V374DuAJHba+d2dxUDcjVALgIlfOg= 261 | github.com/vicanso/keygrip v1.2.1 h1:876fXDwGJqxdi4JxZ1lNGBxYswyLZotrs7AA2QWcLeY= 262 | github.com/vicanso/keygrip v1.2.1/go.mod h1:tfB5az1yqold78zotkzNugk3sV+QW5m71CFz3zg9eeo= 263 | github.com/vicanso/lru-ttl v1.5.1 h1:+3cgI8NOPKAs2FA8XIB9sPvZ3c2I8b+iP5oy5sx/x5A= 264 | github.com/vicanso/lru-ttl v1.5.1/go.mod h1:mIJqi+LqGF9H1BI0bdiqUV7W9R9XMz3NjDt8LvdF3hg= 265 | github.com/wagoodman/dive v0.10.0 h1:JaitQBVwmfZD5mvLkBHk1LUq6jwsjvnNS6mgIl7YNZQ= 266 | github.com/wagoodman/dive v0.10.0/go.mod h1:8IDxfzmg3+5DQwK6/sGyMpJr95ejuv511+rF9CTNYdQ= 267 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 268 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 269 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 270 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 271 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 272 | go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= 273 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 274 | go.uber.org/automaxprocs v1.5.1 h1:e1YG66Lrk73dn4qhg8WFSvhF0JuFQF0ERIp4rpuV8Qk= 275 | go.uber.org/automaxprocs v1.5.1/go.mod h1:BF4eumQw0P9GtnuxxovUd06vwm1o18oMzFtK66vU6XU= 276 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 277 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 278 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 279 | golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 280 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 281 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 282 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 283 | golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= 284 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 285 | golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= 286 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 287 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 288 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 289 | golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 290 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 291 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 292 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 293 | golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 294 | golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 295 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 296 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 297 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 298 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 299 | golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 300 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 301 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 302 | golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= 303 | golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b h1:3ogNYyK4oIQdIKzTu68hQrr4iuVxF3AxKl9Aj/eDrw0= 304 | golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= 305 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 306 | golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= 307 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 308 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 309 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 310 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 311 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 312 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 313 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 314 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 315 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 316 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 317 | golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 318 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 319 | golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 320 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 321 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 322 | golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 323 | golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 324 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 325 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 326 | golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 327 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 328 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 329 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 330 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 331 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 332 | golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 333 | golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 334 | golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 335 | golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 336 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 337 | golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 h1:Y7NOhdqIOU8kYI7BxsgL38d0ot0raxvcW+EMQU2QrT4= 338 | golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 339 | golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 340 | golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 h1:Q5284mrmYTpACcm+eAKjKJH48BBwSyfJqmmGDTtT8Vc= 341 | golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 342 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 343 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 344 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 345 | golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= 346 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 347 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 348 | golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs= 349 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 350 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 351 | golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 352 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 353 | golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= 354 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 355 | golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= 356 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 357 | golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 358 | golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= 359 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 360 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 361 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 362 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 363 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 364 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 365 | google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= 366 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 367 | google.golang.org/genproto v0.0.0-20190620144150-6af8c5fc6601/go.mod h1:z3L6/3dTEVtUr6QSP8miRzeRqwQOioJ9I66odjN4I7s= 368 | google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= 369 | google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= 370 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= 371 | google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f h1:ywoA0TLvF/4n7P2lr/+bNRueYxWYUJZbRwV3hyYt8gY= 372 | google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc= 373 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 374 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 375 | google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 376 | google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= 377 | google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= 378 | google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= 379 | google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= 380 | google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= 381 | google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w= 382 | google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk= 383 | google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= 384 | google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= 385 | google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= 386 | google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= 387 | google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= 388 | google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 389 | google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 390 | google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= 391 | google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= 392 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 393 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 394 | google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 395 | google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= 396 | google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 397 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 398 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 399 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 400 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 401 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 402 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 403 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 404 | gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 405 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 406 | gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 407 | gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 408 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 409 | gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= 410 | gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= 411 | gotest.tools/v3 v3.0.3 h1:4AuOwCGf4lLR9u3YOe2awrHygurzhO/HeQ6laiA6Sx0= 412 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 413 | honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 414 | -------------------------------------------------------------------------------- /log/log.go: -------------------------------------------------------------------------------- 1 | package log 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/url" 7 | "os" 8 | "regexp" 9 | "strconv" 10 | 11 | "github.com/rs/zerolog" 12 | "github.com/vicanso/diving/util" 13 | mask "github.com/vicanso/go-mask" 14 | ) 15 | 16 | var enabledDebugLog = false 17 | var defaultLogger = newLogger() 18 | 19 | // 日志中值的最大长度 20 | var logFieldValueMaxSize = 30 21 | var logMask = mask.New( 22 | mask.RegExpOption(regexp.MustCompile(`(?i)password`)), 23 | mask.MaxLengthOption(logFieldValueMaxSize), 24 | mask.NotMaskRegExpOption(regexp.MustCompile(`stack`)), 25 | ) 26 | 27 | type httpServerLogger struct{} 28 | 29 | func (hsl *httpServerLogger) Write(p []byte) (int, error) { 30 | Info(context.Background()). 31 | Str("category", "httpServerLogger"). 32 | Msg(string(p)) 33 | return len(p), nil 34 | } 35 | 36 | type redisLogger struct{} 37 | 38 | func (rl *redisLogger) Printf(ctx context.Context, format string, v ...interface{}) { 39 | Info(context.Background()). 40 | Str("category", "redisLogger"). 41 | Msg(fmt.Sprintf(format, v...)) 42 | } 43 | 44 | type entLogger struct{} 45 | 46 | func (el *entLogger) Log(args ...interface{}) { 47 | Info(context.Background()). 48 | Msg(fmt.Sprint(args...)) 49 | } 50 | 51 | // DebugEnabled 是否启用了debug日志 52 | func DebugEnabled() bool { 53 | return enabledDebugLog 54 | } 55 | 56 | // newLogger 初始化logger 57 | func newLogger() *zerolog.Logger { 58 | // 全局禁用sampling 59 | zerolog.DisableSampling(true) 60 | // 如果要节约日志空间,可以配置 61 | zerolog.TimestampFieldName = "t" 62 | zerolog.LevelFieldName = "l" 63 | zerolog.TimeFieldFormat = "2006-01-02T15:04:05.999Z07:00" 64 | 65 | l := zerolog.New(os.Stdout). 66 | Level(zerolog.InfoLevel). 67 | With(). 68 | Timestamp(). 69 | Logger() 70 | 71 | // 如果有配置指定日志级别,则以配置指定的输出 72 | logLevel := os.Getenv("LOG_LEVEL") 73 | if logLevel != "" { 74 | lv, _ := strconv.Atoi(logLevel) 75 | l = l.Level(zerolog.Level(lv)) 76 | if logLevel != "" && lv <= 0 { 77 | enabledDebugLog = true 78 | } 79 | } 80 | 81 | return &l 82 | } 83 | 84 | func fillTraceInfos(ctx context.Context, e *zerolog.Event) *zerolog.Event { 85 | if ctx == nil { 86 | ctx = context.Background() 87 | } 88 | return e.Str("traceID", util.GetTraceID(ctx)) 89 | } 90 | 91 | func Info(ctx context.Context) *zerolog.Event { 92 | return fillTraceInfos(ctx, defaultLogger.Info()) 93 | } 94 | 95 | func Error(ctx context.Context) *zerolog.Event { 96 | return fillTraceInfos(ctx, defaultLogger.Error()) 97 | } 98 | 99 | func Debug(ctx context.Context) *zerolog.Event { 100 | return fillTraceInfos(ctx, defaultLogger.Debug()) 101 | } 102 | 103 | func Warn(ctx context.Context) *zerolog.Event { 104 | return fillTraceInfos(ctx, defaultLogger.Warn()) 105 | } 106 | 107 | // URLValues create a url.Values log event 108 | func URLValues(query url.Values) *zerolog.Event { 109 | if len(query) == 0 { 110 | return zerolog.Dict() 111 | } 112 | return zerolog.Dict().Fields(logMask.URLValues(query)) 113 | } 114 | 115 | // Struct create a struct log event 116 | func Struct(data interface{}) *zerolog.Event { 117 | if data == nil { 118 | return zerolog.Dict() 119 | } 120 | 121 | // 转换出错忽略 122 | m, _ := logMask.Struct(data) 123 | return zerolog.Dict().Fields(m) 124 | } 125 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "flag" 6 | "fmt" 7 | "net/http" 8 | "os" 9 | "time" 10 | 11 | "golang.org/x/net/http2" 12 | "golang.org/x/net/http2/h2c" 13 | 14 | "github.com/dustin/go-humanize" 15 | _ "github.com/vicanso/diving/controller" 16 | "github.com/vicanso/diving/log" 17 | "github.com/vicanso/diving/router" 18 | _ "github.com/vicanso/diving/schedule" 19 | "github.com/vicanso/diving/util" 20 | "github.com/vicanso/elton" 21 | "github.com/vicanso/elton/middleware" 22 | maxprocs "go.uber.org/automaxprocs/maxprocs" 23 | ) 24 | 25 | var ( 26 | runMode string 27 | ) 28 | 29 | // 获取监听地址 30 | func getListen() string { 31 | listen := os.Getenv("LISTEN") 32 | if listen == "" { 33 | listen = ":7001" 34 | } 35 | return listen 36 | } 37 | 38 | func check() { 39 | listen := getListen() 40 | url := "" 41 | if listen[0] == ':' { 42 | url = "http://127.0.0.1" + listen + "/ping" 43 | } else { 44 | url = "http://" + listen + "/ping" 45 | } 46 | client := http.Client{ 47 | Timeout: 3 * time.Second, 48 | } 49 | resp, err := client.Get(url) 50 | if err != nil || resp == nil || resp.StatusCode != http.StatusOK { 51 | os.Exit(1) 52 | return 53 | } 54 | os.Exit(0) 55 | } 56 | 57 | func init() { 58 | _, _ = maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) { 59 | value := fmt.Sprintf(format, args...) 60 | log.Info(context.Background()).Msg(value) 61 | })) 62 | } 63 | 64 | func main() { 65 | 66 | flag.StringVar(&runMode, "mode", "", "running mode") 67 | flag.Parse() 68 | 69 | if runMode == "check" { 70 | check() 71 | return 72 | } 73 | listen := getListen() 74 | 75 | e := elton.New() 76 | 77 | e.OnError(func(c *elton.Context, err error) { 78 | log.Error(c.Context()). 79 | Str("uri", c.Request.RequestURI). 80 | Err(err). 81 | Msg("unexpected error") 82 | }) 83 | 84 | e.Use(middleware.NewRecover()) 85 | 86 | e.Use(middleware.NewStats(middleware.StatsConfig{ 87 | OnStats: func(statsInfo *middleware.StatsInfo, c *elton.Context) { 88 | log.Info(c.Context()). 89 | Str("ip", statsInfo.IP). 90 | Str("method", statsInfo.Method). 91 | Str("uri", statsInfo.URI). 92 | Int("status", statsInfo.Status). 93 | Str("latency", statsInfo.Latency.String()). 94 | Str("size", humanize.Bytes(uint64(statsInfo.Size))). 95 | Msg("access log") 96 | }, 97 | })) 98 | 99 | e.Use(middleware.NewDefaultError()) 100 | 101 | e.Use(func(c *elton.Context) error { 102 | ctx := util.SetTraceID(c.Context(), util.RandomString(8)) 103 | c.WithContext(ctx) 104 | c.NoCache() 105 | return c.Next() 106 | }) 107 | 108 | e.Use(middleware.NewDefaultFresh()) 109 | e.Use(middleware.NewDefaultETag()) 110 | 111 | e.Use(middleware.NewDefaultResponder()) 112 | 113 | // health check 114 | e.GET("/ping", func(c *elton.Context) (err error) { 115 | c.Body = "pong" 116 | return 117 | }) 118 | 119 | groups := router.GetGroups() 120 | for _, g := range groups { 121 | e.AddGroup(g) 122 | } 123 | 124 | // http1与http2均支持 125 | e.Server = &http.Server{ 126 | Handler: h2c.NewHandler(e, &http2.Server{}), 127 | } 128 | 129 | log.Info(context.Background()).Msg("server will listen on " + listen) 130 | err := e.ListenAndServe(listen) 131 | if err != nil { 132 | panic(err) 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /router/router.go: -------------------------------------------------------------------------------- 1 | package router 2 | 3 | import ( 4 | "github.com/vicanso/elton" 5 | ) 6 | 7 | var ( 8 | // groupList 路由组列表 9 | groupList = make([]*elton.Group, 0) 10 | ) 11 | 12 | // NewGroup new router group 13 | func NewGroup(path string, handlerList ...elton.Handler) *elton.Group { 14 | g := elton.NewGroup(path, handlerList...) 15 | groupList = append(groupList, g) 16 | return g 17 | } 18 | 19 | // NewAPIGroup new api router group 20 | func NewAPIGroup(path string, handlerList ...elton.Handler) *elton.Group { 21 | return NewGroup("/api"+path, handlerList...) 22 | } 23 | 24 | // GetGroups get groups 25 | func GetGroups() []*elton.Group { 26 | return groupList 27 | } 28 | -------------------------------------------------------------------------------- /runner.conf: -------------------------------------------------------------------------------- 1 | root: . 2 | tmp_path: ./tmp 3 | build_name: diving 4 | build_log: diving-errors.log 5 | valid_ext: .go, .tpl, .tmpl, .html 6 | no_rebuild_ext: .tpl, .tmpl, .html 7 | ignored: tmp, admin, vendor, web 8 | build_delay: 600 9 | colors: 1 10 | log_color_main: cyan 11 | log_color_build: yellow 12 | log_color_runner: green 13 | log_color_watcher: magenta -------------------------------------------------------------------------------- /schedule/schedule.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 tree xie 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | package schedule 16 | 17 | import ( 18 | "context" 19 | "time" 20 | 21 | "github.com/robfig/cron/v3" 22 | "github.com/vicanso/diving/log" 23 | "github.com/vicanso/diving/service" 24 | ) 25 | 26 | func init() { 27 | c := cron.New() 28 | 29 | _, _ = c.AddFunc("@every 1h", removeExpiredImages) 30 | 31 | c.Start() 32 | } 33 | 34 | func removeExpiredImages() { 35 | // 镜像删除,如果程序刚好重启等有可能导致镜像未删除 36 | // 服务对应的实体机有硬盘空间监控,因此问题不太大 37 | err := service.RemoveExpiredImages() 38 | startedAt := time.Now() 39 | if err != nil { 40 | log.Error(context.Background()). 41 | Err(err). 42 | Msg("remove expired images fail") 43 | return 44 | } 45 | log.Info(context.Background()). 46 | Str("use", time.Since(startedAt).String()). 47 | Msg("remove expired images done") 48 | } 49 | -------------------------------------------------------------------------------- /service/image.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "errors" 5 | "os/exec" 6 | "strconv" 7 | "strings" 8 | "sync" 9 | "time" 10 | 11 | "github.com/wagoodman/dive/dive" 12 | 13 | "github.com/wagoodman/dive/dive/filetree" 14 | ) 15 | 16 | type ( 17 | imageInfo struct { 18 | fetchedAt time.Time 19 | name string 20 | } 21 | fetchedImages struct { 22 | sync.Mutex 23 | imageInfoList []*imageInfo 24 | } 25 | // ImageAnalysis analysis for image 26 | ImageAnalysis struct { 27 | // Efficiency space efficiency of image 28 | Efficiency float64 `json:"efficiency,omitempty"` 29 | // SizeBytes size of image 30 | SizeBytes uint64 `json:"sizeBytes,omitempty"` 31 | // UserSizeBytes user size of image 32 | UserSizeBytes uint64 `json:"userSizeBytes,omitempty"` 33 | // WastedBytes wasted size of image 34 | WastedBytes uint64 `json:"wastedBytes,omitempty"` 35 | // LayerAnalysisList layer analysis list 36 | LayerAnalysisList []*LayerAnalysis `json:"layerAnalysisList,omitempty"` 37 | // InefficiencyAnalysisList inefficiency analysis list 38 | InefficiencyAnalysisList []*InefficiencyAnalysis `json:"inefficiencyAnalysisList,omitempty"` 39 | Comparer *filetree.Comparer `json:"-"` 40 | // TreeCache *filetree.TreeCache `json:"-"` 41 | } 42 | // LayerAnalysis analysis for layer 43 | LayerAnalysis struct { 44 | ID string `json:"id,omitempty"` 45 | ShortID string `json:"shortID,omitempty"` 46 | Index int `json:"index,omitempty"` 47 | Command string `json:"command,omitempty"` 48 | Size uint64 `json:"size,omitempty"` 49 | } 50 | // FileAnalysis analysis info for file 51 | FileAnalysis struct { 52 | IDS string `json:"ids,omitempty"` 53 | IsDir bool `json:"isDir,omitempty"` 54 | Size int64 `json:"size,omitempty"` 55 | LinkName string `json:"linkName,omitempty"` 56 | Mode string `json:"mode,omitempty"` 57 | // Unchanged DiffType = iota 58 | // Changed 59 | // Added 60 | // Removed 61 | DiffType filetree.DiffType `json:"diffType,omitempty"` 62 | Children map[string]*FileAnalysis `json:"children,omitempty"` 63 | } 64 | // InefficiencyAnalysis analysis for inefficiency 65 | InefficiencyAnalysis struct { 66 | Path string `json:"path,omitempty"` 67 | CumulativeSize int64 `json:"cumulativeSize,omitempty"` 68 | Count int `json:"count,omitempty"` 69 | } 70 | ) 71 | 72 | var currentFetchedImages = &fetchedImages{} 73 | 74 | // Add 添加image 75 | func (fi *fetchedImages) Add(name string) { 76 | fi.Lock() 77 | defer fi.Unlock() 78 | if len(fi.imageInfoList) == 0 { 79 | fi.imageInfoList = make([]*imageInfo, 0) 80 | } 81 | var found *imageInfo 82 | for _, item := range fi.imageInfoList { 83 | if item.name == name { 84 | found = item 85 | } 86 | } 87 | if found != nil { 88 | found.fetchedAt = time.Now() 89 | } else { 90 | fi.imageInfoList = append(fi.imageInfoList, &imageInfo{ 91 | fetchedAt: time.Now(), 92 | name: name, 93 | }) 94 | } 95 | } 96 | 97 | // ClearExpired 清除过期的镜像 98 | func (fi *fetchedImages) ClearExpired() []string { 99 | fi.Lock() 100 | defer fi.Unlock() 101 | // 一天前的镜像则删除 102 | expiredTime := time.Now().AddDate(0, 0, -1) 103 | expiredImages := make([]string, 0) 104 | infos := make([]*imageInfo, 0) 105 | for _, item := range fi.imageInfoList { 106 | if item.fetchedAt.Before(expiredTime) { 107 | expiredImages = append(expiredImages, item.name) 108 | } else { 109 | infos = append(infos, item) 110 | } 111 | } 112 | fi.imageInfoList = infos 113 | 114 | return expiredImages 115 | } 116 | 117 | // findOrCreateDir 查找目录或创建该目录 118 | func findOrCreateDir(m *FileAnalysis, pathList []string) *FileAnalysis { 119 | current := m 120 | for _, path := range pathList { 121 | // 如果该目录为空,则创建 122 | if current.Children[path] == nil { 123 | current.Children[path] = &FileAnalysis{ 124 | IsDir: true, 125 | Children: make(map[string]*FileAnalysis), 126 | } 127 | } 128 | current = current.Children[path] 129 | } 130 | return current 131 | } 132 | 133 | func analyzeFile(tree *filetree.FileTree) *FileAnalysis { 134 | 135 | topFileAnalysis := &FileAnalysis{ 136 | IsDir: true, 137 | Children: make(map[string]*FileAnalysis), 138 | } 139 | tree.VisitDepthParentFirst(func(node *filetree.FileNode) error { 140 | fileInfo := node.Data.FileInfo 141 | // 如果无目录信息,则跳过 142 | if fileInfo.Path == "" { 143 | return nil 144 | } 145 | // 拆分路径 146 | arr := strings.SplitN(fileInfo.Path, "/", -1) 147 | end := len(arr) - 1 148 | m := findOrCreateDir(topFileAnalysis, arr[:end]) 149 | ids := strconv.Itoa(fileInfo.Uid) + ":" + strconv.Itoa(fileInfo.Gid) 150 | diffType := node.Data.DiffType 151 | mode := fileInfo.Mode.String() 152 | // 如果是目录,则添加相应的属性 153 | if fileInfo.IsDir { 154 | m.Mode = mode 155 | m.IDS = ids 156 | m.DiffType = diffType 157 | return nil 158 | } 159 | // 添加子文件至目录 160 | m.Children[arr[len(arr)-1]] = &FileAnalysis{ 161 | IDS: ids, 162 | Size: fileInfo.Size, 163 | LinkName: fileInfo.Linkname, 164 | Mode: mode, 165 | DiffType: diffType, 166 | } 167 | return nil 168 | }, nil) 169 | updateDirSizeAndDiffType(topFileAnalysis) 170 | return topFileAnalysis 171 | } 172 | 173 | // updateDirSizeAndDiffType 计算目录的大小以及更新diff type 174 | func updateDirSizeAndDiffType(fileAnalysis *FileAnalysis) int64 { 175 | if !fileAnalysis.IsDir { 176 | return fileAnalysis.Size 177 | } 178 | var size int64 179 | unchangedCount := 0 180 | changedCount := 0 181 | addedCount := 0 182 | removedCount := 0 183 | for _, item := range fileAnalysis.Children { 184 | if item.IsDir { 185 | size += updateDirSizeAndDiffType(item) 186 | } else { 187 | size += item.Size 188 | } 189 | switch item.DiffType { 190 | case filetree.Modified: 191 | changedCount++ 192 | case filetree.Added: 193 | addedCount++ 194 | case filetree.Removed: 195 | removedCount++ 196 | default: 197 | unchangedCount++ 198 | } 199 | } 200 | // 如果目录的diff type 为默认值 201 | // diff type 中未处理目录新增的情况 202 | if fileAnalysis.DiffType == filetree.Unmodified { 203 | // 只有新增文件 204 | if unchangedCount == 0 && 205 | removedCount == 0 && 206 | changedCount == 0 && 207 | addedCount != 0 { 208 | fileAnalysis.DiffType = filetree.Added 209 | } 210 | } 211 | fileAnalysis.Size = size 212 | return size 213 | } 214 | 215 | // RemoveExpiredImages remove expired image 216 | func RemoveExpiredImages() (err error) { 217 | expiredImages := currentFetchedImages.ClearExpired() 218 | for _, name := range expiredImages { 219 | cmd := exec.Command("docker", "rmi", name) 220 | e := cmd.Run() 221 | if e != nil { 222 | err = e 223 | } 224 | } 225 | return 226 | } 227 | 228 | // GetFileAnalysis get file analysis 229 | func GetFileAnalysis(imgAnalysis *ImageAnalysis, index int) (*FileAnalysis, error) { 230 | 231 | // cache := imgAnalysis.TreeCache 232 | layerCount := len(imgAnalysis.LayerAnalysisList) 233 | 234 | layerIndex := layerCount - index - 1 235 | 236 | // 使用的是比较模式,只与上一层的比较 237 | bottomTreeStart := 0 238 | topTreeStop := layerIndex 239 | bottomTreeStop := layerIndex - 1 240 | topTreeStart := layerIndex 241 | 242 | tree, err := imgAnalysis.Comparer.GetTree(filetree.NewTreeIndexKey(bottomTreeStart, bottomTreeStop, topTreeStart, topTreeStop)) 243 | if err != nil { 244 | return nil, err 245 | } 246 | 247 | return analyzeFile(tree), nil 248 | } 249 | 250 | // Analyze analyze the docker images 251 | func Analyze(name string) (imgAnalysis *ImageAnalysis, err error) { 252 | resolver, err := dive.GetImageResolver(dive.SourceDockerEngine) 253 | if err != nil { 254 | return 255 | } 256 | image, err := resolver.Fetch(name) 257 | if err != nil { 258 | return 259 | } 260 | result, err := image.Analyze() 261 | if err != nil { 262 | return 263 | } 264 | 265 | // 镜像基本信息 266 | imgAnalysis = &ImageAnalysis{ 267 | Efficiency: result.Efficiency, 268 | SizeBytes: result.SizeBytes, 269 | UserSizeBytes: result.UserSizeByes, 270 | WastedBytes: result.WastedBytes, 271 | LayerAnalysisList: make([]*LayerAnalysis, len(result.Layers)), 272 | } 273 | 274 | // 分析生成低效数据(多个之间文件层覆盖) 275 | inefficiencyAnalysisList := make([]*InefficiencyAnalysis, 0, len(result.Inefficiencies)) 276 | for _, item := range result.Inefficiencies { 277 | if item.CumulativeSize == 0 { 278 | continue 279 | } 280 | inefficiencyAnalysisList = append(inefficiencyAnalysisList, &InefficiencyAnalysis{ 281 | Path: item.Path, 282 | CumulativeSize: item.CumulativeSize, 283 | Count: len(item.Nodes), 284 | }) 285 | } 286 | imgAnalysis.InefficiencyAnalysisList = inefficiencyAnalysisList 287 | 288 | comparer := filetree.NewComparer(result.RefTrees) 289 | errs := comparer.BuildCache() 290 | if len(errs) != 0 { 291 | err = errors.New(errs[0].Error()) 292 | return 293 | } 294 | imgAnalysis.Comparer = &comparer 295 | 296 | // 生成各层的相关信息 297 | max := len(result.Layers) 298 | for index, layer := range result.Layers { 299 | la := &LayerAnalysis{ 300 | ID: layer.Id, 301 | ShortID: layer.ShortId(), 302 | Index: layer.Index, 303 | Command: layer.Command, 304 | Size: layer.Size, 305 | } 306 | // 更换层的顺序 307 | imgAnalysis.LayerAnalysisList[max-index-1] = la 308 | } 309 | // 添加至当前已拉取的镜像 310 | currentFetchedImages.Add(name) 311 | return 312 | } 313 | -------------------------------------------------------------------------------- /service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "os" 5 | ) 6 | 7 | const ( 8 | // ENV go env 9 | ENV = "GO_ENV" 10 | // DEV dev env 11 | DEV = "dev" 12 | ) 13 | 14 | // IsDev is dev mode 15 | func IsDev() bool { 16 | return os.Getenv(ENV) == DEV 17 | } 18 | -------------------------------------------------------------------------------- /util/context.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "context" 5 | ) 6 | 7 | type contextKey string 8 | 9 | const ( 10 | traceIDKey contextKey = "traceID" 11 | ) 12 | 13 | func getStringFromContext(ctx context.Context, key contextKey) string { 14 | v := ctx.Value(key) 15 | if v == nil { 16 | return "" 17 | } 18 | s, _ := v.(string) 19 | return s 20 | } 21 | 22 | // SetTraceID sets trace id to context 23 | func SetTraceID(ctx context.Context, traceID string) context.Context { 24 | return context.WithValue(ctx, traceIDKey, traceID) 25 | } 26 | 27 | // GetTraceID gets trace id from context 28 | func GetTraceID(ctx context.Context) string { 29 | return getStringFromContext(ctx, traceIDKey) 30 | } 31 | -------------------------------------------------------------------------------- /util/string.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "math/rand" 5 | "time" 6 | ) 7 | 8 | // https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go 9 | const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 10 | const ( 11 | letterIdxBits = 6 // 6 bits to represent a letter index 12 | letterIdxMask = 1<= 0; { 23 | if remain == 0 { 24 | cache, remain = rand.Int63(), letterIdxMax 25 | } 26 | if idx := int(cache & letterIdxMask); idx < len(baseLetters) { 27 | b[i] = baseLetters[idx] 28 | i-- 29 | } 30 | cache >>= letterIdxBits 31 | remain-- 32 | } 33 | 34 | return string(b) 35 | } 36 | 37 | // RandomString 创建指定长度的字符串 38 | func RandomString(n int) string { 39 | return randomString(letterBytes, n) 40 | } 41 | -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /web/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | 46 | ### Code Splitting 47 | 48 | This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting 49 | 50 | ### Analyzing the Bundle Size 51 | 52 | This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size 53 | 54 | ### Making a Progressive Web App 55 | 56 | This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app 57 | 58 | ### Advanced Configuration 59 | 60 | This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration 61 | 62 | ### Deployment 63 | 64 | This section has moved here: https://facebook.github.io/create-react-app/docs/deployment 65 | 66 | ### `npm run build` fails to minify 67 | 68 | This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify 69 | -------------------------------------------------------------------------------- /web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web", 3 | "version": "0.1.0", 4 | "private": true, 5 | "proxy": "http://localhost:7001", 6 | "dependencies": { 7 | "antd": "^3.19.2", 8 | "axios": "^0.18.1", 9 | "bytes": "^3.1.0", 10 | "react": "^16.8.6", 11 | "react-dom": "^16.8.6", 12 | "react-scripts": "^3.0.1" 13 | }, 14 | "scripts": { 15 | "format": "node node_modules/.bin/prettier --write *.js */**.js", 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": [ 25 | ">0.2%", 26 | "not dead", 27 | "not ie <= 11", 28 | "not op_mini all" 29 | ], 30 | "devDependencies": { 31 | "prettier": "^1.16.4", 32 | "terser": "^3.14.1" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /web/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicanso/diving/e419563b7f0fb31f86a573b8f840808eb920603f/web/public/favicon.ico -------------------------------------------------------------------------------- /web/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 15 | 16 | 25 | 38 | diving 39 | 40 | 41 | 42 |
43 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /web/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /web/src/App.css: -------------------------------------------------------------------------------- 1 | .diving { 2 | min-height: 100vh; 3 | background-color: rgb(240, 242, 245); 4 | color: white; 5 | font-size: 14px; 6 | /* visibility: hidden; */ 7 | } 8 | 9 | .diving-cache-images { 10 | position: fixed; 11 | right: 0; 12 | bottom: 0; 13 | background-color: #fff; 14 | color: rgba(0, 0, 0, 0.65); 15 | padding: 10px; 16 | border: 1px solid #ebedf0; 17 | } 18 | 19 | .diving-header { 20 | background-color: #fff; 21 | box-shadow: 0 1px 4px rgba(0,21,41,.08); 22 | overflow: hidden; 23 | } 24 | .diving-logo { 25 | float: left; 26 | position: relative; 27 | height: 64px; 28 | padding: 0 48px 0 24px; 29 | overflow: hidden; 30 | line-height: 64px; 31 | transition: all .3s; 32 | background: #002140; 33 | } 34 | .diving-logo h1 { 35 | display: inline-block; 36 | margin: 0 0 0 12px; 37 | color: #fff; 38 | font-weight: 600; 39 | font-size: 20px; 40 | font-family: Avenir,Helvetica Neue,Arial,Helvetica,sans-serif; 41 | vertical-align: middle; 42 | } 43 | .diving-logo h1 span { 44 | margin-left: 15px; 45 | font-size: 16px; 46 | } 47 | 48 | .diving-cache-image { 49 | border-bottom: 1px solid #ebedf0; 50 | padding-bottom: 10px; 51 | margin-bottom: 10px; 52 | cursor: pointer; 53 | } 54 | .diving-cache-image:last-child { 55 | border-bottom: none; 56 | margin-bottom: 0; 57 | padding-bottom: 0; 58 | } 59 | 60 | .diving-search-wrapper { 61 | background-color: #373e5d; 62 | min-height: 70vh; 63 | } 64 | .diving-search { 65 | position: fixed; 66 | top: 50%; 67 | left: 50%; 68 | width: 610px; 69 | margin-left: -305px; 70 | margin-top: -60px; 71 | } 72 | 73 | .diving-detail-info { 74 | padding: 24px; 75 | } 76 | 77 | .diving-row { 78 | margin-left: -12px; 79 | margin-right: -12px; 80 | } 81 | .diving-row-col { 82 | padding-left: 12px; 83 | padding-right: 12px; 84 | margin-bottom: 24px; 85 | } 86 | 87 | .diving-basic-info span { 88 | height: 22px; 89 | color: rgba(0,0,0,.85); 90 | font-size: 14px; 91 | line-height: 22px; 92 | } 93 | .diving-basic-info p { 94 | height: 38px; 95 | margin-top: 4px; 96 | margin-bottom: 0; 97 | overflow: hidden; 98 | color: rgba(0,0,0,.85); 99 | font-size: 30px; 100 | line-height: 38px; 101 | white-space: nowrap; 102 | text-overflow: ellipsis; 103 | word-break: break-all; 104 | } 105 | 106 | .diving-file-type-proportion { 107 | height: 16px; 108 | overflow: hidden; 109 | } 110 | 111 | .diving-file-tree-color { 112 | float: right; 113 | color: #999; 114 | font-size: 12px; 115 | } 116 | .diving-file-tree-color span { 117 | margin-right: 10px; 118 | } 119 | 120 | -------------------------------------------------------------------------------- /web/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "antd/dist/antd.css"; 3 | import { 4 | Input, 5 | Spin, 6 | message, 7 | Row, 8 | Col, 9 | Card, 10 | Icon, 11 | Tooltip, 12 | Table, 13 | Progress, 14 | Popover 15 | } from "antd"; 16 | 17 | import bytes from "bytes"; 18 | 19 | import "./App.css"; 20 | import FileTree from "./FileTree"; 21 | import { fetchImage, fetchLayer, fetchCaches } from "./image"; 22 | import { 23 | getFileType, 24 | TypeUnknown, 25 | convertCacheDate, 26 | convertTimeConsuming 27 | } from "./util"; 28 | import FileTypeProportion from "./FileTypeProportion"; 29 | import logo from "./logo.png"; 30 | 31 | const Search = Input.Search; 32 | 33 | const StepSearch = "search"; 34 | const StepDetail = "detail"; 35 | 36 | class App extends Component { 37 | state = { 38 | image: "", 39 | step: StepSearch, 40 | loading: false, 41 | basicInfo: null, 42 | fileTypeProportion: null, 43 | caches: null 44 | }; 45 | constructor() { 46 | super(); 47 | const { location, decodeURIComponent } = window; 48 | if (location.search) { 49 | const arr = location.search.substring(1).split("&"); 50 | const query = {}; 51 | // 简单处理,不考虑有相同key的情况 52 | arr.forEach(item => { 53 | const tmp = item.split("="); 54 | query[tmp[0]] = decodeURIComponent(tmp[1]); 55 | }); 56 | if (query.image) { 57 | this.state.image = query.image; 58 | } 59 | } 60 | } 61 | // 获取image的基本信息 62 | async getBasicInfo(name, times = 0) { 63 | if (!name) { 64 | return; 65 | } 66 | const { loading } = this.state; 67 | if (!loading) { 68 | this.setState({ 69 | loading: true 70 | }); 71 | } 72 | try { 73 | if (times > 3) { 74 | throw new Error("Analyse image isn't done, please try again later."); 75 | } 76 | const { status, data } = await fetchImage(name); 77 | if (status === 202) { 78 | setTimeout(() => { 79 | this.getBasicInfo(name, times + 1); 80 | }, 5000); 81 | return; 82 | } 83 | this.setState({ 84 | loading: false, 85 | basicInfo: data, 86 | step: StepDetail 87 | }); 88 | this.fetchLayerInfo(); 89 | } catch (err) { 90 | message.error(err.message); 91 | this.setState({ 92 | loading: false 93 | }); 94 | } 95 | } 96 | async fetchLayerInfo() { 97 | const { image, basicInfo } = this.state; 98 | const res = await fetchLayer(image, 0); 99 | const { data } = res; 100 | const sizeMap = {}; 101 | const loop = item => { 102 | if (!item) { 103 | return; 104 | } 105 | const { children } = item; 106 | if (children) { 107 | const keys = Object.keys(item.children); 108 | keys.forEach(key => { 109 | const tmp = children[key]; 110 | if (tmp.isDir) { 111 | loop(tmp); 112 | return; 113 | } 114 | // 软链接,忽略 115 | if (tmp.linkName) { 116 | return; 117 | } 118 | const fileType = getFileType(key); 119 | if (!fileType) { 120 | return; 121 | } 122 | if (!sizeMap[fileType]) { 123 | sizeMap[fileType] = 0; 124 | } 125 | sizeMap[fileType] += tmp.size; 126 | }); 127 | } 128 | }; 129 | loop(data); 130 | let otherTypeSize = basicInfo.sizeBytes; 131 | Object.keys(sizeMap).forEach(item => { 132 | otherTypeSize -= sizeMap[item]; 133 | }); 134 | sizeMap[TypeUnknown] = otherTypeSize; 135 | this.setState({ 136 | fileTypeProportion: sizeMap 137 | }); 138 | } 139 | onSearch(name) { 140 | this.setState({ 141 | image: name 142 | }); 143 | this.getBasicInfo(name, 0); 144 | const { location, history, encodeURIComponent } = window; 145 | history.pushState( 146 | null, 147 | "", 148 | `${location.pathname}?image=${encodeURIComponent(name)}` 149 | ); 150 | } 151 | async refreshCacheImages() { 152 | const { caches } = this.state; 153 | try { 154 | const { data } = await fetchCaches(); 155 | const key = JSON.stringify(data); 156 | if (!caches || JSON.stringify(caches) !== key) { 157 | this.setState({ 158 | caches: data 159 | }); 160 | } 161 | } catch (err) { 162 | message.error(err.message); 163 | } 164 | } 165 | renderSearch() { 166 | const { step, image } = this.state; 167 | if (step !== StepSearch) { 168 | return; 169 | } 170 | return ( 171 |
172 | 181 | 192 | 193 | this.onSearch(value)} 202 | /> 203 |
204 | ); 205 | } 206 | renderBasicInfo() { 207 | const { basicInfo, fileTypeProportion } = this.state; 208 | const efficiencyScoreName = "Efficiency Score"; 209 | const imageSizeName = "Image Size"; 210 | const userSizeName = "User Size"; 211 | const wastedSizeName = "Wasted Size"; 212 | const keys = [ 213 | { 214 | name: efficiencyScoreName, 215 | title: "Image efficiency score", 216 | value: `${(basicInfo.efficiency * 100).toFixed(2)}%` 217 | }, 218 | { 219 | name: imageSizeName, 220 | title: 221 | "Image size and file type proportion(Text, Image, Document, Compression, Others)", 222 | value: bytes.format(basicInfo.sizeBytes) 223 | }, 224 | { 225 | name: userSizeName, 226 | title: "All bytes except for the base image", 227 | value: bytes.format(basicInfo.userSizeBytes) 228 | }, 229 | { 230 | name: wastedSizeName, 231 | title: "All bytes of remove or duplicate files", 232 | value: bytes.format(basicInfo.wastedBytes) 233 | } 234 | ]; 235 | const renderEfficiencyScoreProgress = item => { 236 | if (item.name !== efficiencyScoreName) { 237 | return; 238 | } 239 | return ( 240 | 241 | 251 | 252 | ); 253 | }; 254 | const renderFileTypeProportion = item => { 255 | if (item.name !== imageSizeName || !fileTypeProportion) { 256 | return; 257 | } 258 | return ( 259 | 265 | ); 266 | }; 267 | const renderUserSize = item => { 268 | if (item.name !== userSizeName) { 269 | return; 270 | } 271 | return ( 272 | 282 | ); 283 | }; 284 | const renderWastedSize = item => { 285 | if (item.name !== wastedSizeName) { 286 | return; 287 | } 288 | const maxSize = 5 * 1024 * 1024; 289 | const percent = Math.min(100, (100 * basicInfo.wastedBytes) / maxSize); 290 | let status = "success"; 291 | if (percent > 70) { 292 | status = "exception"; 293 | } else if (percent > 50) { 294 | status = "normal"; 295 | } 296 | return ( 297 | 298 | 308 | 309 | ); 310 | }; 311 | const basicInfoCols = keys.map(item => ( 312 | 321 | 322 | 323 | 330 | 331 | {item.name} 332 |

{item.value}

333 | {renderEfficiencyScoreProgress(item)} 334 | {renderFileTypeProportion(item)} 335 | {renderUserSize(item)} 336 | {renderWastedSize(item)} 337 |
338 | 339 | )); 340 | return {basicInfoCols}; 341 | } 342 | formatCommand(text) { 343 | const result = []; 344 | text.split(";").forEach(function(value) { 345 | const tmpResult = []; 346 | value.split("&&").forEach(function(item) { 347 | if (item) { 348 | tmpResult.push(item); 349 | } 350 | }); 351 | if (tmpResult.length) { 352 | result.push(tmpResult.join("&& \\ \n")); 353 | } 354 | }); 355 | return ( 356 |
361 |         {result.join("; \\ \n")}
362 |       
363 | ); 364 | } 365 | renderLayersAndInefficiency() { 366 | const { basicInfo } = this.state; 367 | const layerColumns = [ 368 | { 369 | title: "Image ID", 370 | dataIndex: "shortID" 371 | }, 372 | { 373 | title: "Size", 374 | dataIndex: "size", 375 | render: size => bytes.format(size), 376 | sorter: (a, b) => a.size - b.size 377 | }, 378 | { 379 | title: "Command", 380 | dataIndex: "command", 381 | render: text => ( 382 | 383 | 388 | {text} 389 | 390 | 391 | ) 392 | } 393 | ]; 394 | const inefficiencyColumn = [ 395 | { 396 | title: "Path", 397 | dataIndex: "path" 398 | }, 399 | { 400 | title: "Cumulative Size", 401 | dataIndex: "cumulativeSize", 402 | defaultSortOrder: "descend", 403 | render: size => bytes.format(size), 404 | sorter: (a, b) => a.cumulativeSize - b.cumulativeSize 405 | }, 406 | { 407 | title: "Count", 408 | dataIndex: "count", 409 | sorter: (a, b) => a.count - b.count 410 | } 411 | ]; 412 | const layerAnalysisData = basicInfo.layerAnalysisList.map(item => { 413 | item.key = item.id; 414 | return item; 415 | }); 416 | let inefficiencyData = null; 417 | if (basicInfo.inefficiencyAnalysisList) { 418 | inefficiencyData = basicInfo.inefficiencyAnalysisList.map(item => { 419 | item.key = item.path; 420 | return item; 421 | }); 422 | } 423 | 424 | return ( 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 |
434 | 435 | 436 | 437 | ); 438 | } 439 | renderFileTrees() { 440 | const { image, basicInfo } = this.state; 441 | if (!image || !basicInfo) { 442 | return; 443 | } 444 | return ; 445 | } 446 | renderDetailInfo() { 447 | const { step, image } = this.state; 448 | if (step !== StepDetail) { 449 | return; 450 | } 451 | return ( 452 |
453 |
454 | 455 | logo 462 |

463 | Diving 464 | {image} 465 |

466 |
467 |
468 |
469 | {this.renderBasicInfo()} 470 | {this.renderFileTrees()} 471 | {this.renderLayersAndInefficiency()} 472 |
473 |
474 | ); 475 | } 476 | renderCacheImages() { 477 | const { caches } = this.state; 478 | if (!caches) { 479 | return; 480 | } 481 | const keys = Object.keys(caches); 482 | if (keys.length === 0) { 483 | return; 484 | } 485 | keys.sort((k1, k2) => caches[k2].createdAt - caches[k1].createdAt); 486 | const arr = keys.map(key => { 487 | const item = caches[key]; 488 | const date = convertCacheDate(item.createdAt); 489 | let iconType = "loading"; 490 | let color = "#1890ff"; 491 | let timeConsuming = null; 492 | if (item.status === 2) { 493 | iconType = "check-circle"; 494 | color = "#52c41a"; 495 | } else if (item.status === 1) { 496 | iconType = "close-circle"; 497 | color = "#f5222d"; 498 | } 499 | if (item.timeConsuming) { 500 | timeConsuming = ( 501 | 506 | {convertTimeConsuming(item.timeConsuming)} 507 | 508 | ); 509 | } 510 | return ( 511 |
this.onSearch(key)} 515 | > 516 | {key} 517 | 522 | {date} 523 | 524 | {timeConsuming} 525 | 531 |
532 | ); 533 | }); 534 | return
{arr}
; 535 | } 536 | render() { 537 | return ( 538 | 539 |
540 | {this.renderSearch()} 541 | {this.renderDetailInfo()} 542 | {this.renderCacheImages()} 543 |
544 |
545 | ); 546 | } 547 | componentDidMount() { 548 | const { image } = this.state; 549 | if (image) { 550 | this.onSearch(image); 551 | } 552 | setInterval(() => { 553 | this.refreshCacheImages(); 554 | }, 5000); 555 | this.refreshCacheImages(); 556 | } 557 | } 558 | 559 | export default App; 560 | -------------------------------------------------------------------------------- /web/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./App"; 4 | 5 | it("renders without crashing", () => { 6 | const div = document.createElement("div"); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /web/src/FileTree.css: -------------------------------------------------------------------------------- 1 | .diving-file-tree-functions { 2 | overflow: hidden; 3 | /* margin-bottom: 15px; */ 4 | } 5 | 6 | .diving-file-tree-functions-item { 7 | /* float: left; */ 8 | display: inline-block; 9 | margin-bottom: 15px; 10 | margin-right: 15px; 11 | } 12 | 13 | .diving-file-tree-item { 14 | font-size: 14px; 15 | } 16 | 17 | .diving-file-tree-item:nth-child(2n) { 18 | background-color: #f7f7f6; 19 | } 20 | 21 | .diving-file-tree-item > span { 22 | display: inline-block; 23 | line-height: 30px; 24 | margin-right: 15px; 25 | } 26 | 27 | .diving-file-tree-item .mode { 28 | width: 100px; 29 | } 30 | 31 | .diving-file-tree-item .ids { 32 | width: 80px; 33 | text-align: right; 34 | } 35 | 36 | .diving-file-tree-item .size { 37 | width: 100px; 38 | text-align: right; 39 | } -------------------------------------------------------------------------------- /web/src/FileTree.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import bytes from "bytes"; 3 | import PropTypes from "prop-types"; 4 | import { 5 | Icon, 6 | Spin, 7 | Row, 8 | Col, 9 | Card, 10 | message, 11 | Select, 12 | Checkbox, 13 | Tooltip, 14 | Input 15 | } from "antd"; 16 | 17 | import { fetchLayer } from "./image"; 18 | 19 | import "./FileTree.css"; 20 | 21 | const Option = Select.Option; 22 | 23 | const colors = { 24 | changed: "#f0a020", 25 | added: "#18a058", 26 | removed: "#d03050", 27 | default: "rgba(0, 0, 0, 0.65)" 28 | }; 29 | const sizeLimitArr = [ 30 | { 31 | name: "no limit", 32 | value: 0 33 | }, 34 | { 35 | name: ">=10KB", 36 | value: 10 * 1024 37 | }, 38 | { 39 | name: ">=30KB", 40 | value: 30 * 1024 41 | }, 42 | { 43 | name: ">=100KB", 44 | value: 100 * 1024 45 | }, 46 | { 47 | name: ">=500KB", 48 | value: 500 * 1024 49 | }, 50 | { 51 | name: ">=1MB", 52 | value: 1024 * 1024 53 | }, 54 | { 55 | name: ">=10MB", 56 | value: 10 * 1024 * 1024 57 | } 58 | ]; 59 | 60 | class FileTree extends Component { 61 | state = { 62 | keyword: "", 63 | sizeFilter: "", 64 | showModifications: false, 65 | expandAll: false, 66 | expands: [], 67 | fileTree: null, 68 | loading: false 69 | }; 70 | // 是否应该展开此目录 71 | shouldExpand(level, name) { 72 | const { expandAll } = this.state; 73 | // 如果设置全部展开 74 | if (expandAll) { 75 | return true; 76 | } 77 | return this.findExpandIndex(level, name) !== -1; 78 | } 79 | findExpandIndex(level, name) { 80 | const { expands } = this.state; 81 | let found = -1; 82 | if (!expands) { 83 | return found; 84 | } 85 | expands.forEach((item, index) => { 86 | if (found !== -1) { 87 | return; 88 | } 89 | if (item.level === level && item.name === name) { 90 | found = index; 91 | } 92 | }); 93 | return found; 94 | } 95 | getFileTree() { 96 | const { keyword, showModifications, sizeFilter, fileTree } = this.state; 97 | if (!fileTree) { 98 | return null; 99 | } 100 | if (!keyword && !sizeFilter && !showModifications) { 101 | return fileTree; 102 | } 103 | let reg = null; 104 | // 如果只是 \ 时,先不生成正则,因为此时还仅是转义字符 105 | if (keyword && keyword !== "\\") { 106 | try { 107 | reg = new RegExp(keyword, "gi"); 108 | } catch (err) { 109 | console.error(err); 110 | } 111 | } 112 | const minSize = sizeFilter; 113 | // 判断是否符合筛选条件 114 | const check = (name, item) => { 115 | const { size } = item; 116 | let regCheck = true; 117 | let sizeCheck = true; 118 | let modificationCheck = true; 119 | if (reg) { 120 | regCheck = reg.test(name); 121 | } 122 | if (minSize) { 123 | sizeCheck = size >= minSize; 124 | } 125 | if (showModifications && !item.diffType) { 126 | modificationCheck = false; 127 | } 128 | return regCheck && sizeCheck && modificationCheck; 129 | }; 130 | // 复制 131 | const copy = item => { 132 | const clone = Object.assign({}, item); 133 | delete clone.children; 134 | return clone; 135 | }; 136 | // 筛选复制可用的节点 137 | const filter = (current, original) => { 138 | if (!original || !original.children) { 139 | return; 140 | } 141 | const keys = Object.keys(original.children); 142 | keys.forEach(k => { 143 | const originalItem = original.children[k]; 144 | const item = copy(originalItem); 145 | if (item.isDir) { 146 | filter(item, originalItem); 147 | } 148 | // 如果是目录,而且目录下有文件 149 | if ( 150 | check(k, item) || 151 | (item.isDir && 152 | item.children && 153 | Object.keys(item.children).length !== 0) 154 | ) { 155 | current.children = current.children || {}; 156 | current.children[k] = item; 157 | } 158 | }); 159 | }; 160 | const result = copy(fileTree); 161 | filter(result, fileTree); 162 | return result; 163 | } 164 | // 切换展开的显示 165 | toggleExpand(level, name) { 166 | const { expands } = this.state; 167 | const index = this.findExpandIndex(level, name); 168 | if (index !== -1) { 169 | expands.splice(index, 1); 170 | } else { 171 | expands.push({ 172 | level, 173 | name 174 | }); 175 | } 176 | this.setState({ 177 | expands 178 | }); 179 | } 180 | renderFileNodes() { 181 | const tree = this.getFileTree(); 182 | if (!tree) { 183 | return; 184 | } 185 | const fileNodes = []; 186 | fileNodes.push( 187 |
188 | Permission 189 | UID:GID 190 | Size 191 | FileTree 192 |
193 | ); 194 | const renderFileAnalysis = (tree, prefix, level) => { 195 | if (!tree.children || tree.children.length === 0) { 196 | return null; 197 | } 198 | const keys = Object.keys(tree.children); 199 | keys.forEach((k, index) => { 200 | const item = tree.children[k]; 201 | const size = bytes.format(item.size); 202 | let name = k; 203 | // 非目录非软链接 204 | // if (!item.isDir && !item.linkName && item.size) { 205 | // totalSizeOfFile += item.size; 206 | // } 207 | if (item.linkName) { 208 | name += ` → ${item.linkName}`; 209 | } 210 | let mode = item.mode; 211 | if (mode && mode.charAt(0) === "L") { 212 | mode = "-" + mode.substring(1); 213 | } 214 | const hasChildren = item.children && item.children.length !== 0; 215 | const expanded = this.shouldExpand(level, k); 216 | let fontColor = ""; 217 | switch (item.diffType) { 218 | case 1: 219 | fontColor = colors.changed; 220 | break; 221 | case 2: 222 | fontColor = colors.added; 223 | break; 224 | case 3: 225 | fontColor = colors.removed; 226 | break; 227 | default: 228 | fontColor = colors.default; 229 | break; 230 | } 231 | let iconType = "plus-square"; 232 | if (expanded) { 233 | iconType = "minus-square"; 234 | } 235 | fileNodes.push( 236 |
243 | {mode} 244 | {item.ids} 245 | {size} 246 | 251 | {hasChildren && ( 252 | this.toggleExpand(level, name)} 260 | /> 261 | )} 262 | {name} 263 | 264 |
265 | ); 266 | if (hasChildren && expanded) { 267 | renderFileAnalysis(item, `${prefix}-${k}`, level + 1); 268 | } 269 | }); 270 | }; 271 | renderFileAnalysis(tree, "root", 0); 272 | return fileNodes; 273 | } 274 | // 获取 layer的文件树 275 | async getTree(layer = 0) { 276 | const { image } = this.props; 277 | this.setState({ 278 | fileTree: null, 279 | loading: true 280 | }); 281 | try { 282 | const res = await fetchLayer(image, layer); 283 | this.setState({ 284 | fileTree: res.data 285 | }); 286 | } catch (err) { 287 | message.error(err.message); 288 | } finally { 289 | this.setState({ 290 | loading: false 291 | }); 292 | } 293 | } 294 | onChangeLayer(value) { 295 | const { layers } = this.props; 296 | let found = -1; 297 | layers.forEach((item, index) => { 298 | if (item.shortID === value) { 299 | found = index; 300 | } 301 | }); 302 | if (found === -1) { 303 | return; 304 | } 305 | this.getTree(found); 306 | } 307 | onChangeSizeFilter(value) { 308 | this.setState({ 309 | sizeFilter: value 310 | }); 311 | } 312 | componentDidMount() { 313 | this.getTree(0); 314 | } 315 | renderFunctions() { 316 | const { layers } = this.props; 317 | const layerArr = layers.map(item => { 318 | let sizeDesc = ""; 319 | if (item.size) { 320 | sizeDesc = `(${bytes.format(item.size)})`; 321 | } 322 | return ( 323 | 326 | ); 327 | }); 328 | const sizeArr = sizeLimitArr.map(item => ( 329 | 332 | )); 333 | return ( 334 |
335 |
336 | 343 | 352 |
353 |
354 | 361 | 370 |
371 |
372 | 374 | this.setState({ 375 | showModifications: e.target.checked 376 | }) 377 | } 378 | > 379 | Modifications 380 | 381 | 388 | 389 | 390 |
391 |
392 | 394 | this.setState({ 395 | expandAll: e.target.checked 396 | }) 397 | } 398 | > 399 | Expand 400 | 401 | 408 | 409 | 410 |
411 |
412 | 417 | this.setState({ 418 | keyword: e.target.value 419 | }) 420 | } 421 | placeholder="support regexp" 422 | addonBefore="Keyword:" 423 | /> 424 |
425 |
426 | ); 427 | } 428 | render() { 429 | const { loading } = this.state; 430 | const title = ( 431 |
432 | Layer Content 433 |
434 | 439 | Modified 440 | 441 | 446 | Added 447 | 448 | 453 | Removed 454 | 455 | 456 | 463 | 464 |
465 |
466 | ); 467 | 468 | return ( 469 | 470 |
471 | 472 | {this.renderFunctions()} 473 | 474 | {this.renderFileNodes()} 475 | 476 | 477 | 478 | 479 | ); 480 | } 481 | } 482 | 483 | FileTree.propTypes = { 484 | image: PropTypes.string.isRequired, 485 | layers: PropTypes.array.isRequired 486 | }; 487 | 488 | export default FileTree; 489 | -------------------------------------------------------------------------------- /web/src/FileTypeProportion.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import PropTypes from "prop-types"; 3 | import bytes from "bytes"; 4 | import { Tooltip } from "antd"; 5 | 6 | import { getFileTypeName } from "./util"; 7 | 8 | const colors = [ 9 | "#1f8ffb", 10 | "#54c3c3", 11 | "#5cc35c", 12 | "#facd33", 13 | "#ed4a64", 14 | "#854ae0" 15 | ]; 16 | 17 | class FileTypeProportion extends Component { 18 | render() { 19 | const { data } = this.props; 20 | const keys = Object.keys(data).sort(); 21 | let count = 0; 22 | keys.forEach(k => { 23 | count += data[k]; 24 | }); 25 | const result = []; 26 | let rest = 100; 27 | keys.forEach((k, index) => { 28 | const size = data[k]; 29 | let percent = ((100 * size) / count).toFixed(2); 30 | if (index === keys.length - 1) { 31 | percent = rest.toFixed(2); 32 | } else { 33 | rest -= percent; 34 | } 35 | const color = colors[index % colors.length]; 36 | const name = getFileTypeName(k); 37 | const title = `${name}'s size is ${bytes.format(size)}(${percent}%)`; 38 | result.push( 39 | 40 | 49 | 50 | ); 51 | }); 52 | return ( 53 |
54 | {result} 55 |
56 | ); 57 | } 58 | } 59 | 60 | FileTypeProportion.propTypes = { 61 | data: PropTypes.object.isRequired 62 | }; 63 | 64 | export default FileTypeProportion; 65 | -------------------------------------------------------------------------------- /web/src/LOGO.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicanso/diving/e419563b7f0fb31f86a573b8f840808eb920603f/web/src/LOGO.zip -------------------------------------------------------------------------------- /web/src/image.js: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | 3 | axios.interceptors.response.use( 4 | function(response) { 5 | return response; 6 | }, 7 | function(err) { 8 | if (err.response && err.response.data && err.response.data.message) { 9 | const { data } = err.response; 10 | let msg = data.message; 11 | if (data.category) { 12 | msg += `[${data.category}]`; 13 | } 14 | err.message = msg; 15 | } 16 | return Promise.reject(err); 17 | } 18 | ); 19 | 20 | const ImageDetailURL = "/api/images/detail/"; 21 | const ImageLayerDetailURL = "/api/images/tree/"; 22 | const ImageCacheURL = "/api/images/caches"; 23 | 24 | const layerCache = {}; 25 | 26 | function generateImageName(name) { 27 | return name.includes(":") ? name : `${name}:latest`; 28 | } 29 | 30 | export function fetchImage(name) { 31 | return axios.get(ImageDetailURL + generateImageName(name)); 32 | } 33 | 34 | export function fetchLayer(image, layer) { 35 | const key = `${image}-${layer}`; 36 | if (layerCache[key]) { 37 | return layerCache[key]; 38 | } 39 | const p = axios.get( 40 | `${ImageLayerDetailURL}${generateImageName(image)}?layer=${layer}` 41 | ); 42 | layerCache[key] = p; 43 | p.catch(err => { 44 | delete layerCache[key]; 45 | throw err; 46 | }); 47 | return p; 48 | } 49 | 50 | export function fetchCaches() { 51 | return axios.get(ImageCacheURL); 52 | } 53 | -------------------------------------------------------------------------------- /web/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /web/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import "./index.css"; 4 | import App from "./App"; 5 | // import * as serviceWorker from './serviceWorker'; 6 | 7 | ReactDOM.render(, document.getElementById("root")); 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: http://bit.ly/CRA-PWA 12 | // serviceWorker.unregister(); 13 | -------------------------------------------------------------------------------- /web/src/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vicanso/diving/e419563b7f0fb31f86a573b8f840808eb920603f/web/src/logo.png -------------------------------------------------------------------------------- /web/src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read http://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === "localhost" || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === "[::1]" || 17 | // 127.0.0.1/8 is considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | export function register(config) { 24 | if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) { 25 | // The URL constructor is available in all browsers that support SW. 26 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); 27 | if (publicUrl.origin !== window.location.origin) { 28 | // Our service worker won't work if PUBLIC_URL is on a different origin 29 | // from what our page is served on. This might happen if a CDN is used to 30 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 31 | return; 32 | } 33 | 34 | window.addEventListener("load", () => { 35 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 36 | 37 | if (isLocalhost) { 38 | // This is running on localhost. Let's check if a service worker still exists or not. 39 | checkValidServiceWorker(swUrl, config); 40 | 41 | // Add some additional logging to localhost, pointing developers to the 42 | // service worker/PWA documentation. 43 | navigator.serviceWorker.ready.then(() => { 44 | console.log( 45 | "This web app is being served cache-first by a service " + 46 | "worker. To learn more, visit http://bit.ly/CRA-PWA" 47 | ); 48 | }); 49 | } else { 50 | // Is not localhost. Just register service worker 51 | registerValidSW(swUrl, config); 52 | } 53 | }); 54 | } 55 | } 56 | 57 | function registerValidSW(swUrl, config) { 58 | navigator.serviceWorker 59 | .register(swUrl) 60 | .then(registration => { 61 | registration.onupdatefound = () => { 62 | const installingWorker = registration.installing; 63 | if (installingWorker == null) { 64 | return; 65 | } 66 | installingWorker.onstatechange = () => { 67 | if (installingWorker.state === "installed") { 68 | if (navigator.serviceWorker.controller) { 69 | // At this point, the updated precached content has been fetched, 70 | // but the previous service worker will still serve the older 71 | // content until all client tabs are closed. 72 | console.log( 73 | "New content is available and will be used when all " + 74 | "tabs for this page are closed. See http://bit.ly/CRA-PWA." 75 | ); 76 | 77 | // Execute callback 78 | if (config && config.onUpdate) { 79 | config.onUpdate(registration); 80 | } 81 | } else { 82 | // At this point, everything has been precached. 83 | // It's the perfect time to display a 84 | // "Content is cached for offline use." message. 85 | console.log("Content is cached for offline use."); 86 | 87 | // Execute callback 88 | if (config && config.onSuccess) { 89 | config.onSuccess(registration); 90 | } 91 | } 92 | } 93 | }; 94 | }; 95 | }) 96 | .catch(error => { 97 | console.error("Error during service worker registration:", error); 98 | }); 99 | } 100 | 101 | function checkValidServiceWorker(swUrl, config) { 102 | // Check if the service worker can be found. If it can't reload the page. 103 | fetch(swUrl) 104 | .then(response => { 105 | // Ensure service worker exists, and that we really are getting a JS file. 106 | const contentType = response.headers.get("content-type"); 107 | if ( 108 | response.status === 404 || 109 | (contentType != null && contentType.indexOf("javascript") === -1) 110 | ) { 111 | // No service worker found. Probably a different app. Reload the page. 112 | navigator.serviceWorker.ready.then(registration => { 113 | registration.unregister().then(() => { 114 | window.location.reload(); 115 | }); 116 | }); 117 | } else { 118 | // Service worker found. Proceed as normal. 119 | registerValidSW(swUrl, config); 120 | } 121 | }) 122 | .catch(() => { 123 | console.log( 124 | "No internet connection found. App is running in offline mode." 125 | ); 126 | }); 127 | } 128 | 129 | export function unregister() { 130 | if ("serviceWorker" in navigator) { 131 | navigator.serviceWorker.ready.then(registration => { 132 | registration.unregister(); 133 | }); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /web/src/util.js: -------------------------------------------------------------------------------- 1 | export const TypeUnknown = 0; 2 | export const TypeText = 1; 3 | export const TypeImage = 2; 4 | export const TypeDocument = 3; 5 | export const TypeCompression = 4; 6 | 7 | const fileTypes = {}; 8 | 9 | (() => { 10 | const fillType = (arr, type) => { 11 | arr.forEach(ext => { 12 | fileTypes[ext] = type; 13 | }); 14 | }; 15 | fillType(["csv", "markdown", "md", "txt", "text", "log"], TypeText); 16 | 17 | fillType( 18 | ["apng", "png", "bmp", "gif", "jp2", "jpg2", "jpg", "jpeg", "jpe", "webp"], 19 | TypeImage 20 | ); 21 | 22 | fillType(["doc", "docx", "xls", "xlsx", "ppt", "pptx", "pdf"], TypeDocument); 23 | 24 | fillType(["gz", "zip", "bz2", "xz"], TypeCompression); 25 | })(); 26 | 27 | export function getFileType(name) { 28 | const arr = name.split("."); 29 | // 如果无文件后缀,忽略 30 | if (arr.length < 2) { 31 | return TypeUnknown; 32 | } 33 | const ext = arr[arr.length - 1]; 34 | return fileTypes[ext] || TypeUnknown; 35 | } 36 | 37 | export function getFileTypeName(type) { 38 | let name = ""; 39 | switch (Number.parseInt(type)) { 40 | case TypeText: 41 | name = "text"; 42 | break; 43 | case TypeImage: 44 | name = "image"; 45 | break; 46 | case TypeDocument: 47 | name = "document"; 48 | break; 49 | case TypeCompression: 50 | name = "compression"; 51 | break; 52 | default: 53 | name = "others"; 54 | break; 55 | } 56 | return name; 57 | } 58 | 59 | export function convertCacheDate(value) { 60 | const str = new Date(value * 1000).toLocaleString(); 61 | return str; 62 | } 63 | 64 | export function convertTimeConsuming(value) { 65 | const ms = 1e6; 66 | const second = 1e9; 67 | const minute = 60 * second; 68 | if (value > minute) { 69 | return `${Math.ceil(value / minute)}m`; 70 | } 71 | if (value > second) { 72 | return `${Math.ceil(value / second)}s`; 73 | } 74 | return `${Math.ceil(value / ms)}ms`; 75 | } 76 | --------------------------------------------------------------------------------