go - 如何从 golang 中的 gherkin 数据表中解析具有 int 类型的列的空/null/nil 值?
问题描述
我想将小黄瓜数据表值转换为结构。在该结构中,我有一个声明了 int 类型的属性。如果小黄瓜数据表中没有数据,我应该如何填充值?在当前情况下,它会引发错误。
这是功能文件
Feature: send request
In order to be a rest tester
I need to be able to make rest requests to server
Scenario: GET request are allowed
When I send "GET" request to "http://localhost:3000/posts/"
Then the response code should be 200
And the response from server should match:
| Id | Title | Author | Worth |
| 1 | json-server | typicode | |
这是相应的结构:
type response struct {
Id int `json:"id"`
Title string `json:"title"`
Author string `json:"author"`
Worth int `json:"worth"`
}
使用这行代码将其转换为结构:
assist := assistdog.NewDefault()
expectedStruct := &response{}
result, err2 := assist.CreateSlice(expectedStruct, dataTable)
我在这种情况下遇到错误。谁能帮帮我?提前致谢 :)
解决方案
推荐阅读
- tomcat9 - 在 Tomcat 上托管的 Web 服务上放置请求时出现 409 错误
- google-sheets-formula - Query Function not working in Google Sheets
- java - 未找到参数,需要 javafx.stage.Stage
- javascript - 如何制作 HTML 标头 (
- javascript - Chrome 扩展程序:单击扩展程序图标时转到站点
- javascript - 制作一个抓取特定 HTML 行的 Chrome 扩展程序,第一次编码
- safari - 由于 Content-Security-Policy 问题,Safari 无法从 blob 创建 Worker
- python - 包装器的 Genism 模块属性错误
- google-sheets - 如果单元格中的日期是今天,则清除单元格
- c# - “LoggerSinkConfiguration”不包含“调试”的定义