# drupal **Repository Path**: yak3/drupal ## Basic Information - **Project Name**: drupal - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-10-29 - **Last Updated**: 2025-11-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Drupal Node Builder 一个用于构建 Drupal JSON API 节点数据的 Go 语言库。 ## 功能特性 - **DrupalNode 数据结构**:支持 Drupal JSON API 的节点数据格式。 - **建造者模式**:提供 `DrupalNodeBuilder` 接口,简化节点构建过程。 ## 数据结构 `DrupalNode` 定义了 Drupal JSON API 的节点数据结构: ```go type DrupalNode struct { Data struct { // Type 表示节点的类型,例如 "node--article" Type string `json:"type"` // Attributes 包含节点的核心属性 Attributes map[string]interface{} `json:"attributes"` // Relationships 包含节点与其他实体的关联关系 Relationships map[string]interface{} `json:"relationships"` } `json:"data,omitempty"` } ``` ## 建造者模式 `DrupalNodeBuilder` 提供了一种链式调用的方式来构建 `DrupalNode` 对象: ```go type DrupalNodeBuilder interface { SetType(nodeType string) DrupalNodeBuilder SetAttributes(key string, value interface{}) DrupalNodeBuilder SetRelationships(key string, value interface{}) DrupalNodeBuilder Build() DrupalNode } ``` ## 快速开始 以下是一个简单的示例,展示如何使用 `DrupalNodeBuilder` 构建节点数据: ```go package main import ( "fmt" "github.com/yourusername/alai/drupal" ) func main() { node := types.NewDrupalNodeBuilder(). SetType("node--article"). SetAttributes("title", "示例文章"). SetAttributes("body", map[string]interface{}{ "value": "这是一篇示例文章的内容。", "format": "full_html", }). SetAttributes("field_url", link.URL). SetRelationships("field_tags", map[string]interface{}{ "data": map[string]string{ "type": "taxonomy_term--tags", "id": link.TagID, }, }).Build() fmt.Printf("构建的节点: %+v\n", node) } ``` ### 关于 Tag 关系 `tag` 关系通常用于表示节点与标签的关联。可以通过 `SetRelationships` 方法设置 `tag` 关系,支持单个标签或多个标签的数组形式。 ## 贡献 欢迎提交 Issue 或 Pull Request! ## 许可证 MIT