首页 > 在Golang中需要自定义一种结构,用来保存可追溯证据链以及结果,我该如何设置?

在Golang中需要自定义一种结构,用来保存可追溯证据链以及结果,我该如何设置?

我最近在做一个风控模型,里面涉及到某要看一个人的消费记录,比如他买过什么东西,买过多少次,以及是什么时候买的,同时,我还需要记录下证据,这些数据需要给风控人员看的,模型是使用 Golang 写的。


直接上代码吧:

package main

type EvidencedBoolReport struct {
    Label     string         `json:"label,string"`
    Value     bool           `json:"value,bool"`
    Evidences []*interface{} `json:"evidences"`
}

// 创建新的可追溯证据链的报告项
func NewEvidencedBoolReport(label string, evidences []*interface{}) (ebr EvidencedBoolReport) {
    ebr.Label = label
    if evidences != nil {
        ebr.Evidences = evidences
        ebr.Value = len(ebr.Evidences) > 0
    }
    return
}

func (ebr *EvidencedBoolReport) SetValue(value bool) {
    ebr.Value = value
}

// 添加证据
func (ebr *EvidencedBoolReport) AddEvidence(evidence *interface{}) {
    ebr.Value = true
    ebr.Evidences = append(ebr.Evidences, evidence)
}

这里面只写了是否为XX的实现,更多的,比如要计算次数的等等的,更复杂一点儿,我也是刚接触这个行业,最主要的是居然还都选择了 Go

【热门文章】
【热门文章】