go打印结构数组只打印指针值

时间:2018-05-21 16:46:24

标签: go

使用以下代码

checks := checkDeployment.CheckAll().All()
fmt.Printf("checks: %+v\n", checks[0])
fmt.Printf("checks: %+v\n", checks)

我得到了这个输出

checks: &{name:CheckUpdateStrategy serviceState:0 message:everything ok}
checks: [0xc42050b9e0]

为什么将数组打印为指针的值而不是像单个元素那样格式化?

type (
    // ServiceCheckResults contains multiple results for service checks
    ServiceCheckResults interface {
        All() []ServiceCheckResult
    }

    serviceCheckResultsImpl struct {
        results map[string]ServiceCheckResult
    }
)

// All returns all values from the set
func (r *serviceCheckResultsImpl) All() []ServiceCheckResult {
    values := []ServiceCheckResult{}
    for _, value := range r.results {
        values = append(values, value)
    }
    return values
}

0 个答案:

没有答案