Documentation ¶
Index ¶
- Constants
- Variables
- func ConvBool(raw string) (value bool)
- func ConvF64(raw string) (value float64)
- func ConvI64(raw string) (value int64)
- func ConvInt(raw string) (value int)
- func GetUrlContent(vUrl string) []byte
- func NewParser(script string) [][]string
- func NewScriptFile(filename string) []string
- func ParseLine(line string) [][]string
- type BaseReceiver
- type DataReceiver
- type DataReceiverType
- type JsonReceiver
- func (c *JsonReceiver) GetData() map[string]any
- func (c *JsonReceiver) JsonFile(filename string) *JsonReceiver
- func (c *JsonReceiver) JsonStr(vStr string) *JsonReceiver
- func (c *JsonReceiver) JsonUrl(vUrl string) *JsonReceiver
- func (c *JsonReceiver) Name() string
- func (c *JsonReceiver) Receiver(vType DataReceiverType, content string) DataReceiver
- type UrlReceiver
- func (c *UrlReceiver) GetData() map[string]any
- func (c *UrlReceiver) Name() string
- func (c *UrlReceiver) Receiver(vType DataReceiverType, content string) DataReceiver
- func (c *UrlReceiver) UrlFile(filename string) *UrlReceiver
- func (c *UrlReceiver) UrlStr(vStr string) *UrlReceiver
- func (c *UrlReceiver) UrlUrl(vUrl string) *UrlReceiver
- type Value
Examples ¶
Constants ¶
const ( RJson = "json" RUrl = "url" )
Variables ¶
var Transferred map[string]string = map[string]string{
`\'`: "_Sg_.Qmark_",
`\"`: "_Db_.Qmark_",
}
Transferred Escape symbol
Functions ¶
func ConvBool ¶ added in v1.2.0
ConvBool convert string to bool
Example ¶
func TestExampleConvBool(t *testing.T) {
var raw = "True" var cv bool // case cv = ConvBool(raw) fmt.Printf("ConvBool:%v => %v\n", raw, cv) // case raw = "TRUE" cv = ConvBool(raw) fmt.Printf("ConvBool:%v => %v\n", raw, cv) // case raw = "vaild" cv = ConvBool(raw) fmt.Printf("ConvBool:%v => %v\n", raw, cv)
Output: ConvBool:True => true ConvBool:TRUE => true ConvBool:vaild => false
func ConvF64 ¶ added in v1.2.0
ConvF64 convert string to float64
Example ¶
var raw = "1949" var cv float64 // case cv = ConvF64(raw) fmt.Printf("ConvF64:%v => %v\n", raw, cv) // case raw = "+1949" cv = ConvF64(raw) fmt.Printf("ConvF64:%v => %v\n", raw, cv) // case raw = "-1949.1001" cv = ConvF64(raw) fmt.Printf("ConvF64:%v => %v\n", raw, cv) // case raw = "-3.14159265359" cv = ConvF64(raw) fmt.Printf("ConvI64:%v => %v\n", raw, cv) // case raw = "vaild" cv = ConvF64(raw) fmt.Printf("ConvI64:%v => %v\n", raw, cv)
Output: ConvF64:1949 => 1949 ConvF64:+1949 => 1949 ConvF64:-1949.1001 => -1949.1001 ConvI64:-3.14159265359 => -3.14159265359 ConvI64:vaild => 0
func ConvI64 ¶ added in v1.2.0
ConvI64 convert string to int64, compatible float types
Example ¶
var raw = "1949" var cv int64 // case cv = ConvI64(raw) fmt.Printf("ConvI64:%v => %v\n", raw, cv) // case raw = "+1949" cv = ConvI64(raw) fmt.Printf("ConvI64:%v => %v\n", raw, cv) // case raw = "-1949.1001" cv = ConvI64(raw) fmt.Printf("ConvBool:%v => %v\n", raw, cv) // case raw = "-2022" cv = ConvI64(raw) fmt.Printf("ConvI64:%v => %v\n", raw, cv) // case raw = "vaild" cv = ConvI64(raw) fmt.Printf("ConvI64:%v => %v\n", raw, cv)
Output: ConvI64:1949 => 1949 ConvI64:+1949 => 1949 ConvI64:-1949.1001 => -1949 ConvI64:-2022 => -2022 ConvI64:vaild => 0
func ConvInt ¶ added in v1.2.0
ConvInt convert string to int
Example ¶
var raw = "1949" var cv int // case cv = ConvInt(raw) fmt.Printf("ConvInt:%v => %v\n", raw, cv) // case raw = "+1949" cv = ConvInt(raw) fmt.Printf("ConvInt:%v => %v\n", raw, cv) // case raw = "-1949.1001" cv = ConvInt(raw) fmt.Printf("ConvInt:%v => %v\n", raw, cv) // case raw = "-2022" cv = ConvInt(raw) fmt.Printf("ConvInt:%v => %v\n", raw, cv) // case raw = "vaild" cv = ConvInt(raw) fmt.Printf("ConvInt:%v => %v\n", raw, cv)
Output: ConvInt:1949 => 1949 ConvInt:+1949 => 1949 ConvInt:-1949.1001 => -1949 ConvInt:-2022 => -2022 ConvInt:vaild => 0
Types ¶
type BaseReceiver ¶
type BaseReceiver struct {
// contains filtered or unexported fields
}
BaseReceiver the url data receiver
type DataReceiver ¶
type DataReceiver interface { Name() string Receiver(DataReceiverType, string) DataReceiver GetData() map[string]any }
DataReceiver the data parse tool
func NewDataReceiver ¶
func NewDataReceiver(vType string) (dr DataReceiver, er error)
NewDataReceiver get DataReceiver by different type.
type DataReceiverType ¶
type DataReceiverType uint8
const ( ReceiverContent DataReceiverType = iota ReceiverFile ReceiverUrl )
type JsonReceiver ¶
type JsonReceiver struct {
BaseReceiver
}
JsonReceiver the data parse grammar, support json/url
func (*JsonReceiver) GetData ¶
func (c *JsonReceiver) GetData() map[string]any
GetData get finally data by parse
func (*JsonReceiver) JsonFile ¶
func (c *JsonReceiver) JsonFile(filename string) *JsonReceiver
JsonFile parse json from json-file
func (*JsonReceiver) JsonStr ¶
func (c *JsonReceiver) JsonStr(vStr string) *JsonReceiver
JsonStr parse json string
func (*JsonReceiver) JsonUrl ¶
func (c *JsonReceiver) JsonUrl(vUrl string) *JsonReceiver
JsonUrl parse json from json-url, only http.get
func (*JsonReceiver) Name ¶
func (c *JsonReceiver) Name() string
func (*JsonReceiver) Receiver ¶
func (c *JsonReceiver) Receiver(vType DataReceiverType, content string) DataReceiver
Receiver receiver data
type UrlReceiver ¶
type UrlReceiver struct {
BaseReceiver
}
UrlReceiver the url data receiver
func (*UrlReceiver) GetData ¶
func (c *UrlReceiver) GetData() map[string]any
GetData get finally data by parse
func (*UrlReceiver) Name ¶
func (c *UrlReceiver) Name() string
func (*UrlReceiver) Receiver ¶
func (c *UrlReceiver) Receiver(vType DataReceiverType, content string) DataReceiver
Receiver receiver data
func (*UrlReceiver) UrlFile ¶
func (c *UrlReceiver) UrlFile(filename string) *UrlReceiver
UrlFile parse json from json-file
func (*UrlReceiver) UrlStr ¶
func (c *UrlReceiver) UrlStr(vStr string) *UrlReceiver
UrlStr parse json string
func (*UrlReceiver) UrlUrl ¶
func (c *UrlReceiver) UrlUrl(vUrl string) *UrlReceiver
UrlUrl parse json from json-url, only http.get