草庐IT

server_is_down

全部标签

http - ListenAndServe 和 Server.Serve

有什么区别ln,err:=net.Listen("tcp",addr)iferr!=nil{returnerr}gosrv.Serve(ln)和ln,err:=net.Listen("tcp",addr)iferr!=nil{returnerr}returnsrv.Serve(tcpKeepAliveListener{ln.(*net.TCPListener)})?我正在创建我自己的ListenAndServe(第一个代码片段),以便我可以在调用我的ListenAndServe后立即执行代码并向我的服务器发送请求。但是,我无法使用tcpKeepAliveListener,因为它未导出。

docker - 去构建 : build output "api" already exists and is a directory

我正在尝试使用CompileDaemon热重载使用Docker的go项目。我的文件夹结构如下所示my-api-server-main.go-Dockerfile-docker-compose.yml-Makefile这是我得到的错误:gobuildgithub.com/firstApi/test-platform/lib/my-api/server:构建输出“server”已经存在并且是一个目录这是我的dockerfile的样子FROMgolang:1.12-stretchENVGO111MODULE=onWORKDIR/go/srcCOPYgo.mod.COPYgo.sum.RUNg

go - HTTP : server gave HTTP response to HTTPS client

我正在使用go来使用googlemapsgeocodingAPI,但我不断收到此错误:TheHTTPrequestfailedwitherrorGethttps://maps.googleapis.com/maps/api/geocode/json?address=Bangalore&key=KEY:http:servergaveHTTPresponsetoHTTPSclient错误中的url在我的浏览器中工作正常并给出适当的响应,但不会在下面的代码片段中给出我想要的:packagemainimport("fmt""io/ioutil""net/http")funcmain(){key

gorename : What is a 'DO NOT EDIT' marker?

我正在使用vscode并尝试重命名变量名称。它没有说:Renamefailed:gorename:cannotrenameidentifiersingeneratedfilecontainingDONOTEDITmarker:/home/adam/go/src/hello/hello.go那么什么是DONOTEDIT标记?为什么它在那里,我怎样才能删除它以便gorename可以做它的事情?我的文件是这样开始的:packagemain//#cgoCFLAGS:-g-Wall//#include//#include"c/greet.h"import"C"import("encoding/j

go - 是什么让 http.server 使用 HTTP/2?

我制作了两个Go程序,每个程序都尝试通过TLS向对方发送请求。换句话说,两个程序既充当客户端又充当服务器。但是,第一个客户端主机尝试使用HTTP/1.1连接到服务器主机,而服务器主机使用HTTP/2进行监听,这会导致错误。程序Aclient:=&http.Client{Transport:&http.Transport{TLSClientConfig:tlsConfig,},}mux:=httprouter.New()mux.GET("/test",test)serverTLS:=&http.Server{Addr:"127.0.0.1:8081",Handler:mux,TLSCon

mysql - 无法连接到 DB : database is closed

我有以下项目结构:-main.go-db--dbinit.go在dbinit.go中,我有以下代码:packagedbimport("database/sql"_"github.com/go-sql-driver/mysql")varDb*sql.DBvarerrerrorfuncinit(){Db,err=sql.Open("mysql","myDBCreds")deferDb.Close()}在main.go中我有:packagemainimport(db"./db")funcmain(){deferdb.Db.Close()sqlStatement:=`INSERTINTOtab

go - 错误 "protoc-gen-go: program not found or is not executable"

我正在尝试使用Go构建示例应用程序gRPC,但我无法使用“协议(protocol)”生成代码我已经使用以下方法安装了所需的库和Go包:goget-ugoogle.golang.org/grpcgoget-ugithub.com/golang/protobuf/protoc-gen-go我也试过设置路径,但没有成功。示例“原型(prototype)”文件:syntax="proto3";packagegreet;optiongo_package="greetpb";serviceGreetService{}错误信息:"protoc-gen-go:programnotfoundorisno

转到 : channel is necessary in this case?

http://play.golang.org/p/Xn3Qw7xAi3很难理解channel。我有funcmain(){in:=make(chanint)out:=make(chanint)goQuickSort(in,out)fori:=0;i这使得名为in、out和goroutine的两个channel成为函数Quicksort。1.QuickSort如何将in和out作为参数?它是否从下面的线路接收?in2。这种情况下使用channel是最佳的吗?动态地接收值看起来非常整洁……如果没有channel进行排序会有什么不同?这种情况更快? 最佳答案

select - golang : channel in select statement is only receiving sometimes (? ??)

我在从两个channel接收的go例程中有一个select语句。for{fmt.Printf("Waitingforselectstatement...\n")select{casereq:=如果调用函数两次发送到第一个channel然后发送到第二个channel一切正常:requestChan控制台输出(正确)是:>Waitingforselectstatement...>Igotarequest:{Loginyaylaswiese}>Waitingforselectstatement...>SendingtruetothedoneChannel>Igotarequest:{Sign

time - 戈朗 : throttle (time delay) function is not working in goroutine (works fine in main thread)

所以我正在编写一个实用程序来查询工作中的API,它们将每10秒限制为20次调用。很简单,我会将我的通话时间限制在自上次通话后至少0.5秒。在我尝试使用goroutine之前,我的Throttle实用程序运行良好。现在我正在使用结构/方法组合:func(c*CTKAPI)Throttle(){ifc.Debug{fmt.Println("\t\t\tEnteringThrottle()")}for{//incasesomethingelsemakesacallwhilewe'resleeping,weneedtore-checkift:=time.Now().Sub(c.LastCall