DAT
Tài liệu

DAT Go Library

GitHub pkg.go.dev

Installation

bash

Quick start

This complete flow retrieves certificates from CMS, creates a DAT containing JSON data, and verifies it.

go

Step by step

1. Connect to CMS

An issuing service uses a token for full certificates. Synchronizing immediately at startup prevents issuance before certificates are available.

go

2. Issue a DAT

This example puts public JSON in plain and protected user information as JSON in secure.

go

3. Verify a DAT

parse checks expiration and the signature, then decrypts secure. Use only a payload returned after successful verification.

go

Key functions

FunctionPurpose
Sync()Synchronizes certificates immediately.
Issue(plain, secure)Returns a DAT string and an error.
Parse(dat)Returns a verified Payload and an error.
LastError()Returns the last synchronization error.

Data regions

  • plain: bytes that are signed but not encrypted.
  • secure: encrypted bytes.
  • payload: trust it only after parse succeeds.

Options beyond JSON

The examples use familiar JSON. For faster processing, binary data can avoid JSON serialization and parsing while reducing data size.

Store simple values as text, or place structured data in binary formats such as Protobuf or MessagePack in plain and secure.

go

Go strings can contain bytes. Pass a byte slice as a string, then convert the result back to []byte.

Verify-only services

A service that does not issue DATs uses the verify-only option and a verify-only token, and calls only parse.

Shutdown and errors

When automatic synchronization is enabled, use defer cms.Close() to guarantee cleanup.

Use error codes and retry classifications instead of error messages.