首页 > 解决方案 > 如何从 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)

我在这种情况下遇到错误。谁能帮帮我?提前致谢 :)

标签: gogherkin

解决方案


推荐阅读