php2go

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 41 Imported by: 0

README

PHP2Go

GoDoc Go Report Card MIT licensed

Use Golang to implement PHP's common built-in functions. About 140+ functions have been implemented.

Install

go get github.com/mj520/php2go

Requirements

Go 1.10 or above.

PHP Functions

Date/Time Functions
time()
strtotime()
date()
checkdate()
sleep()
usleep()
String Functions
strpos()
stripos()
strrpos()
strripos()
str_replace()
ucfirst()
lcfirst()
ucwords()
substr()
strrev()
number_format()
chunk_split()
str_word_count()
wordwrap()
strlen()
mb_strlen()
str_repeat()
strstr()
strtr()
str_shuffle()
trim()
ltrim()
rtrim()
explode()
strtoupper()
strtolower()
chr()
ord()
nl2br()
json_encode()
json_decode()
addslashes()
stripslashes()
quotemeta()
htmlentities()
html_entity_decode()
md5()
md5_file()
sha1()
sha1_file()
crc32()
levenshtein()
similar_text()
soundex()
parse_str()
URL Functions
base64_encode()
base64_decode()
parse_url()
urlencode()
urldecode()
rawurlencode()
rawurldecode()
http_build_query()
Array(Slice/Map) Functions
array_fill()
array_flip()
array_keys()
array_values()
array_merge()
array_chunk()
array_pad()
array_slice()
array_rand()
array_column()
array_push()
array_pop()
array_unshift()
array_shift()
array_key_exists()
array_combine()
array_reverse()
array_diff
array_unique ArrayUnique,ArrayUniqueInt
implode()
in_array()
Mathematical Functions
abs()
rand()
round()
floor()
ceil()
pi()
max()
min()
decbin()
bindec()
hex2bin()
bin2hex()
dechex()
hexdec()
decoct()
octdec()
hexbin()
binhex()
base_convert()
is_nan()
CSPRNG Functions
random_bytes()
random_int()
Directory/Filesystem Functions
stat()
pathinfo()
file_exists()
is_file()
is_dir()
filesize()
file_put_contents()
file_get_contents()
unlink()
delete()
copy()
is_readable()
is_writeable()
rename()
touch()
mkdir()
getcwd()
realpath()
basename()
chmod()
chown()
fclose()
filemtime()
fgetcsv()
glob()
Variable handling Functions
empty()
is_numeric()
Program execution Functions
exec()
system()
passthru()
Network Functions
gethostname()
gethostbyname()
gethostbynamel()
gethostbyaddr()
ip2long()
long2ip()
pack() only number
uppack() only number
Misc. Functions
echo()
uniqid()
exit()
die()
getenv()
putenv()
memory_get_usage()
memory_get_peak_usage()
version_compare()
zip_open()
Ternary(condition bool, trueVal, falseVal interface{}) interface{}

LICENSE

PHP2Go source code is licensed under the MIT Licence.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTransport = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
	}).DialContext,
	ForceAttemptHTTP2:     true,
	MaxIdleConns:          100,
	MaxIdleConnsPerHost:   100,
	IdleConnTimeout:       90 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
	DisableKeepAlives:     false,
}
View Source
var HexChar = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Functions

func Abs

func Abs(number float64) float64

Abs abs()

func Addslashes

func Addslashes(str string) string

Addslashes addslashes()

func ArrayChunk

func ArrayChunk(s []interface{}, size int) [][]interface{}

ArrayChunk array_chunk()

func ArrayColumn

func ArrayColumn(input map[string]map[string]interface{}, columnKey string) []interface{}

ArrayColumn array_column()

func ArrayCombine

func ArrayCombine(s1, s2 []interface{}) map[interface{}]interface{}

ArrayCombine array_combine()

func ArrayDiff

func ArrayDiff(array1 []string, arrayOthers ...[]string) []string

ArrayDiff array_diff()

func ArrayFill

func ArrayFill(startIndex int, num uint, value interface{}) map[int]interface{}

ArrayFill array_fill()

func ArrayFlip

func ArrayFlip(m map[interface{}]interface{}) map[interface{}]interface{}

ArrayFlip array_flip()

func ArrayKeyExists

func ArrayKeyExists(key interface{}, m map[interface{}]interface{}) bool

ArrayKeyExists array_key_exists()

func ArrayKeys

func ArrayKeys(elements map[interface{}]interface{}) []interface{}

ArrayKeys array_keys()

func ArrayMerge

func ArrayMerge(ss ...[]interface{}) []interface{}

ArrayMerge array_merge()

func ArrayPad

func ArrayPad(s []interface{}, size int, val interface{}) []interface{}

ArrayPad array_pad()

func ArrayPop

func ArrayPop(s *[]interface{}) interface{}

ArrayPop array_pop() Pop the element off the end of slice

func ArrayPush

func ArrayPush(s *[]interface{}, elements ...interface{}) int

ArrayPush array_push() Push one or more elements onto the end of slice

func ArrayRand

func ArrayRand(elements []interface{}) []interface{}

ArrayRand array_rand()

func ArrayReverse

func ArrayReverse(s []interface{}) []interface{}

ArrayReverse array_reverse()

func ArrayShift

func ArrayShift(s *[]interface{}) interface{}

ArrayShift array_shift() Shift an element off the beginning of slice

func ArraySlice

func ArraySlice(s []interface{}, offset, length uint) []interface{}

ArraySlice array_slice()

func ArrayUnique

func ArrayUnique(arr []string) []string

ArrayUnique array_unique()

func ArrayUniqueInt

func ArrayUniqueInt(arr []int) []int

ArrayUniqueInt array_unique()

func ArrayUnshift

func ArrayUnshift(s *[]interface{}, elements ...interface{}) int

ArrayUnshift array_unshift() Prepend one or more elements to the beginning of a slice

func ArrayValues

func ArrayValues(elements map[interface{}]interface{}) []interface{}

ArrayValues array_values()

func Base64Decode

func Base64Decode(str string) (string, error)

Base64Decode base64_decode()

func Base64Encode

func Base64Encode(str string) string

Base64Encode base64_encode()

func BaseConvert

func BaseConvert(number string, frombase, tobase int) (string, error)

BaseConvert base_convert()

func Basename

func Basename(path string) string

Basename basename()

func Bin2hex

func Bin2hex(str string) (string, error)

Bin2hex bin2hex()

func Bindec

func Bindec(str string) (int64, error)

Bindec bindec()

func Binhex

func Binhex(str string) (string, error)

Binhex binhex()

func Bytes2ToInt64

func Bytes2ToInt64(b []byte) int64

Bytes2ToInt64 byte2 转 int64

func Bytes4ToInt64

func Bytes4ToInt64(b []byte) int64

Bytes4ToInt64 byte4 转 int64

func Bytes8ToInt64

func Bytes8ToInt64(buf []byte) int64

Bytes8ToInt64 byte8 转 int64

func Ceil

func Ceil(value float64) float64

Ceil ceil()

func Checkdate

func Checkdate(month, day, year int) bool

Checkdate checkdate() Validate a Gregorian date

func Chmod

func Chmod(filename string, mode os.FileMode) bool

Chmod chmod()

func Chown

func Chown(filename string, uid, gid int) bool

Chown chown()

func Chr

func Chr(ascii int) string

Chr chr()

func ChunkSplit

func ChunkSplit(body string, chunklen uint, end string) string

ChunkSplit chunk_split()

func Copy

func Copy(source, dest string) (bool, error)

Copy copy()

func Crc32

func Crc32(str string) uint32

Crc32 crc32()

func Date

func Date(format string, timestamp int64) string

Date date() Date("02/01/2006 15:04:05 PM", 1524799394) Note: the behavior is inconsistent with php's date function

func DecHex

func DecHex(number int64) string

DecHex dechex()

func Decbin

func Decbin(number int64) string

Decbin decbin()

func Dechex

func Dechex(number int64) string

Dechex dechex()

func Decoct

func Decoct(number int64) string

Decoct decoct()

func Delete

func Delete(filename string) error

Delete delete()

func Die

func Die(status int)

Die die()

func DiskFreeSpace

func DiskFreeSpace(directory string) (uint64, error)

DiskFreeSpace disk_free_space()

func DiskTotalSpace

func DiskTotalSpace(directory string) (uint64, error)

DiskTotalSpace disk_total_space()

func Echo

func Echo(args ...interface{})

Echo echo

func Empty

func Empty(val interface{}) bool

Empty empty()

func Exec

func Exec(command string, output *[]string, returnVar *int) string

Exec exec() returnVar, 0: succ; 1: fail Return the last line from the result of the command. command format eg:

"ls -a"
"/bin/bash -c \"ls -a\""

func Exit

func Exit(status int)

Exit exit()

func Explode

func Explode(delimiter, str string) []string

Explode explode()

func Fclose

func Fclose(handle *os.File) error

Fclose fclose()

func Fgetcsv

func Fgetcsv(handle *os.File, length int, delimiter rune) ([][]string, error)

Fgetcsv fgetcsv()

func FileExists

func FileExists(filename string) bool

FileExists file_exists()

func FileGetContents

func FileGetContents(filename string) (string, error)

FileGetContents file_get_contents()

func FilePutContents

func FilePutContents(filename string, data string, mode os.FileMode) error

FilePutContents file_put_contents()

func FileSize

func FileSize(filename string) (int64, error)

FileSize filesize()

func Filemtime

func Filemtime(filename string) (int64, error)

Filemtime filemtime()

func Floor

func Floor(value float64) float64

Floor floor()

func GetAgentServiceCheck added in v1.1.1

func GetAgentServiceCheck(service *api.AgentServiceRegistration, remotePort int, checkPath string) *api.AgentServiceCheck

GetAgentServiceCheck 健康检查 checkPath!=tcp 走http 为空时 默认/health CONSUL_FRP=1 特殊使用 http 检查路径为 /{checkPath}/{service.ID} 注意绑定 http.HandleFunc("/health/", Health) 注意斜杠兼容 增加的server.ID

func GetClient added in v1.2.2

func GetClient() *http.Client

GetClient 获取新的客户端

func GetClientIp added in v1.2.3

func GetClientIp(r *http.Request) (ip string)

GetClientIp 获取客户端IP

func GetFrpConfig added in v1.1.1

func GetFrpConfig() config.ClientCommonConf

func GetHttpClient added in v1.2.2

func GetHttpClient() *http.Client

GetHttpClient 建议使用连接池复用 或 使用 github.com/go-resty/resty/v2

func GetInBoundIP added in v1.1.0

func GetInBoundIP() string

GetInBoundIP 获取入口 外网ip

func GetInterfaceToFloat

func GetInterfaceToFloat(value interface{}) float64

GetInterfaceToFloat interface 转 float64

func GetInterfaceToInt

func GetInterfaceToInt(value interface{}) int

GetInterfaceToInt interface 转 int

func GetInterfaceToString

func GetInterfaceToString(value interface{}) string

GetInterfaceToString interface 转 string

func GetOutBoundIP added in v1.1.0

func GetOutBoundIP() string

GetOutBoundIP 获取出口ip 内网

func Getcwd

func Getcwd() (string, error)

Getcwd getcwd()

func Getenv

func Getenv(varname string) string

Getenv getenv()

func Gethostbyaddr

func Gethostbyaddr(ipAddress string) (string, error)

Gethostbyaddr gethostbyaddr() Get the Internet host name corresponding to a given IP address

func Gethostbyname

func Gethostbyname(hostname string) (string, error)

Gethostbyname gethostbyname() Get the IPv4 address corresponding to a given Internet host name

func Gethostbynamel

func Gethostbynamel(hostname string) ([]string, error)

Gethostbynamel gethostbynamel() Get a list of IPv4 addresses corresponding to a given Internet host name

func Gethostname

func Gethostname() (string, error)

Gethostname gethostname()

func Glob

func Glob(pattern string) ([]string, error)

Glob glob()

func HTMLEntityDecode

func HTMLEntityDecode(str string) string

HTMLEntityDecode html_entity_decode()

func HTTPBuildQuery

func HTTPBuildQuery(queryData url.Values) string

HTTPBuildQuery http_build_query()

func Hex2bin

func Hex2bin(h string) (str string, err error)

Hex2bin hex2bin() to AscII

func HexDec

func HexDec(str string) int64

HexDec hexdec()

func HexDecode

func HexDecode(code string, hex int64) int64

HexDecode 进制数还原 n 表示进制, 16 or 36 or 62

func HexEncode

func HexEncode(num, hex int64) string

HexEncode 进制数转换 n 表示进制, 16 or 36 or 62

func Hexbin

func Hexbin(str string) (string, error)

Hexbin hexbin()

func Hexdec

func Hexdec(str string) (int64, error)

Hexdec hexdec()

func Htmlentities

func Htmlentities(str string) string

Htmlentities htmlentities()

func HttpDo added in v1.2.2

func HttpDo(url string, param string, method string) ([]byte, error)

func HttpGet added in v1.2.2

func HttpGet(url string) ([]byte, error)

func HttpJson added in v1.2.2

func HttpJson(url string, data interface{}) ([]byte, error)

func IP2long

func IP2long(ipAddress string) uint32

IP2long ip2long() IPv4

func Implode

func Implode(glue string, pieces []string) string

Implode implode()

func InArray

func InArray(needle interface{}, haystack interface{}) bool

InArray in_array() haystack supported types: slice, array or map

func IntToBytes1

func IntToBytes1(n int64) []byte

IntToBytes1 int64 转 byte1

func IntToBytes2

func IntToBytes2(n int64) []byte

IntToBytes2 int64 转 byte2

func IntToBytes4

func IntToBytes4(n int64) []byte

IntToBytes4 int64 转 byte4

func IntToBytes8

func IntToBytes8(n int64) []byte

IntToBytes8 int64 转 byte8

func IsDir

func IsDir(filename string) (bool, error)

IsDir is_dir()

func IsFile

func IsFile(filename string) bool

IsFile is_file()

func IsFrp added in v1.1.1

func IsFrp() bool

func IsNan

func IsNan(val float64) bool

IsNan is_nan()

func IsNumeric

func IsNumeric(val interface{}) bool

IsNumeric is_numeric() Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part. Thus +0123.45e6 is a valid numeric value. In PHP hexadecimal (e.g. 0xf4c3b00c) is not supported, but IsNumeric is supported.

func IsReadable

func IsReadable(filename string) bool

IsReadable is_readable()

func IsWriteable

func IsWriteable(filename string) bool

IsWriteable is_writeable()

func JSONDecode

func JSONDecode(data []byte, val interface{}) error

JSONDecode json_decode()

func JSONEncode

func JSONEncode(val interface{}) ([]byte, error)

JSONEncode json_encode()

func Lcfirst

func Lcfirst(str string) string

Lcfirst lcfirst()

func Levenshtein

func Levenshtein(str1, str2 string, costIns, costRep, costDel int) int

Levenshtein levenshtein() costIns: Defines the cost of insertion. costRep: Defines the cost of replacement. costDel: Defines the cost of deletion.

func Long2ip

func Long2ip(properAddress uint32) string

Long2ip long2ip() IPv4

func Ltrim

func Ltrim(str string, characterMask ...string) string

Ltrim ltrim()

func Max

func Max(nums ...float64) float64

Max max()

func MbStrlen

func MbStrlen(str string) int

MbStrlen mb_strlen()

func Md5

func Md5(str string) string

Md5 md5()

func Md5File

func Md5File(path string) (string, error)

Md5File md5_file()

func MemoryGetPeakUsage

func MemoryGetPeakUsage(realUsage bool) uint64

MemoryGetPeakUsage memory_get_peak_usage() return in bytes

func MemoryGetUsage

func MemoryGetUsage(realUsage bool) uint64

MemoryGetUsage memory_get_usage() return in bytes

func Min

func Min(nums ...float64) float64

Min min()

func Mkdir

func Mkdir(filename string, mode os.FileMode) error

Mkdir mkdir()

func Nl2br

func Nl2br(str string, isXhtml bool) string

Nl2br nl2br() \n\r, \r\n, \r, \n

func NumberFormat

func NumberFormat(number float64, decimals uint, decPoint, thousandsSep string) string

NumberFormat number_format() decimals: Sets the number of decimal points. decPoint: Sets the separator for the decimal point. thousandsSep: Sets the thousands' separator.

func Octdec

func Octdec(str string) (int64, error)

Octdec Octdec()

func Ord

func Ord(char string) int

Ord ord()

func Pack

func Pack(format []string, args ...int64) string

Pack pack() only number

func ParseStr

func ParseStr(encodedString string, result map[string]interface{}) error

ParseStr parse_str() f1=m&f2=n -> map[f1:m f2:n] f[a]=m&f[b]=n -> map[f:map[a:m b:n]] f[a][a]=m&f[a][b]=n -> map[f:map[a:map[a:m b:n]]] f[]=m&f[]=n -> map[f:[m n]] f[a][]=m&f[a][]=n -> map[f:map[a:[m n]]] f[][]=m&f[][]=n -> map[f:[map[]]] // Currently does not support nested slice. f=m&f[a]=n -> error // This is not the same as PHP. a .[[b=c -> map[a___[b:c]

func ParseURL

func ParseURL(str string, component int) (map[string]string, error)

ParseURL parse_url() Parse a URL and return its components -1: all; 1: scheme; 2: host; 4: port; 8: user; 16: pass; 32: path; 64: query; 128: fragment

func Passthru

func Passthru(command string, returnVar *int)

Passthru passthru() returnVar, 0: succ; 1: fail

func Pathinfo

func Pathinfo(path string, options int) map[string]string

Pathinfo pathinfo() -1: all; 1: dirname; 2: basename; 4: extension; 8: filename Usage: Pathinfo("/home/go/path/src/php2go/php2go.go", 1|2|4|8)

func Pi

func Pi() float64

Pi pi()

func Putenv

func Putenv(setting string) error

Putenv putenv() The setting, like "FOO=BAR"

func Quotemeta

func Quotemeta(str string) string

Quotemeta quotemeta()

func Rand

func Rand(min, max int) int

Rand rand() Range: [0, 2147483647]

func RandStringRunes added in v1.2.2

func RandStringRunes(l int, runes string) string

RandStringRunes - generate random string using random int

func RandomBytes

func RandomBytes(length int) ([]byte, error)

RandomBytes random_bytes()

func RandomInt

func RandomInt(min, max int) (int, error)

RandomInt random_int()

func RandomString added in v1.2.2

func RandomString(l int) string

RandomString - Generate a random string of a-z chars with len = l

func Rawurldecode

func Rawurldecode(str string) (string, error)

Rawurldecode rawurldecode()

func Rawurlencode

func Rawurlencode(str string) string

Rawurlencode rawurlencode()

func Realpath

func Realpath(path string) (string, error)

Realpath realpath()

func Rename

func Rename(oldname, newname string) error

Rename rename()

func Round

func Round(value float64, precision int) float64

Round round()

func Rtrim

func Rtrim(str string, characterMask ...string) string

Rtrim rtrim()

func SetAgentServiceProxyFrp added in v1.1.1

func SetAgentServiceProxyFrp(service *api.AgentServiceRegistration, remotePort int, checkPath string)

SetAgentServiceProxyFrp CONSUL_FRP_ADDR=必须子域名;CONSUL_FRP_PORT=7000;CONSUL_FRP_TOKEN=;CONSUL_FRP=1

func Sha1

func Sha1(str string) string

Sha1 sha1()

func Sha1File

func Sha1File(path string) (string, error)

Sha1File sha1_file()

func SimilarText

func SimilarText(first, second string, percent *float64) int

SimilarText similar_text()

func Sleep

func Sleep(t int64)

Sleep sleep()

func Soundex

func Soundex(str string) string

Soundex soundex() Calculate the soundex key of a string.

func Stat

func Stat(filename string) (os.FileInfo, error)

Stat stat()

func StrRepeat

func StrRepeat(input string, multiplier int) string

StrRepeat str_repeat()

func StrReplace

func StrReplace(search, replace, subject string, count int) string

StrReplace str_replace()

func StrShuffle

func StrShuffle(str string) string

StrShuffle str_shuffle()

func StrWordCount

func StrWordCount(str string) []string

StrWordCount str_word_count()

func Stripos

func Stripos(haystack, needle string, offset int) int

Stripos stripos()

func Stripslashes

func Stripslashes(str string) string

Stripslashes stripslashes()

func Strlen

func Strlen(str string) int

Strlen strlen()

func Strpos

func Strpos(haystack, needle string, offset int) int

Strpos strpos()

func Strrev

func Strrev(str string) string

Strrev strrev()

func Strripos

func Strripos(haystack, needle string, offset int) int

Strripos strripos()

func Strrpos

func Strrpos(haystack, needle string, offset int) int

Strrpos strrpos()

func Strstr

func Strstr(haystack string, needle string) string

Strstr strstr()

func Strtolower

func Strtolower(str string) string

Strtolower strtolower()

func Strtotime

func Strtotime(format, strtime string) (int64, error)

Strtotime strtotime() Strtotime("02/01/2006 15:04:05", "02/01/2016 15:04:05") == 1451747045 Strtotime("3 04 PM", "8 41 PM") == -62167144740

func Strtoupper

func Strtoupper(str string) string

Strtoupper strtoupper()

func Strtr

func Strtr(haystack string, params ...interface{}) string

Strtr strtr()

If the parameter length is 1, type is: map[string]string Strtr("baab", map[string]string{"ab": "01"}) will return "ba01" If the parameter length is 2, type is: string, string Strtr("baab", "ab", "01") will return "1001", a => 0; b => 1.

func Substr

func Substr(str string, start uint, length int) string

Substr substr()

func System

func System(command string, returnVar *int) string

System system() returnVar, 0: succ; 1: fail Returns the last line of the command output on success, and "" on failure.

func Ternary

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

Ternary Ternary expression max := Ternary(a > b, a, b).(int)

func Time

func Time() int64

Time time()

func Touch

func Touch(filename string) (bool, error)

Touch touch()

func Trim

func Trim(str string, characterMask ...string) string

Trim trim()

func URLDecode

func URLDecode(str string) (string, error)

URLDecode urldecode()

func URLEncode

func URLEncode(str string) string

URLEncode urlencode()

func Ucfirst

func Ucfirst(str string) string

Ucfirst ucfirst()

func Ucwords

func Ucwords(str string) string

Ucwords ucwords()

func Umask

func Umask(mask int) int

Umask umask()

func Uniqid

func Uniqid(prefix string) string

Uniqid uniqid()

func Unlink(filename string) error

Unlink unlink()

func Unpack

func Unpack(format []string, data string) []int64

Unpack unpack() only number

func Usleep

func Usleep(t int64)

Usleep usleep()

func VersionCompare

func VersionCompare(version1, version2, operator string) bool

VersionCompare version_compare() The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively. special version strings these are handled in the following order, (any string not found) < dev < alpha = a < beta = b < RC = rc < # < pl = p Usage: VersionCompare("1.2.3-alpha", "1.2.3RC7", '>=') VersionCompare("1.2.3-beta", "1.2.3pl", 'lt') VersionCompare("1.1_dev", "1.2any", 'eq')

func Wordwrap

func Wordwrap(str string, width uint, br string, cut bool) string

Wordwrap wordwrap()

func ZipOpen

func ZipOpen(filename string) (*zip.ReadCloser, error)

ZipOpen zip_open()

Types

type Client added in v1.1.0

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

func NewClient added in v1.1.0

func NewClient(ip string, port int) Client

NewClient client

func (Client) GetAddress added in v1.1.0

func (a Client) GetAddress() string

func (Client) GetIp added in v1.1.0

func (a Client) GetIp() string

func (Client) GetPort added in v1.1.0

func (a Client) GetPort() int

func (Client) Ip added in v1.1.0

func (a Client) Ip() uint32

func (Client) Port added in v1.1.0

func (a Client) Port() uint16

type Connection added in v1.1.0

type Connection struct {
	Server
	Client
	// contains filtered or unexported fields
}

Connection 24字符串16进制 连接协议

func NewConnection added in v1.1.0

func NewConnection(clientIp string, clientPort int) *Connection

NewConnection 连接传入

func (*Connection) Id added in v1.1.0

func (c *Connection) Id() uint32

func (*Connection) Pack added in v1.1.0

func (c *Connection) Pack() string

Pack 编码

func (*Connection) ReleaseId added in v1.1.0

func (c *Connection) ReleaseId(id uint32)

ReleaseId 释放id

func (*Connection) UnPack added in v1.1.0

func (c *Connection) UnPack(id string)

UnPack 编码

type ConsulApi added in v1.1.1

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

func NewConsul added in v1.1.1

func NewConsul(addr string, auth string) (*ConsulApi, error)

NewConsul 连接至consul服务返回一个ConsulApi对象

func (*ConsulApi) GetClient added in v1.1.1

func (c *ConsulApi) GetClient() *api.Client

func (*ConsulApi) GetLock added in v1.1.1

func (c *ConsulApi) GetLock(key string, value string, ttl string) (lock *api.Lock, err error)

func (*ConsulApi) GetRegisterService added in v1.1.1

func (c *ConsulApi) GetRegisterService(tag string, ip string, port int) *api.AgentServiceRegistration

func (*ConsulApi) RegisterService added in v1.1.1

func (c *ConsulApi) RegisterService(service *api.AgentServiceRegistration, check *api.AgentServiceCheck) error

RegisterService 将服务注册到consul 健康检查 服务名称相同的才会返回多个

func (*ConsulApi) Service added in v1.1.1

func (c *ConsulApi) Service(service string) ([]*api.ServiceEntry, error)

Service 服务发现 服务名称相同的才会返回多个

func (*ConsulApi) ServiceDeregister added in v1.1.1

func (c *ConsulApi) ServiceDeregister(serviceID string) error

ServiceDeregister 注销服务

func (*ConsulApi) ServiceList added in v1.1.1

func (c *ConsulApi) ServiceList(tag string) (map[string]*api.AgentService, error)

ServiceList 服务列表

func (*ConsulApi) ServiceWatch added in v1.1.1

func (c *ConsulApi) ServiceWatch(service string, handle watch.HandlerFunc)

ServiceWatch 服务监控

func (*ConsulApi) WatchKeyToPath added in v1.2.5

func (c *ConsulApi) WatchKeyToPath(key string, path string, t string)

WatchKeyToPath watch key or keyprefix to path t 默认 目录监控 path 目录 + key 取文件部分 t=key path 目录 + key 取文件部分 t=source 转 t=file path=key t=file path是空=key 必须是文件(含路径)

func (*ConsulApi) WatchPathKey added in v1.2.5

func (c *ConsulApi) WatchPathKey(path string, key string, t string)

type Protocol

type Protocol struct {
	Format []string
}

func (*Protocol) DecToHexString

func (p *Protocol) DecToHexString(decString []byte) (responseStr string)

DecToHexString 10进制转16进制字符串

func (*Protocol) HexStringToByte

func (p *Protocol) HexStringToByte(hexString string) (responseByte []byte)

HexStringToByte 16进制字符串转字节类型

func (*Protocol) Pack

func (p *Protocol) Pack(args ...int64) (ret []byte)

Pack 编码

func (*Protocol) Pack16

func (p *Protocol) Pack16(args ...int64) (hString string)

Pack16 转成16进制编码字符串

func (*Protocol) UnPack

func (p *Protocol) UnPack(data []byte) []int64

UnPack 解码

func (*Protocol) UnPack16

func (p *Protocol) UnPack16(hString string) (unIntList []int64)

UnPack16 解码16进制字符串

type Server added in v1.1.0

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

func GetServer added in v1.1.0

func GetServer() Server

GetServer 共享 必须先NewServer

func NewServer added in v1.1.0

func NewServer(ip string, port interface{}) Server

NewServer 注入共享服务的ip 和 port

func (Server) GetAddress added in v1.1.0

func (a Server) GetAddress() string

func (Server) GetIp added in v1.1.0

func (a Server) GetIp() string

func (Server) GetPort added in v1.1.0

func (a Server) GetPort() int

func (Server) Ip added in v1.1.0

func (a Server) Ip() uint32

func (Server) Port added in v1.1.0

func (a Server) Port() uint16

Jump to

Keyboard shortcuts

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