跳到主要内容
Didit 融资 750 万美元,打造身份与欺诈基础设施
Didit
返回博客
博客 · 2026年3月7日

使用 Didit 原语在 Go 中实现可扩展的身份验证 (ZH)

探索如何在 Go 中为自定义身份检查设计灵活的插件架构,利用 Didit 的模块化身份原语。这种方法实现了可扩展、适应性强的验证工作流,可以轻松应对不断变化的需求。.

作者:Didit更新于
extensible-identity-checks-in-go-with-didits-primitives.png

模块化设计,敏捷应对在 Go 中构建可扩展的插件架构,使企业能够快速适应不断变化的合规法规和新的欺诈手段,而无需彻底改造整个身份验证系统。

利用 Go 的优势Go 强大的类型、性能和并发特性使其成为开发能够处理高吞吐量的健壮且可扩展的身份验证服务的理想语言。

Didit 原语的可组合性集成 Didit 的 AI 原生身份原语,例如身份验证、被动与主动活体检测和 AML 筛选,提供了强大的预构建组件,可以在自定义 Go 插件中进行编排。

Didit 的开发者优先方法Didit 简洁的 API、即时沙盒和模块化架构非常适合构建可扩展系统的开发人员,提供免费的核心 KYC 且无设置费用,以加速开发。

对可扩展身份验证的需求

在当今快速变化的数字环境中,身份验证 (IDV) 不再是一个静态过程。法规不断演变,新的欺诈技术层出不穷,业务需求也在变化。僵化、单一的 IDV 系统很快就会成为瓶颈,阻碍创新并增加合规风险。这就是为什么可扩展的插件架构不仅仅是一种奢侈品,而是一种必需品,特别是对于使用高性能语言(如 Go)的开发人员而言。

可扩展架构允许企业动态添加、删除或修改身份检查,而无需重新部署整个服务。这种敏捷性对于适应特定区域的 KYC(了解您的客户)要求、集成尖端欺诈检测机制或尝试新的用户入职流程至关重要。例如,企业最初可能需要基本的身份验证和活体检测。随后,他们可能需要为特定产品添加年龄估算或为金融交易整合 AML 筛选。基于插件的系统可以无缝处理这些添加。

在 Go 中设计插件架构

Go 的接口驱动设计和强类型使其成为构建健壮插件系统的绝佳选择。核心思想是定义一个所有身份检查“插件”都必须实现的通用接口。此接口充当契约,确保任何新的检查都可以无缝集成到现有工作流中。

定义身份检查接口

让我们考虑一个简单的身份检查接口:

package main

type IdentityCheckResult struct {
    Passed  bool
    Details string
}

type IdentityChecker interface {
    Name() string
    Execute(data map[string]interface{}) (IdentityCheckResult, error)
}

在这里,IdentityChecker 定义了两个方法:Name() 用于识别插件,Execute() 用于执行实际检查,它接受通用输入数据并返回结果。这种抽象允许进行各种检查,从文档验证到生物识别分析。

使用 Didit 原语实现自定义检查

现在,让我们看看如何使用 Didit 强大的原语在此插件框架中实现特定的身份检查。Didit 的模块化架构、简洁的 API 和 AI 原生能力使得集成这些高级服务变得简单直接。

示例:Didit 身份验证插件

对于基于文档的身份验证,我们可以创建一个插件,利用 Didit 的身份验证产品,该产品包括对 220 多个国家/地区的 OCR、MRZ 和条形码扫描。此插件将文档图像和数据发送到 Didit 的 API 并处理响应。

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

type DiditIDVCheck struct{}

func (d *DiditIDVCheck) Name() string {
    return "DiditIDVerification"
}

func (d *DiditIDVCheck) Execute(data map[string]interface{}) (IdentityCheckResult, error) {
    documentImage, ok := data["documentImage"].(string)
    if !ok {
        return IdentityCheckResult{Passed: false, Details: "Missing document image"}, nil
    }

    // In a real application, you'd send the image to Didit's ID Verification API.
    // For this example, we'll simulate a call.
    // Documentation: https://docs.didit.me/core-technology/id-verification

    // Simulate API call to Didit's ID Verification
    // Replace with actual API call and error handling
    fmt.Printf("Calling Didit ID Verification for image: %s...\n", documentImage[:20]) // Truncate for display
    
    // Assume a successful response for demonstration
    if documentImage != "invalid_id_image" {
        return IdentityCheckResult{Passed: true, Details: "ID document verified by Didit."}, nil
    } else {
        return IdentityCheckResult{Passed: false, Details: "ID document verification failed by Didit." + " Invalid image provided."},
            fmt.Errorf("Didit ID Verification failed")
    }
}

示例:Didit 活体检测插件

为了对抗深度伪造和演示攻击,活体检测至关重要。Didit 提供被动和主动活体检测。插件可以集成此功能,处理短视频或一系列图像。

package main

type DiditLivenessCheck struct{}

func (d *DiditLivenessCheck) Name() string {
    return "DiditLivenessDetection"
}

func (d *DiditLivenessCheck) Execute(data map[string]interface{}) (IdentityCheckResult, error) {
    livenessVideo, ok := data["livenessVideo"].(string)
    if !ok {
        return IdentityCheckResult{Passed: false, Details: "Missing liveness video"}, nil
    }

    // Simulate API call to Didit's Liveness Detection
    // Replace with actual API call and error handling
    fmt.Printf("Calling Didit Liveness Detection for video: %s...\n", livenessVideo[:20])

    if livenessVideo != "deepfake_video" {
        return IdentityCheckResult{Passed: true, Details: "Liveness detected by Didit."}, nil
    } else {
        return IdentityCheckResult{Passed: false, Details: "Liveness detection failed by Didit." + " Deepfake detected."},
            fmt.Errorf("Didit Liveness Detection failed")
    }
}

使用插件编排工作流

一旦有了插件,就需要一种机制来将它们编排成一个连贯的工作流。Didit 的编排工作流为此提供了无代码可视化构建器,但如果您正在构建自定义 Go 服务,则可以以编程方式管理此逻辑。

package main

import "fmt"

// A simple orchestrator
type Workflow struct {
    Checks []IdentityChecker
}

func (w *Workflow) AddCheck(checker IdentityChecker) {
    w.Checks = append(w.Checks, checker)
}

func (w *Workflow) Run(userData map[string]interface{}) ([]IdentityCheckResult, error) {
    var results []IdentityCheckResult
    for _, check := range w.Checks {
        fmt.Printf("\nRunning %s check...\n", check.Name())
        res, err := check.Execute(userData)
        results = append(results, res)
        if err != nil || !res.Passed {
            fmt.Printf("Check %s failed: %s\n", check.Name(), res.Details)
            return results, fmt.Errorf("workflow failed at %s: %w", check.Name(), err)
        }
        fmt.Printf("Check %s passed: %s\n", check.Name(), res.Details)
    }
    return results, nil
}

func main() {
    workflow := &Workflow{}
    workflow.AddCheck(&DiditIDVCheck{})
    workflow.AddCheck(&DiditLivenessCheck{})

    // Example user data
    userData := map[string]interface{}{
        "documentImage": "valid_passport_image_base64",
        "livenessVideo": "valid_liveness_video_base64",
        "name":          "Jane Doe",
    }

    fmt.Println("--- Running successful workflow ---")
    results, err := workflow.Run(userData)
    if err != nil {
        fmt.Printf("Workflow completed with errors: %v\n", err)
    } else {
        fmt.Println("Workflow completed successfully!")
    }
    for _, r := range results {
        fmt.Printf("- %s: Passed = %t, Details = %s\n", r.Name, r.Passed, r.Details)
    }

    // Example of a failing workflow
    fmt.Println("\n--- Running failing workflow (invalid ID) ---")
    failingUserData := map[string]interface{}{
        "documentImage": "invalid_id_image",
        "livenessVideo": "valid_liveness_video_base64",
        "name":          "John Smith",
    }
    failingResults, err := workflow.Run(failingUserData)
    if err != nil {
        fmt.Printf("Workflow completed with errors: %v\n", err)
    } else {
        fmt.Println("Workflow completed successfully!")
    }
    for _, r := range failingResults {
        fmt.Printf("- %s: Passed = %t, Details = %s\n", r.Name, r.Passed, r.Details)
    }
}

这个简单的协调器按顺序执行检查。在实际场景中,您可能会添加条件逻辑、并行执行或重试,以模仿 Didit 无代码工作流构建器的功能。

Go 插件架构的高级注意事项

在 Go 中构建生产就绪的插件架构时,请考虑以下方面:

  • 错误处理:为每个插件实现健壮的错误处理和日志记录。
  • 配置:允许动态配置插件(例如,API 密钥、阈值)。
  • 插件加载:为了实现无需重新编译的真正可扩展性,可以探索 Go 的 plugin 包(尽管它有平台限制)或用于进程间通信的外部进程/gRPC。
  • 安全性:确保插件经过沙盒化或适当审查,以防止恶意代码执行。
  • 数据流:为每个插件的输入和输出定义清晰的数据契约。
  • 白标:如果您正在构建面向用户的工作流,请记住 Didit 提供广泛的白标选项,允许您自定义颜色、字体、徽标,甚至使用自定义域名,确保无缝的品牌体验。这对于在验证过程中保持用户信任和降低跳出率至关重要。

Didit 如何提供帮助

Didit 从一开始就旨在实现这种模块化、可扩展的集成。作为 AI 原生、开发者优先的身份平台,Didit 提供了可以无缝集成到您的 Go 插件架构中的构建块或“原语”。我们的模块化架构意味着您可以选择所需的精确验证组件,无论是身份验证、被动与主动活体检测、1:1 人脸匹配、AML 筛选与监控、地址证明还是年龄估算。其中每一个都可以在您的系统中成为一个独立的插件。

Didit 的突出之处在于提供免费的核心 KYC,让您无需前期成本即可开始进行基本的身份检查。我们简洁的 API 和全面的文档,以及即时沙盒,使集成变得直观快捷。通过利用 Didit,您可以卸载维护复杂的 AI 模型、全球文档数据库和合规性更新的复杂性,从而使您的 Go 服务能够专注于编排和业务逻辑。Didit 的按成功检查付费模式和无设置费用进一步符合灵活、可扩展的架构,确保您只为所使用的付费。

准备好开始了吗?

准备好亲身体验 Didit 了吗?立即获取免费演示

使用Didit 的免费套餐免费开始验证身份。

身份与欺诈基础设施。

一个 API 即可实现 KYC、KYB、交易监控和钱包筛选。5 分钟即可集成。

让 AI 总结此页面
使用 Didit 原语在 Go 中实现可扩展身份检查.