我是 Go 新手,正在尝试创建从 Jira 到 GitLab 的迁移脚本。 Jira API 库我正在使用这种类型从 Jira 读取问题创建时间:
// Time represents the Time definition of JIRA as a time.Time of go
type Time time.Time
GitLab API 客户端允许使用类型为
*time.Time
的字段创建具有创建时间的问题。
type CreateIssueOptions struct {
CreatedAt *time.Time `url:"created_at,omitempty" json:"created_at,omitempty"`
DueDate *ISOTime `url:"due_date,omitempty" json:"due_date,omitempty"`
// ...
}
如何将 Jira 时间转换为 GitLab 时间?我一直在尝试不同的选项,但无法理解它应该如何工作。
如果您有 Jira 结构:
type SomeStruct struct {
...
T Time
}
然后你可以简单地做:
tm:=time.Time(someStruct.T)
if !tm.IsZero() {
createIssue.CreatedAt=&tm
}