小编Tim*_*nov的帖子

Docker如何更改存储库名称或重命名图像?

我正在尝试更改图像的存储库名称:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
server              latest              d583c3ac45fd        26 minutes ago      685.5 MB
Run Code Online (Sandbox Code Playgroud)

因此,我想将名称更改server为类似myname/server:

REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
myname/server       latest              d583c3ac45fd        26 minutes ago      685.5 MB
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

docker linux-containers

515
推荐指数
6
解决办法
30万
查看次数

何时使用os.Exit()和panic()?

有人可以解释Go 之间的关键差异os.Exit()以及panic()它们在实践中的使用方式吗?

exit go

86
推荐指数
3
解决办法
4万
查看次数

Golang.用什么?http.ServeFile(..)或http.FileServer(..)?

我有点困惑.大多数例子都显示了两者的用法:http.ServeFile(..)http.FileServer(..),但似乎它们具有非常接近的功能.此外,我没有找到有关如何设置自定义NotFound处理程序的信息.

// This works and strip "/static/" fragment from path
fs := http.FileServer(http.Dir("static"))
http.Handle("/static/", http.StripPrefix("/static/", fs))

// This works too, but "/static2/" fragment remains and need to be striped manually
http.HandleFunc("/static2/", func(w http.ResponseWriter, r *http.Request) {
    http.ServeFile(w, r, r.URL.Path[1:])
})

http.ListenAndServe(":8080", nil)
Run Code Online (Sandbox Code Playgroud)

我试过阅读源代码,他们都使用serveFile(ResponseWriter, *Request, FileSystem, string, bool)底层函数.但是使用自己的方法http.FileServer返回并在提供文件之前进行一些准备工作(例如path.Clean()).fileHandlerServeHTTP()

那么为什么需要这种分离?哪种方法更好用?我如何设置自定义NotFound处理程序,例如找不到请求的文件?

go server

35
推荐指数
2
解决办法
4万
查看次数

如何使用"内部"包?

我尝试了解如何使用"内部"包来组织代码.让我展示一下我的结构:

project/
  internal/
    foo/
      foo.go # package foo
    bar/
      bar.go # package bar
  main.go

# here is the code from main.go
package main

import (
  "project/internal/foo"
  "project/internal/bar"
)
Run Code Online (Sandbox Code Playgroud)

project/在GOPATH树外面.无论我尝试从main.go无效的任何方式导入的路径,唯一正常工作的情况是import "./internal/foo|bar".我认为我做错了什么或者一般来说"内部"包装的想法是错误的.请问有人能让事情更清楚吗?

UPDATE

上面的例子是正确的,我唯一需要的是放置project/文件夹$GOPATH/src.所以事情是导入路径,project/internal/foo|bar如果我们只从project/子树而不是从外部导入它是可行的.

go

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

如何获取变量的内存大小?

有谁知道如何获得变量的内存大小(int,string,[]struct等),并打印出来?可能吗?

var i int = 1
//I want to get something like this:
fmt.Println("Size of i is: %?", i)
//Also, it would be nice if I could store the value into a string
Run Code Online (Sandbox Code Playgroud)

memory-management runtime go

22
推荐指数
4
解决办法
3万
查看次数

检查value是否实现接口的说明

我读过"Effective Go"和其他问答:golang界面兼容性编译类型检查,但是我无法正确理解如何使用这种技术.

请看例子:

type Somether interface {
    Method() bool
}

type MyType string

func (mt MyType) Method2() bool {
    return true
}

func main() {
    val := MyType("hello")

    //here I want to get bool if my value implements Somether
    _, ok := val.(Somether)
    //but val must be interface, hm..what if I want explicit type?

    //yes, here is another method:
    var _ Iface = (*MyType)(nil)
    //but it throws compile error
    //it would be great if someone explain the notation …
Run Code Online (Sandbox Code Playgroud)

interface type-conversion go

20
推荐指数
4
解决办法
2万
查看次数

一些运算符"|","^","&","&^"之间的差异.Golang

最近我读了golang规范并面对一些有趣的运算符:

&    bitwise AND            integers
|    bitwise OR             integers
^    bitwise XOR            integers
&^   bit clear (AND NOT)    integers
Run Code Online (Sandbox Code Playgroud)

我试过玩它,但我唯一理解的是"|" 添加整数和"+"运算符另外使用浮点数,字符串等.

它们在实践中用于什么?有人可以对上面的这4个运营商做出一些解释吗?

math operators go bitwise-operators

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

如何跳过Ansible中的角色执行

对不起我犯过的错误,我不是英国人.

我尝试为我的流浪汉机器编写playbook.yml,我遇到了以下问题.Ansible提示我设置这些变量,我将这些变量设置为null/false/no/[just enter],但无论如何都要执行角色!我该如何防止这种行为?如果没有设置变量,我只想要没有动作..

---
- name: Deploy Webserver
  hosts: webservers
  vars_prompt:
    run_common: "Run common tasks?"
    run_wordpress: "Run Wordpress tasks?"
    run_yii: "Run Yii tasks?"
    run_mariadb: "Run MariaDB tasks?"
    run_nginx: "Run Nginx tasks?"
    run_php5: "Run PHP5 tasks?"

  roles:
    - { role: common, when: run_common is defined }
    - { role: mariadb, when: run_mariadb is defined }
    - { role: wordpress, when: run_wordpress is defined }
    - { role: yii, when: run_yii is defined }
    - { role: nginx, when: run_nginx is defined …
Run Code Online (Sandbox Code Playgroud)

deployment webserver administration vagrant ansible

17
推荐指数
1
解决办法
2万
查看次数

如何杀死容器内的进程?Docker顶级命令

我在docker网站的官方指南中有一个简单的例子.

我执行以下操作:

sudo docker run -d ubuntu:latest /bin/sh -c "while true; do echo hello world; sleep 1; done"
a66asdasdhqie123...
Run Code Online (Sandbox Code Playgroud)

然后从创建的容器中获取一些输出:

sudo docker logs a66
hello
hello
hello
...
Run Code Online (Sandbox Code Playgroud)

然后我查找容器的运行进程:

sudo docker top a66
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                25055               15152               0                   20:07               ?                   00:00:00            /bin/sh -c while true; do echo hello world; sleep 1; done
root                25295               25055               0                   20:10               ?                   00:00:00            sleep 1
Run Code Online (Sandbox Code Playgroud)

接下来我尝试杀死容器的第一个进程:

sudo docker exec a66 kill -9 25055
Run Code Online (Sandbox Code Playgroud)

但是在我做完之后没什么变化.进程仍然有效并且每秒输出"你好".我错了什么?

unix command-line kill process docker

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

为什么带有`overflow:hidden`的`inline-block`元素的基线设置为其下边距?

读取两个伟大的答案解释的行为后inline-block元素(这是为什么inline-block的元素被推向下?为什么跨度的行高也没用)我仍然有两个原因不明的问题.

1.inline-block元素基线从其线框基线改为底边缘的原因是什么?

http://www.w3.org/TR/CSS2/visudet.html#leading

"内联块"的基线是正常流程中其最后一个线框的基线,除非它没有流入线框或者其"溢出"属性具有"可见"以外的计算值,在哪种情况下,基线是底部边缘边缘.

2.如何计算这种转变?

在此输入图像描述

重要提示:我不要试图找到一个解决方案如何解决它.我试着理解inline-block在应用元素时改变元素定位行为的原因是什么overflow: hidden.所以,请不要发布傻瓜的答案.

UPDATE

不幸的是,虽然我接受了答案,但我没有得到我想要的东西.我认为问题本身存在问题.关于第一个问题:我想了解为什么inline-block不能保留其线框的基线,即使它有overflow:hidden(当然,尽管有W3C规范).我想听听设计决定 - 不仅仅是必须设置一些东西,因为它要求W3C.第二个:我想得到一个公式,我们可以粘贴font-sizeline-height元素,并得到正确的结果.

无论如何感谢任何人:)

更新2

幸运的是,主观上找到了答案!看到第一个重新接受的答案.谢谢@pallxk!)

html css w3c overflow

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