model

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// C语言注释类型
	CTypeComment = &CommentType{
		Simple: "//",
		Begin:  "/*",
		End:    "*/",
	}
	// Python语言注释类型
	PythonTypeComment = &CommentType{
		Simple: "#",
		Begin:  "'''",
		End:    "'''",
	}
)

Functions

func Purl

func Purl(vendor, name, version string, language Language) string

func ReadLine

func ReadLine(reader io.Reader, do func(line string))

ReadLine 按行读取内容 去除行尾换行符

func ReadLineNoComment

func ReadLineNoComment(reader io.Reader, t *CommentType, do func(line string))

ReadLineNoComment 按行读取内容 忽略注释

Types

type CommentType

type CommentType struct {
	// 单行注释标记
	Simple string
	// 多行注释起始标记
	Begin string
	// 多行注释终止标记
	End string
}

注释类型

type CreationInfo

type CreationInfo struct {
	Created  string   `json:"created,omitempty" xml:"created,omitempty"`
	Creators []string `json:"creators,omitempty" xml:"creators,omitempty"`
}

type DepGraph

type DepGraph struct {
	// 厂商
	Vendor string
	// 名称
	Name string
	// 版本号
	Version string
	// 语言
	Language Language
	// 检出路径
	Path string
	// 许可证
	Licenses []string

	// 仅用于开发环境
	Develop bool
	// 直接依赖
	Direct bool
	// 父节点
	Parents []*DepGraph

	// 子节点
	Children []*DepGraph

	// 附加信息
	Expand any
	// contains filtered or unexported fields
}

DepGraph 依赖关系图

func (*DepGraph) AppendChild

func (dep *DepGraph) AppendChild(child *DepGraph)

AppendChild 添加子依赖

func (*DepGraph) AppendLicense

func (dep *DepGraph) AppendLicense(lic string)

func (*DepGraph) Build

func (dep *DepGraph) Build(deep bool, lan Language)

Build 构建依赖图路径 deep: 依赖路径构建顺序 true=>深度优先 false=>广度优先 广度优先的路径更短 如果不清楚该用什么推荐false lan: 更新依赖语言

func (*DepGraph) Flush

func (dep *DepGraph) Flush()

Flush 更新依赖图依赖关系

func (*DepGraph) ForEach

func (dep *DepGraph) ForEach(deep, path, name bool, do func(p, n *DepGraph) bool)

ForEach 遍历依赖图 deep: true=>深度优先 false=>广度优先 path: true=>遍历所有路径 false=>遍历所有节点 name: true=>按名称顺序迭代子节点 false=>按添加顺序迭代子节点 do: 对当前节点的操作 返回true代表继续迭代子节点 do.p: 路径父节点 do.n: 路径子节点

func (*DepGraph) ForEachNode

func (dep *DepGraph) ForEachNode(do func(p, n *DepGraph) bool)

ForEachNode 遍历依赖图节点

func (*DepGraph) ForEachPath

func (dep *DepGraph) ForEachPath(do func(p, n *DepGraph) bool)

ForEachPath 遍历依赖图路径

func (*DepGraph) Index

func (dep *DepGraph) Index() string

func (*DepGraph) RemoveChild

func (dep *DepGraph) RemoveChild(child *DepGraph)

RemoveChild 移除子依赖

func (*DepGraph) RemoveDevelop

func (dep *DepGraph) RemoveDevelop()

RemoveDevelop 移除develop组件

func (*DepGraph) String

func (dep *DepGraph) String() string

func (*DepGraph) Tree

func (dep *DepGraph) Tree(path, name bool) string

Tree 依赖树 path: true=>记录全部路径 false=>记录全部节点 name: true=>名称升序排序 false=>添加顺序排列

type DepGraphMap

type DepGraphMap struct {
	// contains filtered or unexported fields
}

func NewDepGraphMap

func NewDepGraphMap(key func(...string) string, store func(...string) *DepGraph) *DepGraphMap

func (*DepGraphMap) LoadOrStore

func (s *DepGraphMap) LoadOrStore(words ...string) *DepGraph

func (*DepGraphMap) Range

func (s *DepGraphMap) Range(do func(k string, v *DepGraph) bool)

type DsdxComponent

type DsdxComponent struct {
	// DSDX-xxx
	ID       string   `json:"id" xml:"id"`
	Group    string   `json:"group,omitempty" xml:"group,omitempty"`
	Name     string   `json:"name" xml:"name"`
	Version  string   `json:"version" xml:"version"`
	Language string   `json:"language,omitempty" xml:"language,omitempty"`
	License  []string `json:"license,omitempty" xml:"license,omitempty"`
}

type DsdxDependencies

type DsdxDependencies map[string][]string

type DsdxDocument

type DsdxDocument struct {
	// 文档名称
	Name string `json:"name" xml:"name"`
	// 创作者
	Creator string `json:"creator" xml:"creator"`
	// dsdx版本 DSDX-1.0
	DSDXVersion string `json:"dsdx_version" xml:"dsdx_version"`
	// 文档创建时间 yyyy-MM-dd HH:mm:ss
	CreateTime string `json:"create_time" xml:"create_time"`
	// dsdx文档标识 自动生成 DSDX-${Name}-${Version}-${CreateTime}
	DSDXID string `json:"dsdx_id" xml:"dsdx_id"`
	// 项目名称
	ProjectName string `json:"project_name" xml:"project_name"`
	// 组件列表
	Components []DsdxComponent `json:"components" xml:"components"`
	// 依赖关系
	Dependencies DsdxDependencies `json:"dependencies" xml:"-"`
}

func NewDsdxDocument

func NewDsdxDocument(name, creator string) *DsdxDocument

func (*DsdxDocument) AppendComponents

func (doc *DsdxDocument) AppendComponents(id, group, name, version, language string, license []string)

func (*DsdxDocument) AppendDependencies

func (doc *DsdxDocument) AppendDependencies(parentId string, childrenIds []string)

func (*DsdxDocument) WriteDsdx

func (doc *DsdxDocument) WriteDsdx(w io.Writer) error

type ExternalRef

type ExternalRef struct {
	ReferenceCategory string `json:"referenceCategory" xml:"referenceCategory"`
	ReferenceLocator  string `json:"referenceLocator" xml:"referenceLocator"`
	ReferenceType     string `json:"referenceType" xml:"referenceType"`
}

type File

type File struct {
	// contains filtered or unexported fields
}

File 文件相关信息

func NewFile

func NewFile(abs, rel string) *File

NewFile 创建文件对象 abs: 文件绝对路径 rel: 文件相对路径(相对于项目根目录)

func (*File) Abspath

func (file *File) Abspath() string

Abspath 文件绝对路径

func (*File) OpenReader

func (file *File) OpenReader(do func(reader io.Reader)) error

OpenReader 打开文件reader

func (File) ReadLine

func (file File) ReadLine(do func(line string))

ReadLine 按行读取文件内容 去除行尾换行符

func (File) ReadLineNoComment

func (file File) ReadLineNoComment(t *CommentType, do func(line string))

ReadLineNoComment 按行读取文件内容 忽略注释

func (*File) Relpath

func (file *File) Relpath() string

Relpath 文件相对路径

func (*File) String added in v3.0.2

func (file *File) String() string

type Language

type Language string
const (
	Lan_None       Language = ""
	Lan_Java       Language = "Java"
	Lan_JavaScript Language = "JavaScript"
	Lan_Php        Language = "Php"
	Lan_Ruby       Language = "Ruby"
	Lan_Golang     Language = "Golang"
	Lan_Rust       Language = "Rust"
	Lan_Erlang     Language = "Erlang"
	Lan_Python     Language = "Python"
)

func ParsePurl

func ParsePurl(purl string) (vendor, name, version string, language Language)

type Relationship

type Relationship struct {
	SPDXElementID      string `json:"spdxElementId" xml:"spdxElementId"`
	RelatedSPDXElement string `json:"relatedSpdxElement" xml:"relatedSpdxElement"`
	RelationshipType   string `json:"relationshipType" xml:"relationshipType"`
}

type ResCallback

type ResCallback func(file *File, root ...*DepGraph)

ResCallback 检测结果回调函数 file: 检出组件的文件信息 root: 组件依赖图根节点列表

type SpdxDocument

type SpdxDocument struct {
	Namespace     string         `json:"documentNamespace" xml:"documentNamespace"`
	SPDXVersion   string         `json:"spdxVersion" xml:"spdxVersion"`
	SPDXID        string         `json:"SPDXID" xml:"SPDXID"`
	DocumentName  string         `json:"name" xml:"name"`
	CreationInfo  CreationInfo   `json:"creationInfo" xml:"creationInfo"`
	Packages      []SpdxPackage  `json:"packages" xml:"packages"`
	Relationships []Relationship `json:"relationships" xml:"relationships"`
}

func NewSpdxDocument

func NewSpdxDocument(name string) *SpdxDocument

func (*SpdxDocument) AddPackage

func (doc *SpdxDocument) AddPackage(id, vendor, name, version string, language Language, lics []string)

func (*SpdxDocument) AddRelation

func (doc *SpdxDocument) AddRelation(parentId, childId string)

func (*SpdxDocument) WriteSpdx

func (doc *SpdxDocument) WriteSpdx(w io.Writer) error

type SpdxPackage

type SpdxPackage struct {
	SPDXID       string        `json:"SPDXID" xml:"SPDXID"`
	Name         string        `json:"name" xml:"name"`
	Version      string        `json:"versionInfo,omitempty" xml:"versionInfo,omitempty"`
	Supplier     string        `json:"supplier,omitempty" xml:"supplier,omitempty"`
	ExternalRefs []ExternalRef `json:"externalRefs" xml:"externalRefs"`
	// 从文件中解析的许可证名称不符合spdx规范
	LicenseConcluded string `json:"-" xml:"-"`
}

Jump to

Keyboard shortcuts

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