草庐IT

is_io_type

全部标签

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 - 如何使用go客户端查询kubernetes自定义api(networking.gke.io/v1beta1)?

我想用gke玩kubernetesapi。但是gke使用特殊的api(networking.gke.io/v1beta1)。我想查询它,但是kubernetes的go-client没有这个api。如何查询?我尝试了RESTAPI,但完全不知道如何使用它,而且文档也不清楚。 最佳答案 GKE网络api和客户端在此repo中:gke-managed-certs客户端在这个包中:/pkg/clients 关于go-如何使用go客户端查询kubernetes自定义api(networking.g

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进行排序会有什么不同?这种情况更快? 最佳答案

reflection - 在 go 反射包中,调用 Value.Kind() 是 Value.Type().Kind() 的语法糖吗?

两个reflect.Type接口(interface)和reflect.Valuetype实现相同的Kind()方法签名,假设我们有一些值对象v:=reflect.ValueOf(x)v.Kind()只是调用v.Type().Kind()吗? 最佳答案 它们包含相同的值,但似乎指的不是同一件事:type.go来源value.go来源Type通常由未导出的结构rtype实现(通过TypeOf),而Value包含一个*rtype并扩展flag,它本身是Kind的简化形式://flagholdsmetadataaboutthevalue.

types - 我如何获得类型

我想从类型名称中获取(反射(reflect))类型。http://play.golang.org/p/c-9IpSafx0packagemainimport("fmt""reflect")typeNamestringfuncmain(){fmt.Println("Hello,playground")varnameName="Taro"fmt.Println(name)fmt.Println(getType(name))//fmt.Println(getType(Name))//wanttosameasgetType(name)}funcgetType(vinterface{})refl

go - 范围超过 `type x []struct` 或 `type y struct`?

似乎没有Ranger接口(interface)用于自定义类型。有什么类似的吗?或者我是否必须制作一个将类型转换为slice或映射的方法?编辑:我当然可以将x转换为[]struct,但这会使更改x的基础类型变得更加困难。 最佳答案 for循环的range变体不能扩展到自定义集合,这些集合不仅仅是重命名的slice、映射、字符串或channel。没有Ranger界面或类似的东西。如果您想遍历自定义类型,请考虑使用for循环,如下所示:forx,eof:=col.Next();x,eof=col.Next();!eof{//...}其中N

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

go - 为什么 IO.Writer 不填充接收器?

我正在尝试测试模板生成工具。为了做到这一点,我认为捕获模板执行输出的最简单方法是使用iowriter并在测试期间提供它。问题是由于某些原因,接收器没有使用模板输出“更新”。希望下面的代码能更好地解释我面临的问题。packagemainimport"fmt"import"text/template"typeCompanystruct{Namestring}typeCompanies[]Companyfuncmain(){s:=new(stringer)v:=Companies{Company{Name:"Sony"}}tmp:=template.Must(template.New("ma

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