parse

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2022 License: GPL-3.0 Imports: 3 Imported by: 1

README

存证解析库

背景

用于解析存证的数据
在创建存证的时候,区分版本
  • 第一版本的存证内模板和存证内容混在一起,无需分离

  • 第二版本的存证内容格式完全由项目方自定义,不做任何处理

  • 第三版本的存证可以直接将模板和存证内容分离, ,例

[{"label":"相册","key":"","type":3,"data":[{"data":[{"type":"image","format":"hash","value":"4bb42ecfe15a99ee586031b7a5a20a5d15c4364780f5ea14d278095d620619f5"},{"type":"image","format":"hash","value":"b45f6c7728e9b59f9ad381f36c29945317ba646e49ad3b73511ec1731c22dff4"}],"type":1,"key":"","label":"相册"},{"data":{"type":"text","format":"string","value":""},"type":0,"key":"","label":"照片描述"}]},{"label":"ext","key":"","type":3,"data":[{"data":{"type":"text","format":"string","value":"相册"},"type":0,"key":"存证名称","label":"存证名称"},{"data":{"type":"text","format":"string","value":"null"},"type":0,"key":"basehash","label":"basehash"},{"data":{"type":"text","format":"string","value":"null"},"type":0,"key":"prehash","label":"prehash"},{"data":{"type":"text","format":"string","value":"相册"},"type":0,"key":"存证类型","label":"存证类型"}]}]

data的内容为两种
一种是嵌层一层完整数据,内容为数组,元素的key为"label""type""data"
一种是存证具体数据,内容为数组或者map,元素的key为"format""type""value"

分离后
{"ext":{"basehash":"null","prehash":"null","存证名称":"相册","存证类型":"相册"},"相册":{"照片描述":"","相册":["4bb42ecfe15a99ee586031b7a5a20a5d15c4364780f5ea14d278095d620619f5","b45f6c7728e9b59f9ad381f36c29945317ba646e49ad3b73511ec1731c22dff4"]}}

模板为

[{"label":"相册","key":"","type":3,"data":[{"data":[{"type":"image","format":"hash","value":""}],"type":1,"key":"","label":"相册"},{"data":{"type":"text","format":"string","value":""},"type":0,"key":"","label":"照片描述"}]},{"label":"ext","key":"","type":3,"data":[{"data":{"type":"text","format":"string","value":""},"type":0,"key":"存证名称","label":"存证名称"},{"data":{"type":"text","format":"string","value":""},"type":0,"key":"basehash","label":"basehash"},{"data":{"type":"text","format":"string","value":""},"type":0,"key":"prehash","label":"prehash"},{"data":{"type":"text","format":"string","value":""},"type":0,"key":"存证类型","label":"存证类型"}]}]

Documentation

Index

Constants

View Source
const (
	OldVersion = "1.0.0" //最初版本(兼容)
	Version1   = "V1"    //最初版本
	Version2   = "V2"    //项目方的自定义版本 不做处理
	Version3   = "V3"    //对存证内容和模板分离 + 合并
	Version4   = "V4"    //不分离 + 合并

	ProofParaData  = "data"
	ProofParaValue = "value"
	ProofParaLabel = "label"

	ProofParaLabelExt = "ext"
)

Variables

This section is empty.

Functions

func FormatVersion

func FormatVersion(version string) (string, error)

Types

type BaseProof

type BaseProof interface {
	ToTx() (string, error)   //use for backend
	ToView() (string, error) //use for externaldb
}

BaseProof 基础的存证转换接口

type Proof

type Proof struct {
	ComleteData string //完整数据
	Template    string //模板
	Content     string //存证内容
	Version     string //存证版本
}

func NewProof

func NewProof(data, template, value, version string) *Proof

func (*Proof) ComleteDataToContent

func (p *Proof) ComleteDataToContent() error

将完整数据抽离成简化内容 需要完整数据

func (*Proof) ContentToComleteData

func (p *Proof) ContentToComleteData() error

将存证内容和模板合并成完整数据

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL