我正在尝试在 golang 中测试我的数据库(Postgres)模型。问题是当我从数据库检索时,具有 time.Time 类型的字段值不匹配。这是代码:
a := myStruct{aTime: time.Now().UTC(), ...}
res, err := db.Exec("INSERT INTO my_table VALUES ($1, $2, ...) RETURNING id", a.aTime, ...)
...
// some logic for setting id in struct a
...
row := db.QueryRow("SELECT * FROM my_table WHERE id = $1", a.id)
var test *myStruct
row.Scan(test)
reflect.DeepEqual(a, test) // returns False
fmt.Printf("%v\n%v", a, test)
// {2020-02-25 12:37:16.906605805 +0000 UTC ...}
// {2020-02-25 12:37:16.906606 +0000 UTC ...}
Run Code Online (Sandbox Code Playgroud)
数据库中的时间字段类型为timestamp with time zone
。
我也尝试了以下方法:
a.aTime.Equal(test.aTime) // returns …
Run Code Online (Sandbox Code Playgroud) 目前,我的一项服务中有以下配置:
spec:
clusterIP: None
ports:
- name: grpc
port: 9000
protocol: TCP
targetPort: 9000
selector:
app: my-first-app
environment: production
group: my-group
type: ClusterIP
Run Code Online (Sandbox Code Playgroud)
在选择器部分,我需要添加另一个应用程序:
.
.
app: my-first-app my-second-app
.
.
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢!