小编ken*_*ken的帖子

是dereference golang struct返回struct的新副本?

为什么当我们使用(*structObj)引用struct时,golang似乎返回structObj的新副本而不是返回原始structObj的相同地址?可能会对此产生一些误解,所以要求善意澄清

package main

import (
    "fmt"
)

type me struct {
    color string
    total int
}

func study() *me {
    p := me{}
    p.color = "tomato"
    fmt.Printf("%p\n", &p.color)
    return &p
}

func main() {
    p := study()
    fmt.Printf("&p.color = %p\n", &p.color)

    obj := *p
    fmt.Printf("&obj.color = %p\n", &obj.color)
    fmt.Printf("obj = %+v\n", obj)

    p.color = "purple"
    fmt.Printf("p.color = %p\n", &p.color)
    fmt.Printf("p = %+v\n", p)
    fmt.Printf("obj  = %+v\n", obj)

    obj2 := *p
    fmt.Printf("obj2 = %+v\n", obj2)
}
Run Code Online (Sandbox Code Playgroud)

产量

0x10434120
&p.color = 0x10434120 …
Run Code Online (Sandbox Code Playgroud)

struct pointers go dereference

11
推荐指数
3
解决办法
1万
查看次数

如何制作顶级git来跟踪另一个子目录git下的所有文件

命令序列

mkdir topdir
mkdir another-git-directory
touch fileC
touch fileD
git add.
git commit -m"sub-dir init"
cd ..
touch fileA
touch fileB
git add.
git commit -m"top-dir init"
git ls-files
//现在我们可以看到fileC和fileD没有被顶级git跟踪//
git ls-files -o
//这不会向我们展示fileC和fileD as untracked files //

我的问题是:如何让"git ls-files -o"显示子目录中未跟踪的文件?为什么git表现得如此,因为我希望git ls-files显示所有未跟踪的文件(即使它在另一个sub-dir git中)?

我知道我可以使用"git add*/."来制作顶级git来跟踪sub-dir文件......但我很想知道上面这个问题的原因.谢谢!

目录结构

 topdir +  
        +-- .git  
        +-- fileA  
        +-- fileB  
        + another-git-directory +-- .git  
                                +-- fileC  
                                +-- fileD  
Run Code Online (Sandbox Code Playgroud)

更新(6月26日)

我发现这个线程无法跟踪Git子模块中的文件和这个url(cn)http://blog.ossxp.com/2010/01/425/,它解释了如何解决问题.

解决方案:

git rm --cached another-git-directory #no trailing slash
git add another-git-directory /. …

git git-submodules

9
推荐指数
1
解决办法
1857
查看次数

具有代理协议的kubernetes nginx入口以损坏的标头结束

我尝试使用代理协议在Google容器上设置nginx入口(节点端口),以便可以将真实IP转发到后端服务,但最终报头损坏。

2017/02/05 13:48:52 [error] 18#18: *2 broken header: "?????~??]H?k??m[|????I??iv.?{y??Z ??v??q???2Iu4P?z;?    o$?s????"???+?/?,?0??????/" while reading PROXY protocol, client: 10.50.0.1, server: 0.0.0.0:443
Run Code Online (Sandbox Code Playgroud)

如果没有代理协议,一切都会很好。根据https://blog.mythic-beasts.com/2016/05/09/proxy-protocol-nginx-broken-header/,这是由于使用了v2协议(二进制),但是nginx只能说v1 。有什么建议吗?

nginx kubernetes real-ip proxy-protocol

5
推荐指数
1
解决办法
1898
查看次数