core

package
v0.0.0-...-3f0bd07 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseQuietly

func CloseQuietly(closer io.Closer)

CloseQuietly 安静的调用Close()

func CurrentPath

func CurrentPath() (string, error)

CurrentPath 获取当前的执行文件所在的目录

func If

func If(condition bool, trueVal, falseVal interface{}) interface{}

If 模拟的三元运算符

condition: 条件表达式
trueVal: 表达式为true时返回的值
falseVal: 表达式为false时返回的值

return: 根据表达式的true/false,返回trueVal/falseVal

注意,由于返回的类型是interface{},需要转换成trueVal/falseVal对应的类型

func IsExists

func IsExists(p string) bool

IsExists 判断文件或目录是否存在

Types

type ArchType

type ArchType string
const (
	ArchX86    ArchType = "386"
	ArchX64    ArchType = "amd64"
	ArchUnknow ArchType = "unknow"
)

func Arch

func Arch() ArchType

type OsType

type OsType string
const (
	OsWindows OsType = "windows"
	OsLinux   OsType = "linux"
	OsMac     OsType = "darwin"
	OsUnknow  OsType = "unknow"
)

func Os

func Os() OsType

type StringStack

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

StringStarck 是一个模拟的字符串栈,提供了入栈出栈等操作

func MakeStringStack

func MakeStringStack() *StringStack

MakeStringStack 创建 StringStarck

func (*StringStack) Clear

func (s *StringStack) Clear()

Clear 清空当前栈

func (*StringStack) Pop

func (s *StringStack) Pop() (string, error)

Pop 将当前栈中的所有数据出栈,并清空当前栈 return

string: 栈中存储的字符串
error: 出栈失败的错误

func (*StringStack) Push

func (s *StringStack) Push(data string) (int, error)

Push 将一个字符串入栈 param

data: 准备入栈的字符串

return

int: 成功入栈后返回入栈的字符串长度
error: 入栈失败返回错误

func (*StringStack) PushByte

func (s *StringStack) PushByte(data byte) (int, error)

PushByte 将一个字节入栈 param

data: 准备入栈的字节

return

int: 成功入栈后返回入栈的字节长度
error: 入栈失败返回错误

func (*StringStack) PushBytes

func (s *StringStack) PushBytes(data []byte) (int, error)

PushBytes 将一个字节切片入栈 param

data: 准备入栈的字节切片

return

int: 成功入栈后返回入栈的字节切片长度
error: 入栈失败返回错误

func (*StringStack) Size

func (s *StringStack) Size() int64

Size 当前栈的容量

type Template

type Template struct {
}

func NewTemplate

func NewTemplate() *Template

NewTemplate 解析模板,若模板内容中定义的参数多于实际提供的参数,则未提供的参数不会解析

示例1:

args := make(map[string]string)
args["url"] = "http://www.baidu.com"
tmpl := "{url }/aa/bb"
result := core.NewTemplate().Parse(tmpl, args)

结果1:http://www.baidu.com/aa/bb

示例2:

args := make(map[string]string)
args["url"] = "http://www.sina.com"
tmpl := "{url }/11/{test}"
result := core.NewTemplate().Parse(tmpl, args)

结果2:http://www.sina.com/11/{test}

func (*Template) Parse

func (t *Template) Parse(tmpl string, args map[string]string) string

Parse 解析模板,若模板内容中定义的参数多于实际提供的参数,则为提供的参数不会解析

tmpl: 模板内容,参数以 {a} 形式
args: 模板参数

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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