perf: avoid replacing dist tarball url on each call

This commit is contained in:
 Ilya Atamas
2019-04-23 16:06:45 +03:00
parent 18338eb0d7
commit 7e4e00e3d7
5 changed files with 33 additions and 17 deletions

View File

@@ -15,6 +15,7 @@ var rootCmd = &cobra.Command{
}
var rootOptions struct {
Silent bool
ListenAddress string
UpstreamAddress string
CacheLimit string
@@ -22,6 +23,7 @@ var rootOptions struct {
}
func init() {
rootCmd.Flags().BoolVar(&rootOptions.Silent, "silent", getEnvBool("SILENT", "0"), "Disable logging")
rootCmd.Flags().StringVar(&rootOptions.ListenAddress, "listen", getEnvString("LISTEN_ADDRESS", "localhost:8080"), "Address to listen")
rootCmd.Flags().StringVar(&rootOptions.UpstreamAddress, "upstream", getEnvString("UPSTREAM_ADDRESS", "https://registry.npmjs.org"), "Upstream registry address")
rootCmd.Flags().StringVar(&rootOptions.CacheLimit, "cache-limit", getEnvString("CACHE_LIMIT", "0"), "Cached packages count limit")
@@ -39,5 +41,6 @@ func run(cmd *cobra.Command, args []string) {
proxy.Server(npmproxy.ServerOptions{
ListenAddress: rootOptions.ListenAddress,
Silent: rootOptions.Silent,
}).ListenAndServe()
}

View File

@@ -23,3 +23,12 @@ func getEnvInt(env string, def string) int {
return converted
}
func getEnvBool(env string, def string) bool {
value := getEnvString(env, def)
// TODO: handle error
converted, _ := strconv.ParseBool(value)
return converted
}