小编Mar*_*ers的帖子

减去时间.在Go中持续时间

我有一个time.Time价值time.Now(),我希望得到另一个时间,正好是1个月前.

我知道减法是可能的time.Sub()(它想要另一个time.Time),但这将导致a time.Duration,我需要它反过来.

go

91
推荐指数
4
解决办法
7万
查看次数

具体检查超时错误

我在调用webservice时使用以下内容检查超时,但我想特别检查是否返回了超时错误.我该怎么做:S

我有这个:

// Timeout
type Timeout struct {
    Connect   time.Duration
    ReadWrite time.Duration
}

// TimeoutDialer
func TimeoutDialer(timeout *Timeout) func(net, addr string) (c net.Conn, err error) {
    return func(netw, addr string) (net.Conn, error) {    
        conn, err := net.DialTimeout(netw, addr, timeout.Connect)
        if err != nil {
            return nil, err
        }
        conn.SetDeadline(time.Now().Add(timeout.ReadWrite))
        return conn, nil
    }
}

// HttpClient
func HttpClient(config Config) *http.Client {
    to := &Timeout{
        Connect:   time.Duration(config.MaxWait) * time.Second,
        ReadWrite: time.Duration(config.MaxWait) * time.Second,
    }

    return &http.Client{
        Transport: &http.Transport{
            Dial: TimeoutDialer(to),
        }, …
Run Code Online (Sandbox Code Playgroud)

go

29
推荐指数
3
解决办法
2万
查看次数

Golang"最佳实践"来处理与数据库的连接

我有一个用Go编写的web服务,目前我有这个全局包我随处导入,包含与MongoDB的连接(通过MGO),但我不得不说这对我来说非常狡猾.在Go中维护与数据源的连接的最佳实践是什么?我来自PHP世界,因此Global:S

go mgo

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

Google Cloud 容器引擎上的 HTTPS

我有一些在 Google Cloud Container Engine 上运行的容器,它们通过 http 运行良好,但我想知道为这些服务启用 https/ssl 终止的理想设置是什么。

是否可以直接在 GCCE 中(或通过 kubernetes)执行此操作,或者我应该设置一个 nginx 虚拟机并内部链接到容器(这可能会导致分配给容器的动态 IP 出现问题)。

google-kubernetes-engine

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

Docker容器中SizeRootFs和SizeRw之间的确切区别是什么?

在docker容器列表中,您可以获得容器大小SizeRootFs和SizeRw,但我找不到大小的确切含义.

docker docker-api

4
推荐指数
1
解决办法
592
查看次数

按ElasticSearch中数字字段的距离排序

对于项目,我需要选择过滤器范围内和最接近数值的文档.这是一个价格,我似乎无法找到这是否可能.

说我有2个文件:

{
    "name": "Document1",
    "price": 46.12,
    "tags": ["tag1", "tag2"]
}
{
    "name": "Document2",
    "price": 82.29,
    "tags": ["tag1", "tag3"]
}    
Run Code Online (Sandbox Code Playgroud)

是否有可能获得最接近66.23的价格的文件?

elasticsearch

4
推荐指数
1
解决办法
786
查看次数

Arcanist给出了分段错误11

我做了一个arc install-certificate但是每次做一次电弧调用都会返回一个"Segmentation fault:11".我确实输入了令牌.弧差的痕迹对我没有多大帮助:

$ arc diff --trace
libphutil loaded from '/xxx/arcinstall/libphutil/src'.
arcanist loaded from '/xxx/arcinstall/arcanist/src'.
Config: Reading user configuration file "/xxx/.arcrc"...
Config: Did not find system configuration at "/etc/arcconfig".
Working Copy: Reading .arcconfig from "/xxx/.arcconfig".
Working Copy: Path "/xxx" is part of `git` working copy "/xxx".
Working Copy: Project root is at "/xxx".
Config: Did not find local configuration at "/xxx/.git/arc/config".
>>> [0] <conduit> user.whoami() <bytes = 117>
>>> [1] <http> https://xxx.xx.xx/api/user.whoami
<<< [1] <http> 327,750 us
<<< [0] <conduit> …
Run Code Online (Sandbox Code Playgroud)

phabricator arcanist

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