我想安装php54-redis.
Yu:nginx Yu $ brew安装josegonzalez/php/php54-redis
==>从josegonzalez/homebrew-php安装php54-redis
错误:在多个水龙头中找到的公式:
自制/ PHP/php54
josegonzalez/PHP/php54
请使用完全限定的名称,例如homebrew/php/php54来引用公式.
我做错了什么,这是怎么做得好的?
这是示例代码:
package main
import (
"fmt"
)
type A struct {
Name string
}
func (this *A) demo(tag string) {
fmt.Printf("%#v\n", this)
fmt.Println(tag)
}
func main() {
var ele A
ele.demo("ele are called")
ele2 := A{}
ele2.demo("ele2 are called")
}
Run Code Online (Sandbox Code Playgroud)
运行结果:
&main.A{Name:""}
ele are called
&main.A{Name:""}
ele2 are called
Run Code Online (Sandbox Code Playgroud)
它看起来像那些是相同的约var ele A和ele2 := A{}
因此,struct的Zero值不是nil,而是一个结构,所有属性都被初始化为零值.猜对了吗?
如果猜测是正确的,那么的自然var ele A和ele2 := A{}是一样的吧?我不确定.
我有一个大小的字节数组,我做了之后md5.Sum().
data := []byte("testing")
var pass string
var b [16]byte
b = md5.Sum(data)
pass = string(b)
Run Code Online (Sandbox Code Playgroud)
错误:
cannot convert b (type [16]byte) to type string
Run Code Online (Sandbox Code Playgroud)
我找到了解决这个问题的方法
改成:
pass = string(b[:])
Run Code Online (Sandbox Code Playgroud)
但为什么不能这样使用呢?
pass = string(b)
Run Code Online (Sandbox Code Playgroud) 这段代码在builti.go中
// The append built-in function appends elements to the end of a slice. If
// it has sufficient capacity, the destination is resliced to accommodate the
// new elements. If it does not, a new underlying array will be allocated.
// Append returns the updated slice. It is therefore necessary to store the
// result of append, often in the variable holding the slice itself:
// slice = append(slice, elem1, elem2)
// slice = append(slice, anotherSlice...)
// As a …Run Code Online (Sandbox Code Playgroud) 这是代码:
package main
import (
"fmt"
)
type demo struct {
name string
}
func main() {
demo_slice := make([]demo, 3)
demo_slice[0] = demo{"str1"}
demo_slice[1] = demo{"str2"}
demo_slice[2] = demo{"str3"}
point_demo_slice := make([]*demo, 3)
for index, value := range demo_slice {
fmt.Printf("\n%v==++++++++++++++%p\n", value, &value)
point_demo_slice[index] = &value
}
}
Run Code Online (Sandbox Code Playgroud)
结果:
{str1}==++++++++++++++0x20818a220
{str2}==++++++++++++++0x20818a220
{str3}==++++++++++++++0x20818a220
Run Code Online (Sandbox Code Playgroud)
0x20818a220 是最后一个元素的指针值.
为什么所有指针值都相同?
如何获得正确的指针值?