replace

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: Apache-2.0 Imports: 9 Imported by: 2

README

replace

提供各种替换,包括文件,字符串等

功能

  • 文件替换
  • JSON修改
  • XML修改
  • 字符串替换

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorNotSupportReplace 不支持的文件替换
	ErrorNotSupportReplace = &gox.CodeError{ErrorCode: 103, Message: "不支持的文件替换"}
)

Functions

This section is empty.

Types

type FileReplace

type FileReplace struct {
	// 文件
	File transfer.File `json:"file" validate:"required"`
}

文件替换

func (FileReplace) Replace

func (fr FileReplace) Replace(filename string) (err error)

func (FileReplace) String

func (fr FileReplace) String() string

type FileWriteReplace

type FileWriteReplace struct {
	// 内容
	Content string `json:"content" validate:"required"`
}

FileWriteReplace 文件替换

func (FileWriteReplace) Replace

func (fwr FileWriteReplace) Replace(filename string) (err error)

func (FileWriteReplace) String

func (fwr FileWriteReplace) String() string

type JSONReplace

type JSONReplace struct {
	// 修改元素列表
	Elements []JSONReplaceElement `json:"elements" validate:"required,dive"`
}

JSONReplace JSON替换

func (JSONReplace) Replace

func (jr JSONReplace) Replace(filename string) (err error)

func (JSONReplace) String

func (jr JSONReplace) String() string

type JSONReplaceElement

type JSONReplaceElement struct {
	// 节点路径
	Path string `json:"path" validate:"required"`
	// 要设置的值
	Value string `json:"value" validate:"required"`
}

JSONReplaceElement JSON替换元素

type Replace

type Replace struct {
	// Filename 文件名,使用相对路径
	Filename string `json:"filename" validate:"required"`
	// Type 类型
	Type Type `default:"file" json:"type" validate:"omitempty,oneof=file string write json xml"`
	// Value 需要修改的值
	Value interface{} `json:"value" validate:"required"`
}

Replace 替换

func NewFileReplace

func NewFileReplace(filename string, file transfer.File) Replace

NewFileReplace 文件替换

func NewFileWriteReplace

func NewFileWriteReplace(filename string, content string) Replace

NewFileWriteReplace 文件内容替换

func NewJSONReplace

func NewJSONReplace(filename string, elements ...JSONReplaceElement) Replace

NewFileReplace JSON文件修改

func NewReplace

func NewReplace(filename string, replaceType Type, value interface{}) Replace

NewReplace 创建新的替换

func NewStringContentReplace

func NewStringContentReplace(filename string, old string, new string) Replace

NewStringContentReplace 字符串替换

func NewXMLReplace

func NewXMLReplace(filename string, elements ...XMLReplaceElement) Replace

NewXMLReplace JSON文件修改

func (*Replace) Replace

func (r *Replace) Replace(dir string) (err error)

func (Replace) String

func (r Replace) String() string

func (*Replace) UnmarshalJSON

func (r *Replace) UnmarshalJSON(data []byte) (err error)

type Replacer

type Replacer interface {
	// Replace 执行替换
	Replace(filename string) (err error)
}

Replacer 替换

type StringContentReplace

type StringContentReplace struct {
	// Old 旧内容
	Old string `json:"old" validate:"required"`
	// New 新内容
	New string `json:"new" validate:"required"`
}

StringContentReplace 文本内容替换

func (StringContentReplace) Replace

func (scr StringContentReplace) Replace(filename string) (err error)

func (StringContentReplace) String

func (scr StringContentReplace) String() string

type Type

type Type string

ReplaceType 替换类型

const (
	// 所有支持的文件替换类型
	// 文件内容替换
	TypeFileWrite Type = "write"
	// 字符串替换
	TypeStringContent Type = "string"
	// 文件替换
	TypeFile Type = "file"
	// JSON文件替换
	TypeJSON Type = "json"
	// XML文件替换
	TypeXML Type = "xml"
)

type XMLReplace

type XMLReplace struct {
	// Elements 需要替换的元素列表
	Elements []XMLReplaceElement `json:"elements" validate:"required,dive"`
}

XMLReplace XML文件替换

func (XMLReplace) Replace

func (xr XMLReplace) Replace(filename string) (err error)

func (XMLReplace) String

func (xr XMLReplace) String() string

type XMLReplaceElement

type XMLReplaceElement struct {
	// XPath 节点路径
	XPath string `json:"xpath" validate:"required"`
	// Type XML替换类型
	Type XMLReplaceType `json:"type" validate:"required,oneof=attr text"`
	// Key 操作的键
	Key string `json:"key" validate:"omitempty"`
	// Value 要设置的值
	Value string `json:"value" validate:"required"`
}

XMLReplaceElement XML文件替换元素

func (XMLReplaceElement) String

func (xre XMLReplaceElement) String() string

type XMLReplaceType

type XMLReplaceType string

XMLReplaceType XML的操作类型

const (
	// XMLReplaceTypeAttr 替换属性
	XMLReplaceTypeAttr XMLReplaceType = "attr"
	// XMLReplaceTypeText 替换文本
	XMLReplaceTypeText XMLReplaceType = "text"
)

Jump to

Keyboard shortcuts

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