diff --git a/README.md b/README.md index f22df37915..c2dc3d910b 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,13 @@ $ docker run --rm -v :/opt/skywire \ skycoin/skywire:test skywire-cli config gen -i ``` +Docker container will create config automatically for you, should you want to run it manually, you can do: + +```bash +$ docker run --rm -v :/opt/skywire \ + skycoin/skywire:latest skywire-cli visor gen-config --is-hypervisor +``` + After starting up the visor, the UI will be exposed by default on `localhost:8000`. ### Add remote hypervisor @@ -65,6 +72,14 @@ $ docker run --rm -v :/opt/skywire \ skycoin/skywire:test skywire-cli config update hypervisor-pks ``` +Or from docker image: + +```bash +$ docker run --rm -v :/opt/skywire \ + skycoin/skywire:latest skywire-cli update-config hypervisor-pks + +``` + ## Run `skywire-visor` `skywire-visor` hosts apps and is an applications gateway to the Skywire network. diff --git a/docker/images/visor/update.sh b/docker/images/visor/update.sh new file mode 100755 index 0000000000..8b78e26aee --- /dev/null +++ b/docker/images/visor/update.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +if type apt > /dev/null; then + apt-get update && apt-get install -y --no-install-recommends \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* +fi + +if type apk > /dev/null; then + + apk update + apk upgrade + apk add --no-cache ca-certificates openssl iproute2 + update-ca-certificates --fresh + apk add iproute2 +fi diff --git a/go.mod b/go.mod index 4fc6ffbf47..dd2a8a04a8 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( github.com/mmcloughlin/avo v0.0.0-20200523190732-4439b6b2c061 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/pkg/profile v1.5.0 + github.com/rakyll/statik v0.1.7 github.com/schollz/progressbar/v2 v2.15.0 github.com/shirou/gopsutil/v3 v3.21.4 github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 19f69100c0..8fced26276 100644 --- a/go.sum +++ b/go.sum @@ -272,6 +272,8 @@ github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ= +github.com/rakyll/statik v0.1.7/go.mod h1:AlZONWzMtEnMs7W4e/1LURLiI49pIMmp6V9Unghqrcc= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/mainnet_rules.md b/mainnet_rules.md index a0299c1907..dafd00df3d 100644 --- a/mainnet_rules.md +++ b/mainnet_rules.md @@ -23,86 +23,88 @@ This article represents the central source of information for the Skywire mainne * Please join [SkywirePSA](https://t.me/SkywirePSA) as well to get structured public service announcements (PSA) about the Skywire project. * In case you bought an official Skyminer in the [Skycoin hardware store](https://store.skycoin.com/) please read [the Official Skyminer Guide](https://github.com/skycoin/skywire/wiki/Skyminer-Official-Guide) if you haven't done that already. * Participants will be contacted at the beginning of every month via the so-called *Skywire Status Update Emails* including details of their last month's Skywire mainnet participation. -* You can contact support at store.skycoin.com/pages/support +* You can contact support at store.skycoin.com/pages/support or via email at `support [at] skycoin.com` *** ## Rules This section covers the rules of the mainnet. Dependent on the amount of miners that are associated with your emails, some of these rules may apply to you or not. -As of now, each person participating in the Skywire mainnet may own one DIY miner and multiple official Skyminers wrt. to being eligible for rewards. -
"A DIY miner cannot be in the same location as another DIY or official Skyminer.

+Currently, each person participating in the Skywire mainnet may own one DIY miner and/or multiple official Skyminers to be eligible for rewards. +
A DIY miner cannot be in the same location as another DIY or official Skyminer.

-Based on this central rule, each whitelisted person is eligible for receiving rewards for: -* one or multiple official miners +Based on this central rule, each whitelisted person is eligible to receive rewards for: +* one or multiple official Skyminers *and/or* -* one DIY miner with up to 8 (eight) nodes +* one DIY miner with up to 8 (eight) visors, (provided it is at a different location if you also have an official Skyminer). -
You must use the Skywire Whitelisting System to keep your submitted data up to date +
You must use the Skywire Whitelisting System to keep your submitted data up-to-date
Read the Skywire whitelisting system user guide to familiarize yourself with the new system.

Different locations are required due to the fact that we want to spread out the meshnet and not create built-up areas. This prevents paying people to simply run single board computers (SBC) and to require them to provide a service to the network. -* If you are running two separate miners in the same location because you're joining the network living in the same house you still have to move one of your miners to another location. +* If you are running two separate miners in the same location because you're joining the network with someone living in the same house you still have to move one of your miners to another location. -
Submitting miners under multiple email addresses is illegal and very likely to be detected - measures will be taken if such actions are recognized.
+
Submitting miners under multiple email addresses is forbidden and very likely to be detected - measures will be taken if such actions are recognized.
*** ## Rewards -**Skywire Visors must be running Skywire v0.3.0 or higher to receive rewards.** Note that the required minimal Skywire version is subject to change and will be updated from time to time. +**Skywire Visors must be running Skywire v0.4.2 or higher to receive rewards.** Note that the required minimal Skywire version is subject to change and will be updated from time-to-time. We'll keep the minimal version requirement at least one release behind the most recent one to provide everyone with sufficient time to upgrade.
* The rewards are **paid every subsequent month around the 5th** (short delays are possible) * Adjustments of previous months are included in these reward distributions on the 5th. * The deadline to submit complaints is being published in the monthly Skywire status update emails and in the [Skywire PSA channel on Telegram](https://t.me/SkywirePSA). -* Eligible for rewards are only the whitelisted nodes, that **comply with the Skywire mainnet rules** and **meet the uptime requirement** of the respective month (usually 75%). - -
-During Skywire’s testnet phase, owners of official Skyminers were required to have all eight nodes online in order to qualify for full uptime rewards. With the launch of Mainnet, official Skyminers now only require seven nodes to be online at least 75% of the time in order to earn full rewards. - -
-
+* Eligible for rewards are only the whitelisted visors that **comply with the Skywire mainnet rules** and **meet the uptime requirement** of the respective month (usually 75%). +* Updates of user data in the Skywire Whitelisting System are only guaranteed to be recognized for reward distributions if they are submitted during the respective calendar month for which the rewards are being calculated. ### Official Skyminers -There are two different reward categories for official miners: -* official Skyminers first & second batch - **not sold through** the hardware store -* official Skyminers new batches - **sold through** the [hardware store](https://store.skycoin.com) +There are two different reward methods for official miners: +* official Skyminers Skycoin Pool Method: + - first & second batch official Skyminer + - third batch official Skyminers that have received all of the 24 fixed Skycoin payments +* official Skyminers SKY/USD Method: + - **sold through** the [hardware store](https://store.skycoin.com) -Faulty orange pi prime's/routers of official Skyminers will be rewarded regardless of your uptime until you receive a replacement. If the replacement doesn't arrive in time for you to make the uptime requirement because it arrived on short notice or not on the schedule at all you will be rewarded as well. Since we are taking care of this manually you are requested to contact one of our team members on Telegram (@Paperstream @asxtree) or at store.skycoin.com/pages/support +Faulty Orange Pi Primes/routers of official Skyminers will be rewarded regardless of your uptime until you receive a replacement. If the replacement doesn't arrive in time for you to make the uptime requirement because it arrived on short notice or not on the schedule at all you will be rewarded as well. Since we are taking care of this manually you are requested to contact one of our team members on Telegram (@Paperstream @asxtree) or at store.skycoin.com/pages/support -

Official Skyminers - First & Second Batch

-
We are currently revising the reward strucure for our early supporters. Details of the rewards going forward will be announced very soon.

+

Official Skyminers - Pool Method

-Rewards are being paid on a node by node basis. The total amount of rewards is limited by a pool size that is subject to change: -* You can receive a maximum of 13.714 Skycoin per node - - official Skyminer consist of seven nodes (visors) and one manager (hypervisor) -* Rewards are being calculated on a node by node basis - - you'll receive up to 7 Skycoin per-node rewards -* The total pool size is being divided evenly between all nodes eligible for receiving rewards. This implies that you will receive less than 13.714 Skycoin per-node rewards in case the pool size would be surpassed. +Rewards are being paid on a visor by visor basis. The total amount of rewards is limited by a pool size that is subject to change: +* You can receive a maximum of 12.0 Skycoin per visor + - official Skyminers consist of eight visors and one visor that may be additionally serving as hypervisor +* Rewards are being calculated on a visor by visor basis + - you'll receive up to 8 Skycoin per-visor rewards +* The total pool size is being divided evenly between all visors eligible for receiving rewards. This implies that you will receive less than 12.0 Skycoin per-visor rewards in case the pool size would be surpassed. *** ### Official Skyminers - New Batches +

Official Skyminers - SKY/USD Method

+
Fixed Skycoin payments can be claimed within three years after purchase.

-You will receive a fixed Skycoin payment per month in addition to any traffic forwarding payments
that you will receive in the Skywire mainnet.
-Fixed Skycoin payments per month = USD Miner Price / 24 = $83.30 USD.
+You will receive a fixed Skycoin payments per month in addition to any traffic forwarding payments
that you will receive in the Skywire mainnet.
+Fixed Skycoin payments per month = USD Miner Price / 24 = $83.30 USD. +
+

-
Your fixed Skycoin payments are dependent on your the uptime of your nodes. All of your 7 nodes must meet the uptime requirement for you to receive the full $83.30 USD, it is therefore superimportant to keep your nodes online.
+
Your fixed Skycoin payments are dependent on the uptime of your visors. All of your 8 visors must meet the uptime requirement for you to receive the full $83.30 USD, it is therefore super important to keep your visors online.

-Faulty orange pi prime's/routers of official Skyminers will be rewarded regardless of your uptime until you receive a replacement. If the replacement doesn't arrive in time for you to make the uptime requirement because it arrived on short notice or not on the schedule at all you will be rewarded as well. Since we are taking care of this manually you are requested to contact one of our team members on Telegram (@Paperstream @asxtree) or at store.skycoin.com/pages/support +Faulty Orange Pi Primes/Orange Pi 3s or Skyminer Routers of official Skyminers will be rewarded regardless of your uptime until you receive a replacement. If the replacement doesn't arrive in time for you to make the uptime requirement because it arrived on short notice or not on the schedule at all you will be rewarded as well. Since we are taking care of this manually you are requested to contact one of our team members on Telegram (@Paperstream @asxtree) or at store.skycoin.com/pages/support Summary: * You are eligible to receive 24 fixed Skycoin payments ($83.30 USD) -* The 24 fixed Skycoin payments are comprised of 7 Skycoin node payments ($11.9 USD) - - official Skyminer consist of seven nodes (visors) and one manager (hypervisor) -* You'll receive up to 7 Skycoin node payments per month based on the individual uptime of your nodes -* The uptime of all nodes in your official Skyminer is being evaluated on a node by node basis -* *You will receive traffic forwarding payments once the Skywire mainnet is live* +* The 24 fixed Skycoin payments are comprised of 8 Skycoin visor payments ($10.4125 USD) + - official Skyminers consist of eight visors and one visor that may be additionally serving as hypervisor + - you'll receive up to 8 Skycoin visor payments per month based on the individual uptime of your visors +* The uptime of all visors in your official Skyminer is being evaluated on a visor-by-visor basis +* After these 24 payments, the reward model automatically changes to the [pool method reward model](https://github.com/skycoin/skywire/blob/master/mainnet_rules.md#official-skyminers) +* *You will receive traffic forwarding payments once the Skywire mainnet with bandwidth metering is live* #### Skycoin Price Calculation We are calculating the underlying Skycoin price for your rewards based on the moving average exponential method: @@ -114,29 +116,30 @@ We are calculating the underlying Skycoin price for your rewards based on the mo ### DIY Skyminers -- Rewards are being paid on a node by node basis wrt. to the uptime requirement of 75%. -- Up to eight (8) DIY nodes are being rewarded per user account in the Skywire Whitelisting System. +- Rewards are being paid on a visor-by-visor basis according to the uptime requirement of 75%. +- You can receive a maximum of 6.0 Skycoin per visor +- Up to eight (8) DIY visors are being rewarded per user account in the Skywire Whitelisting System. - The total amount of DIY rewards is limited by a pool size that is subject to change. *** ## Requirements -
Each node must have at least 75% uptime during the month to be eligible for rewards.
+
Each visor must have at least 75% uptime during the month to be eligible for rewards.
As of now, you are provided with two tools to check whether or not you're online and generating uptime: -* The [discovery website](https://uptime-tracker.skywire.skycoin.com/visors) +* The [discovery website](https://uptime-tracker.skywire.skycoin.com/uptimes) * The [Skywire whitelisting system](https://whitelist.skycoin.com) - along with the [Skywire whitelisting system user guide](https://github.com/skycoin/skywire/wiki/Skywire-Whitelisting-System) -You are advised to use [this guide](https://github.com/skycoin/skywire/wiki/Troubleshooting#online-status-verification) to **verify that your nodes are online & connected to the discovery server**. -
Make sure to verify the online status of your nodes on a regular basis!
+You are advised to use [this guide](https://github.com/skycoin/skywire/wiki/Troubleshooting#online-status-verification) to **verify that your visors are online & connected to the discovery server**. +
Make sure to verify the online status of your visors on a regular basis!
*** ## Whitelist
Whitelist applications must be submitted using the Skywire Whitelisting System.
-All necessary steps to get up and running are described in this guide
+All necessary steps to get up and running are described in this guide
@@ -146,6 +149,7 @@ All necessary steps to get up and running are described in + + Skywire + + + + + + +
+ + + + \ No newline at end of file diff --git a/vendor/github.com/rakyll/statik/LICENSE b/vendor/github.com/rakyll/statik/LICENSE new file mode 100644 index 0000000000..a4c5efd822 --- /dev/null +++ b/vendor/github.com/rakyll/statik/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2014 Google Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/rakyll/statik/fs/fs.go b/vendor/github.com/rakyll/statik/fs/fs.go new file mode 100644 index 0000000000..5a5b46f2f4 --- /dev/null +++ b/vendor/github.com/rakyll/statik/fs/fs.go @@ -0,0 +1,238 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package fs contains an HTTP file system that works with zip contents. +package fs + +import ( + "archive/zip" + "bytes" + "errors" + "fmt" + "io" + "io/ioutil" + "net/http" + "os" + "path" + "path/filepath" + "sort" + "strings" + "time" +) + +var zipData = map[string]string{} + +// file holds unzipped read-only file contents and file metadata. +type file struct { + os.FileInfo + data []byte + fs *statikFS +} + +type statikFS struct { + files map[string]file + dirs map[string][]string +} + +const defaultNamespace = "default" + +// IsDefaultNamespace returns true if the assetNamespace is +// the default one +func IsDefaultNamespace(assetNamespace string) bool { + return assetNamespace == defaultNamespace +} + +// Register registers zip contents data, later used to initialize +// the statik file system. +func Register(data string) { + RegisterWithNamespace(defaultNamespace, data) +} + +// RegisterWithNamespace registers zip contents data and set asset namespace, +// later used to initialize the statik file system. +func RegisterWithNamespace(assetNamespace string, data string) { + zipData[assetNamespace] = data +} + +// New creates a new file system with the default registered zip contents data. +// It unzips all files and stores them in an in-memory map. +func New() (http.FileSystem, error) { + return NewWithNamespace(defaultNamespace) +} + +// NewWithNamespace creates a new file system with the registered zip contents data. +// It unzips all files and stores them in an in-memory map. +func NewWithNamespace(assetNamespace string) (http.FileSystem, error) { + asset, ok := zipData[assetNamespace] + if !ok { + return nil, errors.New("statik/fs: no zip data registered") + } + zipReader, err := zip.NewReader(strings.NewReader(asset), int64(len(asset))) + if err != nil { + return nil, err + } + files := make(map[string]file, len(zipReader.File)) + dirs := make(map[string][]string) + fs := &statikFS{files: files, dirs: dirs} + for _, zipFile := range zipReader.File { + fi := zipFile.FileInfo() + f := file{FileInfo: fi, fs: fs} + f.data, err = unzip(zipFile) + if err != nil { + return nil, fmt.Errorf("statik/fs: error unzipping file %q: %s", zipFile.Name, err) + } + files["/"+zipFile.Name] = f + } + for fn := range files { + // go up directories recursively in order to care deep directory + for dn := path.Dir(fn); dn != fn; { + if _, ok := files[dn]; !ok { + files[dn] = file{FileInfo: dirInfo{dn}, fs: fs} + } else { + break + } + fn, dn = dn, path.Dir(dn) + } + } + for fn := range files { + dn := path.Dir(fn) + if fn != dn { + fs.dirs[dn] = append(fs.dirs[dn], path.Base(fn)) + } + } + for _, s := range fs.dirs { + sort.Strings(s) + } + return fs, nil +} + +var _ = os.FileInfo(dirInfo{}) + +type dirInfo struct { + name string +} + +func (di dirInfo) Name() string { return path.Base(di.name) } +func (di dirInfo) Size() int64 { return 0 } +func (di dirInfo) Mode() os.FileMode { return 0755 | os.ModeDir } +func (di dirInfo) ModTime() time.Time { return time.Time{} } +func (di dirInfo) IsDir() bool { return true } +func (di dirInfo) Sys() interface{} { return nil } + +// Open returns a file matching the given file name, or os.ErrNotExists if +// no file matching the given file name is found in the archive. +// If a directory is requested, Open returns the file named "index.html" +// in the requested directory, if that file exists. +func (fs *statikFS) Open(name string) (http.File, error) { + name = filepath.ToSlash(filepath.Clean(name)) + if f, ok := fs.files[name]; ok { + return newHTTPFile(f), nil + } + return nil, os.ErrNotExist +} + +func newHTTPFile(file file) *httpFile { + if file.IsDir() { + return &httpFile{file: file, isDir: true} + } + return &httpFile{file: file, reader: bytes.NewReader(file.data)} +} + +// httpFile represents an HTTP file and acts as a bridge +// between file and http.File. +type httpFile struct { + file + + reader *bytes.Reader + isDir bool + dirIdx int +} + +// Read reads bytes into p, returns the number of read bytes. +func (f *httpFile) Read(p []byte) (n int, err error) { + if f.reader == nil && f.isDir { + return 0, io.EOF + } + return f.reader.Read(p) +} + +// Seek seeks to the offset. +func (f *httpFile) Seek(offset int64, whence int) (ret int64, err error) { + return f.reader.Seek(offset, whence) +} + +// Stat stats the file. +func (f *httpFile) Stat() (os.FileInfo, error) { + return f, nil +} + +// IsDir returns true if the file location represents a directory. +func (f *httpFile) IsDir() bool { + return f.isDir +} + +// Readdir returns an empty slice of files, directory +// listing is disabled. +func (f *httpFile) Readdir(count int) ([]os.FileInfo, error) { + var fis []os.FileInfo + if !f.isDir { + return fis, nil + } + di, ok := f.FileInfo.(dirInfo) + if !ok { + return nil, fmt.Errorf("failed to read directory: %q", f.Name()) + } + + // If count is positive, the specified number of files will be returned, + // and if non-positive, all remaining files will be returned. + // The reading position of which file is returned is held in dirIndex. + fnames := f.file.fs.dirs[di.name] + flen := len(fnames) + + // If dirIdx reaches the end and the count is a positive value, + // an io.EOF error is returned. + // In other cases, no error will be returned even if, for example, + // you specified more counts than the number of remaining files. + start := f.dirIdx + if start >= flen && count > 0 { + return fis, io.EOF + } + var end int + if count <= 0 { + end = flen + } else { + end = start + count + } + if end > flen { + end = flen + } + for i := start; i < end; i++ { + fis = append(fis, f.file.fs.files[path.Join(di.name, fnames[i])].FileInfo) + } + f.dirIdx += len(fis) + return fis, nil +} + +func (f *httpFile) Close() error { + return nil +} + +func unzip(zf *zip.File) ([]byte, error) { + rc, err := zf.Open() + if err != nil { + return nil, err + } + defer rc.Close() + return ioutil.ReadAll(rc) +} diff --git a/vendor/github.com/rakyll/statik/fs/walk.go b/vendor/github.com/rakyll/statik/fs/walk.go new file mode 100644 index 0000000000..f4eb37d1a9 --- /dev/null +++ b/vendor/github.com/rakyll/statik/fs/walk.go @@ -0,0 +1,79 @@ +// Copyright 2014 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package fs + +import ( + "bytes" + "io" + "net/http" + "path" + "path/filepath" +) + +// Walk walks the file tree rooted at root, +// calling walkFn for each file or directory in the tree, including root. +// All errors that arise visiting files and directories are filtered by walkFn. +// +// As with filepath.Walk, if the walkFn returns filepath.SkipDir, then the directory is skipped. +func Walk(hfs http.FileSystem, root string, walkFn filepath.WalkFunc) error { + dh, err := hfs.Open(root) + if err != nil { + return err + } + di, err := dh.Stat() + if err != nil { + return err + } + fis, err := dh.Readdir(-1) + dh.Close() + if err = walkFn(root, di, err); err != nil { + if err == filepath.SkipDir { + return nil + } + return err + } + for _, fi := range fis { + fn := path.Join(root, fi.Name()) + if fi.IsDir() { + if err = Walk(hfs, fn, walkFn); err != nil { + if err == filepath.SkipDir { + continue + } + return err + } + continue + } + if err = walkFn(fn, fi, nil); err != nil { + if err == filepath.SkipDir { + continue + } + return err + } + } + return nil +} + +// ReadFile reads the contents of the file of hfs specified by name. +// Just as ioutil.ReadFile does. +func ReadFile(hfs http.FileSystem, name string) ([]byte, error) { + fh, err := hfs.Open(name) + if err != nil { + return nil, err + } + var buf bytes.Buffer + _, err = io.Copy(&buf, fh) + fh.Close() + return buf.Bytes(), err +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 1803b23c8b..81f234b083 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -144,6 +144,9 @@ github.com/pkg/errors github.com/pkg/profile # github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib/difflib +# github.com/rakyll/statik v0.1.7 +## explicit +github.com/rakyll/statik/fs # github.com/schollz/progressbar/v2 v2.15.0 ## explicit github.com/schollz/progressbar/v2