草庐IT

map-function

全部标签

map - 遍历 golang 结构的键和值由于某种原因没有给出相同的结果

我有一个这样的golang映射:varroutesmap[string]*rest.Route我像这样向它添加了一堆键/值:routes["Index"]=&rest.Route{"GET","/",handlers.GetIndex}routes["ListStudents"]=&rest.Route{"GET","/students",handlers.ListStudents}routes["ViewStudent"]=&rest.Route{"GET","/students/:id",handlers.ViewStudent}routes["CreateStudent"]=&r

go - 如何为 map 平铺器执行图像抽取?

已结束。此问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。关闭6年前。Improvethisquestion我正在为大图像的缩放级别18-1编写map平铺。我需要对图像进行下采样,以便缩放级别17的像素在18时为4像素,18是原始分辨率,所有图block均为256x256。我将如何在Go中执行此操作? 最佳答案 看看nfnt/resize.它是一个用于调整图像大小的库(但Google也会这样告诉你):func

go - 如何在 docker registry api 中为带有标签的图像名称创建 map[string][]string?

我正在使用DockerRegistryAPI,首先使用Listrepositories列出注册表中的所有图像方法,然后在图像中循环以创建一个map[string][]string:image[]tags使用Listingimagetags方法。我试过了funcGetImages(whttp.ResponseWriter,r*http.Request){w.Header().Set("Access-Control-Allow-Origin","*")res,err:=http.Get(fmt.Sprintf("%s/%s",sconf.RegistryConf.url,sconf.Reg

html - Golang 中的计数器 html 标签 map 无法正常工作

我遇到了一个问题。我需要编写一个函数来填充从元素名称(p、div、span等)到HTML文档树中具有该名称的元素数量的映射。我制作了函数outline2,它不工作,这是错误日志:htmlpanic:assignmenttoentryinnilmapgoroutine1[running]:panic(0x4c3b40,0xc042010a90)F:/Go/src/runtime/panic.go:500+0x1afmain.outline2(0x0,0xc0420320e0)F:/Go_Stuff/Books/Golang_stuff/exercises/src/gopl.io/ch5/

function - 将函数体/定义作为参数传递给 golang 中的函数调用

最近在使用golang的过程中遇到了如下问题。将函数体传递给函数调用是否可以,例如javascript。例如setTimeout(function(i){console.log("input:",i)},1000).在javascript中将匿名函数传递给另一个函数是很常见的。我想知道在go中是否相同?packagemainimport("fmt")typeHandlerFuncfunc(int)funcmain(){//defineafunctionasobject/variable?hnd:=func(inint){fmt.Println("funchandlerreturnsin

function - 在 Go 中将函数作为参数传递

我尝试在Go中创建一个函数,用于重试任何失败的查询函数(通常是因为序列化问题)。funcretryer(functionAfunc(interface{})(interface{},[]error),maxRetryint,waitBetweentime.Duration)interface{}{//whennoerrorinfunctionA,retryerreturnswhateverfunctionAreturns//whenmaxRetryisreached,returnsnil}我想重试的函数看起来像这样funcGetTopStudent(classIdstring)([]S

戈朗 : Passing structs as parameters of a function

尝试通过在线类(class)自学围棋。而且我正在尝试稍微偏离路线以扩展我的学习。该类(class)让我们使用几个变量编写一个简单的函数,该函数将获取这两个变量并打印出一行。所以我有:funcmain(){vargreeting:="hello"varname:="cleveland"message:=printMessage(greeting,name)fmt.Println(message)}funcprintMessage(greetingstring,namestring)(messagestring){returngreeting+""+name+"!"}稍后类(class)介

go - map[string]interface{} 的类型嵌套映射返回 "type interface {} does not support indexing"

我在使用类型嵌套map时遇到了一个非常奇怪的问题。goreversion0.2.6:helpforhelpgore>typeMmap[string]interface{}gore>m:=M{"d":M{}}main.M{"d":main.M{}}gore>m["d"]["test"]="willfail"#command-line-arguments/tmp/288178778/gore_session.go:13:8:invalidoperation:m["d"]["test"](typeinterface{}doesnotsupportindexing)/tmp/288178778

sorting - 根据值(结构的属性)对 map 进行排序

我有下面的map:detail:=make(map[string]*Log)typeLogstruct{Id[]stringName[]stringPriorityint//valuecouldbe1,2,3Messagestring}我想根据在我的例子中是结构的值对“详细信息”映射进行排序。这应该按属性“优先级”排序。例如,Log(结构映射)可能具有类似于以下的值:Z:&{[ba60][XYZ]3"Iamtheboss"}B:&{[ca50][ABC]2"IamtheJunior"}U:&{[zc20][PQR]1"IamtheNewbie"}我希望他们按递增的优先级顺序打印,即1到

go - 根据具有 map[string] 接口(interface)项的值对 slice 进行排序

修改后真实情况与示例数据略有不同。我有一个表,其中包含与我在应用程序中使用的用户界面相关的所有字段和属性。我需要一个按listorder排序的简单slice,它只有这样的字段名称列表。colons=[]string{'id','name','population','phonecode'}但数据源是一个slice,由map[string]interface{}值组成,这些值来自这样的sql查询selectfieldname,label,listorderfromtablefieldswheretablename="city"orderbyfieldnamefields:=[]map[s