package mokuai import ( "encoding/binary" "io/ioutil" "math" "net/http" "strconv" ) // 整数型转文本型(int) func Type_IntToString(i int) string { return strconv.Itoa(i) } // 文本型转整数型(int) func Type_StringToInt(str string) int { i, _ := strconv.Atoi(str) return i } // string到int64 func Type_StringToInt64(str string) int64 { i64, _ := strconv.ParseInt(str, 10, 64) return i64 } // int64到string func Type_Int64ToString(i64 int64) string { str := strconv.FormatInt(i64, 10) return str } // int到int64 func Type_IntToInt64(i int) int64 { return int64(i) } // int64到int func Type_Int64ToInt(i64 int64) int { return int(i64) } /* // float(32)到string func Type_FloatToString(f float32) string { return strconv.FormatFloat(f,'E',-1,32) }*/ // float(64)到string func Type_Float64ToString(f64 float64) string { return strconv.FormatFloat(f64, 'E', -1, 64) } /* //string到float(32) func Type_StringToFloat(str string) float32 { f , _ := strconv.ParseFloat(str,32) return f }*/ // string到float(64) func Type_StringToFloat64(str string) float64 { f64, _ := strconv.ParseFloat(str, 64) return f64 } // float(32)到Byte func Type_FloatToByte(float float32) []byte { bits := math.Float32bits(float) bytes := make([]byte, 4) binary.LittleEndian.PutUint32(bytes, bits) return bytes } // Byte到float(32) func Type_ByteToFloat(bytes []byte) float32 { bits := binary.LittleEndian.Uint32(bytes) return math.Float32frombits(bits) } // float(64)到Byte func Type_Float64ToByte(float float64) []byte { bits := math.Float64bits(float) bytes := make([]byte, 8) binary.LittleEndian.PutUint64(bytes, bits) return bytes } // Byte到float(64) func Type_ByteToFloat64(bytes []byte) float64 { bits := binary.LittleEndian.Uint64(bytes) return math.Float64frombits(bits) } // string 转 []byte func Type_StringToByte(str string) []byte { return []byte(str) } // []byte 转 string func Type_ByteToString(byteval []byte) string { return string(byteval) } // string 转 rune func Type_StringToRune(str string) []rune { return []rune(str) } // rune 转 string func Type_RuneToString(runeval []rune) string { return string(runeval) } // Response 转 string func Type_ResponseToString(resp http.Response) string { bodyRes, _ := ioutil.ReadAll(resp.Body) return string(bodyRes) } // Response 转 []byte func Type_ResponseToByte(resp http.Response) []byte { bodyRes, _ := ioutil.ReadAll(resp.Body) return bodyRes }