当前位置:首页 > 机动车 >

code500什么意思

来源:原点资讯(www.yd166.com)时间:2023-05-19 07:05:23作者:YD166手机阅读>>

这是 pkg.go.dev 设计与实现的第二篇:本地搭建一个 pkg.go.dev。

为了更好了解这个项目,我们尝试在本地搭建一个。这里假定你在本地安装好了 postgres,同时设置了 postgres 账号的密码为 123456,并执行了上文提到的迁移程序,创建好了需要的数据表。

本地搭建可以基于 Docker,本文采用非 Docker 的方式。

Frontend

最简单的启动 Frontend 的方式是直接执行如下命令:

$goruncmd/frontend/main.go

发现报错,提示 postgres 需要密码。

2020/06/2017:59:50Error:database.Open("postgres-ocsql-0","user='postgres'password=REDACTEDhost='localhost'port=5432dbname='discovery-db'sslmode=disableoptions='-cstatement_timeout=600000'"):pq:passwordauthenticationfailedforuser"postgres" exitstatus1

我们先不处理这个问题,看看 frontend 程序有无 flag 可以设置。

$goruncmd/frontend/main.go-h

输出如下:

-dev enabledevelopermode(reloadtemplatesoneachpageload,servenon-minifiedJS/CSS,etc.) -direct_proxy ifsettotrue,usesthemoduleproxyreferredtobythisURLasadirectbackend,bypassingthedatabase -proxy_urlstring UsesthemoduleproxyreferredtobythisURLfordirectproxymodeandfrontendfetches(default"https://proxy.golang.org") -staticstring pathtofoldercontainingstaticfilesserved(default"content/static") -third_partystring pathtofoldercontainingthird-partylibraries(default"third_party") exitstatus2

不一一解释,英文说明很清楚。这里着重看 -direct_proxy 和 -proxy_url,通过 direct_proxy 似乎可以绕开 postgres,但由于默认的 proxy(proxy.golang.org)国内不可访问,因此同时设置一个 proxy:

$goruncmd/frontend/main.go-direct_proxy-proxy_url=https://goproxy.cn

输出如下:

config:{ "ProxyURL":"https://proxy.golang.org", "IndexURL":"https://index.golang.org/index", "Port":"", "DebugPort":"", "ProjectID":"", "ServiceID":"", "VersionID":"", "ZoneID":"", "InstanceID":"", "LocationID":"us-central1", "GaeEnv":"", "AppMonitoredResource":{ "type":"gae_app", "labels":{ "module_id":"", "project_id":"", "version_id":"", "zone":"" } }, "FallbackVersionLabel":"20200620t181347", "DBSecret":"", "DBUser":"postgres", "DBHost":"localhost", "DBPort":"5432", "DBName":"discovery-db", "DBSecondaryHost":"", "RedisCacheHost":"", "RedisCachePort":"6379", "RedisHAHost":"", "RedisHAPort":"6379", "UseProfiler":false, "Quota":{ "QPS":10, "Burst":20, "MaxEntries":1000, "RecordOnly":true, "AcceptedURLs":null } } 2020/06/2018:13:47Info:NotexportingtoStackDriver:GOOGLE_CLOUD_PROJECTisunset. 2020/06/2018:13:47Info:Listeningonaddrlocalhost:8080

打开浏览器访问 localhost:8080:

code500什么意思,(1)

一切似乎很顺利。打开某个库,第一次稍微慢点,之后很快,从控制台输出的日志也能看到。

2020/06/2018:16:39Info:0/github.com/gin-gonic/ginrequeststart 2020/06/2018:16:44Debug:memoryafterfetchofgithub.com/gin-gonic/gin@v1.6.3:24M 2020/06/2018:16:44Info:302/github.com/gin-gonic/ginrequestend 2020/06/2018:16:44Info:0/github.com/gin-gonic/ginrequeststart 2020/06/2018:16:45Debug:memoryafterfetchofgithub.com/gin-gonic/gin@latest:26M 2020/06/2018:16:45Info:200/github.com/gin-gonic/ginrequestend 2020/06/2018:19:37Info:0/github.com/gin-gonic/ginrequeststart 2020/06/2018:19:37Info:302/github.com/gin-gonic/ginrequestend

但访问标准库,如 database/sql,却报错:(同时页面显示 500)

2020/06/2018:24:05Info:0/database/sqlrequeststart 2020/06/2018:24:35Debug:memoryafterfetchofstd@latest:17M 2020/06/2018:24:35Error:GetPackage("database/sql","latest"):getModule("std","latest"):FetchModule("std","latest"):stdlib.Zip("latest"):Versions():Get"https://go.googlesource.com/go/info/refs?service=git-upload-pack":dialtcp216.239.37.1:443:i/otimeout 2020/06/2018:24:35Info:500/database/sqlrequestend 2020/06/2018:24:35Info:0/static/img/gopher-airplane.svgrequeststart 2020/06/2018:24:35Info:200/static/img/gopher-airplane.svgrequestend

很显然,在去获取 Go 仓库信息时,因为 go.googlesource.com 在国内无法访问导致错误。然而我科学上网后并没有解决问题:

2020/06/2018:31:23Info:0/database/sqlrequeststart 2020/06/2018:31:25Debug:memoryafterfetchofstd@latest:77M 2020/06/2018:31:25Error:GetPackage("database/sql","latest"):getModule("std","latest"):FetchModule("std","latest"):stdlib.Zip("latest"):invalidargument:requestedversionunknown:"latest" 2020/06/2018:31:25Info:500/database/sqlrequestend 2020/06/2018:31:33Info:0/database/sqlrequeststart 2020/06/2018:31:33Error:middleware.Panic:runtimeerror:invalidmemoryaddressornilpointerdereference 2020/06/2018:31:33Info:500/database/sqlrequestend

我们先不细究这个问题。用上数据库试试。

现在解决数据库密码的问题。从启动时输出的 config 可以猜到,数据库信息在 config 中。前文提到,pkgsite 并没有用到配置文件,所有的配置通过环境变量来设置。

在 internal/config/config.go 文件中找到了这行代码:

cfg.DBPassword=os.Getenv("GO_DISCOVERY_DATABASE_PASSWORD")

因此这样启动 Frontend:

$GO_DISCOVERY_DATABASE_PASSWORD=123456goruncmd/frontend/main.go

这回成功了,访问 localhost:8080 也正常显示了。然而查看包都返回 404,包括标准库和第三方包。

code500什么意思,(2)

前文讲解过,pkgsite 就是这么设计的,数据库现在是空的,需要通过 Worker 往里面填充数据。

Worker

同样的采用最简单的方式运行:

$GO_DISCOVERY_DATABASE_PASSWORD=123456goruncmd/worker/main.go

  • 注意上面 postgres 密码的问题

启动后,发现监听 8000 端口:

2020/06/2018:47:29Info:Listeningonaddrlocalhost:8000

看看长什么样:

code500什么意思,(3)

顶部的一些链接,都是 google cloud 的,本地没有意义。

根据前面讲解,Worker 数据最终是从 Module Index 和 Module Proxy 来的,而且 Worker 不会自己触发,必须外界调用它提供的接口。上面界面中可以看到,通过点击上面的几个按钮可以执行拉取:

  • Enqueue From Module Index:从 Module Index 入队列以便处理;
  • Requeue Failed Versions:对失败的版本重入队列;
  • Reprocess Versions:重新处理;
  • Populate Standard Library:填充标准库数据;

很惨的是,Enqueue From Module Index 和 Populate Standard Library 都失败。

code500什么意思,(4)

吐槽一句:在国内做技术真难!

除了这种方式,还有一种手动获取某个版本的办法,比如在浏览器请求 http://localhost:8000/fetch/github.com/gin-gonic/gin/@v/v1.6.3,发现页面报 500,终端出现如下错误:

2020/06/2114:58:23Error(map[fetch:github.com/gin-gonic/gin@v1.6.3]):Errorexecutingfetch:FetchModule("github.com/gin-gonic/gin","v1.6.3"):proxy.Client.GetInfo("github.com/gin-gonic/gin","v1.6.3"):Client.readBody("github.com/gin-gonic/gin","v1.6.3","info"):ctxhttp.Get(ctx,client,"https://proxy.golang.org/github.com/gin-gonic/gin/@v/v1.6.3.info"):Get"https://proxy.golang.org/github.com/gin-gonic/gin/@v/v1.6.3.info":dialtcp34.64.4.113:443:i/otimeout(code500)

这是通过 proxy.golang.org 获取包模块信息。针对 Frontend,我们可以修改 proxy,Worker 可以修改吗?

可惜的是,Worker 并没有提供相关 flag 可以修改,但在 config.go 中发现了环境变量:GO_MODULE_PROXY_URL 和 GO_MODULE_INDEX_URL,默认分别是:https://proxy.golang.org 和 https://index.golang.org/index。proxy 我们可以设置为国内的 https://goproxy.cn,index 没有国内的可用。但对于手动获取某一个版本,设置 proxy 即可。通过如下方式重启 Worker:

$GO_MODULE_PROXY_URL=https://goproxy.cnGO_DISCOVERY_DATABASE_PASSWORD=123456goruncmd/worker/main.go

再次访问 http://localhost:8000/fetch/github.com/gin-gonic/gin/@v/v1.6.3,显示成功:

fetchedandupdatedgithub.com/gin-gonic/gin@v1.6.3 OK

回过头看看 http://localhost:8080/github.com/gin-gonic/gin,发现正常显示了,数据库中也有相应的数据了。但这种方式一次只能搞定一个包的一个版本。

福利:国内访问 pkg.go.dev 比较慢,有时甚至无法访问,因此我搭建了一个镜像:https://pkg.golangclub.com。

栏目热文

人生模拟器4手机版怎么下(人生模拟器4中文版下载手机版)

人生模拟器4手机版怎么下(人生模拟器4中文版下载手机版)

《模拟人生4》最新扩展包“乡间生活”公开实机中文宣传片,DLC 7月22日 发售。“和家人一起使用最新鲜的食材大展厨艺,...

2023-05-19 07:02:36查看全文 >>

人生模拟器4官网(人生模拟器4手机版怎么下载)

人生模拟器4官网(人生模拟器4手机版怎么下载)

英文名称:The Sims 4: Kids Room游戏类型:模拟经营类(SIM)游戏游戏制作:Maxis/The Si...

2023-05-19 06:55:22查看全文 >>

人生模拟器(人生模拟器下载安装)

人生模拟器(人生模拟器下载安装)

各位看官们,大家好。又到了日常推荐精彩小说的时刻了,笔者每天都会为大家整理出一些有趣的小说分享给大家,可以让书迷们能够更...

2023-05-19 07:09:40查看全文 >>

人生模拟器4绅士版(人生模拟器4绅士版怎么设置中文)

人生模拟器4绅士版(人生模拟器4绅士版怎么设置中文)

《模拟人生4(The Sims 4)》是由Maxis/The Sims Studio联合制作,EA发行的一款模拟经营类游...

2023-05-19 06:51:03查看全文 >>

人生模拟器四(人生模拟器视频全集)

人生模拟器四(人生模拟器视频全集)

小说:人生模拟器:我开局首战得胜,全被一姐直播了陆仁类型:军事历史作者:萌妹冰冰角色:陆仁周姐小说《人生模拟器:我开局首...

2023-05-19 06:52:09查看全文 >>

服务器内部错误500如何解决(http500内部服务器错误怎么解决)

服务器内部错误500如何解决(http500内部服务器错误怎么解决)

win10系统用户反映,https网站打不开,系统提示:http 500 内部服务器错误,今天为大家分享http 500...

2023-05-19 06:43:44查看全文 >>

code1000是什么意思(code=1000啥意思)

code1000是什么意思(code=1000啥意思)

精学单词之code code英 /kəʊd/ 美 /kod/解释:它作名词的时候意思是“代码”,而作动词的时候表示“...

2023-05-19 06:49:34查看全文 >>

errorcode:500是什么意思(错误代码1-500怎么解决)

errorcode:500是什么意思(错误代码1-500怎么解决)

⼀:500错误1、500 Internal Server Error 内部服务错误:顾名思义500错误⼀般是服务器遇到意...

2023-05-19 07:00:22查看全文 >>

code400什么意思(code94是什么意思啊)

code400什么意思(code94是什么意思啊)

作为一名技术人员,对常见的HTTP协议状态码需要了如指掌,才能对日常工作游刃有余,下面小编将结合盛邦安全三款产品——we...

2023-05-19 06:35:36查看全文 >>

code25什么意思(code128是什么意思中文)

code25什么意思(code128是什么意思中文)

条码软件支持多种条码码制,码制不同,应用行业不同。今天主要给大家介绍的是纸箱上常用的条形码码制,有需求的可以参考:1.目...

2023-05-19 07:06:46查看全文 >>

文档排行