P2p、install、log package

This commit is contained in:
刘河
2019-04-21 23:03:58 +08:00
parent 45521d5680
commit f6c596f318
16 changed files with 418 additions and 203 deletions

View File

@@ -163,6 +163,13 @@ func TestUdpPort(port int) bool {
//Length prevents sticking
//# Characters are used to separate data
func BinaryWrite(raw *bytes.Buffer, v ...string) {
b := GetWriteStr(v...)
binary.Write(raw, binary.LittleEndian, int32(len(b)))
binary.Write(raw, binary.LittleEndian, b)
}
// get seq str
func GetWriteStr(v ...string) []byte {
buffer := new(bytes.Buffer)
var l int32
for _, v := range v {
@@ -170,8 +177,7 @@ func BinaryWrite(raw *bytes.Buffer, v ...string) {
binary.Write(buffer, binary.LittleEndian, []byte(v))
binary.Write(buffer, binary.LittleEndian, []byte(CONN_DATA_SEQ))
}
binary.Write(raw, binary.LittleEndian, l)
binary.Write(raw, binary.LittleEndian, buffer.Bytes())
return buffer.Bytes()
}
//inArray str interface
@@ -244,6 +250,19 @@ func GetIpByAddr(addr string) string {
return arr[0]
}
//get port from the complete address
func GetPortByAddr(addr string) int {
arr := strings.Split(addr, ":")
if len(arr) < 2 {
return 0
}
p, err := strconv.Atoi(arr[1])
if err != nil {
return 0
}
return p
}
func CopyBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
buf := pool.GetBufPoolCopy()
defer pool.PutBufPoolCopy(buf)

View File

@@ -13,6 +13,9 @@ import (
func InstallNps() {
path := common.GetInstallPath()
if common.FileExists(path) {
log.Fatalf("the path %s has exist, does not support install", path)
}
MkidrDirAll(path, "conf", "web/static", "web/views")
//复制文件到对应目录
if err := CopyDir(filepath.Join(common.GetAppPath(), "web", "views"), filepath.Join(path, "web", "views")); err != nil {

View File

@@ -1,6 +1,6 @@
package version
const VERSION = "0.22.5"
const VERSION = "0.23.0"
// Compulsory minimum version, Minimum downward compatibility to this version
func GetVersion() string {