data_block

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 8 Imported by: 0

README

data-block-golang

Data block golang package

Use
  import (
    "fmt"
    dataBlock "github.com/zaxjs/data-block-golang"
  )

  opts := dataBlock.Options{Api: "http://localhost:8089/data-block-service-api/v1/open, Key: "Y2wwemk4aWtnMDAwMjA4bDQ4c3VrZzB5bA==", Ttl: "5m", ShowSysField: true, ShowGroupInfo: true}
  myBlock, _ := dataBlock.New(opts) // 建议配置为全局单例对象

  res1, _ := myBlock.GetBlock([]string{ "TEST_BLOCK","TEST_MISC" }, nil)
  fmt.Println("[GetBlock]:", res1)

  res2, _ := myBlock.GetBlock([]string{ "TEST_BLOCK","TEST_MISC" }, &dataBlock.Options{ShowSysField: false, ShowGroupInfo: false})
  fmt.Println("[GetBlock]:", res2)

  res3, _ := myBlock.GetKv([]string{ "TEST_BLOCK","TEST_MISC" })
  fmt.Println("[GetKv]:", res2)
Test
go test .
Docs

Go Reference

Documentation

Index

Constants

View Source
const APP_OPEN_KEY = `x-data-block-openkey`

Variables

This section is empty.

Functions

This section is empty.

Types

type BLOCK_TYPE added in v0.0.3

type BLOCK_TYPE string
const (
	BT_KV    BLOCK_TYPE = "kv"
	BT_BLOCK BLOCK_TYPE = "block"
)

type BaseResponseModel added in v0.0.6

type BaseResponseModel[T interface{}] struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	Data    T      `json:"data,omitempty"`
	Success bool   `json:"success,omitempty"`
}

type Block added in v0.0.3

type Block struct {
	BlockCode       *string                  `json:"blockCode,omitempty"`
	BlockData       []map[string]interface{} `json:"blockData,omitempty"`
	Slugs           string                   `json:"slugs,omitempty"`
	Stage           string                   `json:"stage,omitempty"`
	IsMultipleGroup *string                  `json:"isMultipleGroup,omitempty"`
	AtUsers         []string                 `json:"atUsers,omitempty"`
	SpaceId         string                   `json:"spaceId,omitempty"`
	SpaceName       string                   `json:"spaceName,omitempty"`
	SysId           uint                     `json:"sysId,omitempty"`
	BlockStatus     *TEXT_STATUS             `json:"blockStatus,omitempty"`
	SyncAt          *time.Time               `json:"syncAt,omitempty"`
	CreatedBy       string                   `json:"createdBy,omitempty"`
	CreatedAt       *time.Time               `json:"createdAt,omitempty"`
	UpdatedBy       interface{}              `json:"updatedBy,omitempty"`
	UpdatedAt       *time.Time               `json:"updatedAt,omitempty"`
	PublishedBy     interface{}              `json:"publishedBy,omitempty"`
	PublishedAt     interface{}              `json:"publishedAt,omitempty"`
	ModelCode       string                   `json:"modelCode,omitempty"`
}

type BlockData added in v0.0.3

type BlockData struct {
	ID           string                   `json:"id,omitempty"`
	Cid          string                   `json:"cid,omitempty"`
	Data         []map[string]interface{} `json:"data,omitempty"`
	GroupName    string                   `json:"groupName,omitempty"`
	GroupPercent string                   `json:"groupPercent,omitempty"`
}

type DataBlockService added in v0.0.3

type DataBlockService struct {
	Options *Options
}

func New added in v0.0.3

func New(opt Options) (*DataBlockService, error)

func (*DataBlockService) Get added in v0.0.3

func (svc *DataBlockService) Get(codes []string, newOpt Options) (*map[string]interface{}, error)

func (*DataBlockService) GetBlock added in v0.0.3

func (svc *DataBlockService) GetBlock(codes []string, newOpt *Options) (*map[string]interface{}, error)

GetBlock

func (*DataBlockService) GetKv added in v0.0.3

func (svc *DataBlockService) GetKv(codes []string, newOpt *Options) (*map[string]interface{}, error)

GetKv

type FieldSettings added in v0.0.3

type FieldSettings struct {
	Localizations []string `json:"localizations,omitempty"`
}

type FieldValidations added in v0.0.3

type FieldValidations struct {
	Max       int    `json:"max,omitempty"`
	Min       int    `json:"min,omitempty"`
	Type      string `json:"type,omitempty"`
	Required  bool   `json:"required,omitempty"`
	ScaleType string `json:"scaleType,omitempty"`
}

type FieldValues added in v0.0.3

type FieldValues struct {
	DefaultValue   string `json:"defaultValue,omitempty"`
	DatasetValues  string `json:"datasetValues,omitempty"`
	PlaceholderTip string `json:"placeholderTip,omitempty"`
}

type Kv added in v0.0.6

type Kv struct {
	KvId           string       `json:"kvId,omitempty"`
	K              string       `json:"k,omitempty"`
	V              string       `json:"v,omitempty"`
	Description    string       `json:"description,omitempty"`
	OrganizationId string       `json:"organizationId,omitempty"`
	BlockStatus    *TEXT_STATUS `json:"blockStatus,omitempty"`
	SyncAt         *time.Time   `json:"syncAt,omitempty"`
	SysId          uint         `json:"sysId,omitempty"`
	CreatedBy      string       `json:"createdBy,omitempty"`
	CreatedAt      *time.Time   `json:"createdAt,omitempty"`
	UpdatedBy      interface{}  `json:"updatedBy,omitempty"`
	UpdatedAt      *time.Time   `json:"updatedAt,omitempty"`
	PublishedBy    interface{}  `json:"publishedBy,omitempty"`
	PublishedAt    interface{}  `json:"publishedAt,omitempty"`
	Organization   Organization `json:"organization,omitempty"`
}

type Model added in v0.0.3

type Model struct {
	ID                    string             `json:"$id,omitempty"`
	Type                  string             `json:"type,omitempty"`
	CanDrag               bool               `json:"canDrag,omitempty"`
	Omitted               bool               `json:"omitted,omitempty"`
	Children              []interface{}      `json:"children,omitempty"`
	Disabled              bool               `json:"disabled,omitempty"`
	Expanded              bool               `json:"expanded,omitempty"`
	FieldName             string             `json:"fieldName,omitempty"`
	FieldType             string             `json:"fieldType,omitempty"`
	FieldLabel            string             `json:"fieldLabel,omitempty"`
	FieldValues           FieldValues        `json:"fieldValues,omitempty"`
	FieldSettings         FieldSettings      `json:"fieldSettings,omitempty"`
	FieldDescription      string             `json:"fieldDescription,omitempty"`
	FieldValidations      []FieldValidations `json:"fieldValidations,omitempty"`
	FieldNamePlaceholder  string             `json:"fieldNamePlaceholder,omitempty"`
	FieldLabelPlaceholder string             `json:"fieldLabelPlaceholder,omitempty"`
}

type Options added in v0.0.3

type Options struct {
	Key           string     `json:"$id,omitempty"`           // API KEY
	Api           string     `json:"type,omitempty"`          // Request url
	ShowSysField  bool       `json:"showSysField,omitempty"`  // 展示系统字段
	ShowGroupInfo bool       `json:"showGroupInfo,omitempty"` // 展示组信息
	Ttl           string     `json:"ttl,omitempty"`           // 缓存时间,默认5s //  `${number}${'d' | 'h' | 'm' | 's'}`
	KeyType       BLOCK_TYPE `json:"keyType,omitempty"`
}

type Organization added in v0.0.6

type Organization struct {
	OrganizationName string `json:"organizationName,omitempty"`
}

type TEXT_STATUS added in v0.0.3

type TEXT_STATUS string
const (
	TS_PUBLISHED TEXT_STATUS = "PUBLISHED"
	TS_DELETED   TEXT_STATUS = "DELETED"
)

Jump to

Keyboard shortcuts

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