一些测试文件

pull/29/head
taoshihan1991 4 years ago
parent 07b9a1ba9c
commit d9bdfaf2ef

@ -62,6 +62,16 @@ func getIpFromAddr(addr net.Addr) net.IP {
return ip
}
func GetExternalIp() string {
return Get("http://myexternalip.com/raw")
//获取出站IP地址
func GetOutboundIP() (net.IP, error) {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
return nil, err
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP, nil
}

@ -0,0 +1,11 @@
package tools
import (
"log"
"testing"
)
func TestGetOutboundIP(t *testing.T) {
ip, err := GetOutboundIP()
log.Println(ip, err)
}

@ -0,0 +1,52 @@
package tools
import "fmt"
func MyTest() {
type MConn struct {
Name string
}
var conn *MConn
var conn2 MConn
conn3 := new(MConn)
conn4 := &MConn{}
fmt.Printf("%v,%v,%v,%v \r\n", conn, conn2, conn3, conn4)
var mMap map[string][]*MConn
m1, _ := mMap["name"]
//if ok {
// m1.Name = "qqq"
//}
fmt.Printf("ssss%T", m1)
}
func MyStruct() {
type s2 struct {
name string
}
aa := s2{
name: "aa",
}
bb := s2{
name: "aa",
}
fmt.Printf("%v\n", aa == bb)
type s1 struct {
one map[string]string
two []string
three string
}
a := &s1{
one: map[string]string{"aaa": "bbb"},
two: []string{"aaa", "bbb"},
three: "aaaa",
}
b := &s1{
one: map[string]string{"aaa": "bbb"},
two: []string{"aaa", "bbb"},
three: "aaaa",
}
c := a
fmt.Printf("%v;%v", a == b, a == c)
}

@ -0,0 +1,49 @@
package tools
import (
"sync"
"testing"
)
func TestMyTest(t *testing.T) {
MyTest()
}
func TestMyStruct(t *testing.T) {
MyStruct()
}
type SMap struct {
sync.RWMutex
Map map[int]int
}
func (l *SMap) readMap(key int) (int, bool) {
l.RLock()
value, ok := l.Map[key]
l.RUnlock()
return value, ok
}
func (l *SMap) writeMap(key int, value int) {
l.Lock()
l.Map[key] = value
l.Unlock()
}
var mMap *SMap
func TestMyMap(t *testing.T) {
mMap = &SMap{
Map: make(map[int]int),
}
for i := 0; i < 10000; i++ {
go func() {
mMap.writeMap(i, i)
}()
go readMap(i)
}
}
func readMap(i int) (int, bool) {
return mMap.readMap(i)
}

@ -0,0 +1,13 @@
package tools
import (
"go-fly-muti/frpc"
"testing"
)
func TestClientRpc(t *testing.T) {
frpc.ClientRpc()
}
func TestServerRpc(t *testing.T) {
frpc.NewRpcServer("127.0.0.1:8082")
}

@ -14,7 +14,8 @@ func SendSmtp(server string, from string, password string, to []string, subject
"From: " + from + "\r\n" +
"To: " + strings.Join(to, ",") + "\r\n" +
"Subject: =?UTF-8?B?" + subjectBase + "?=\r\n" +
"\r\n" +
"Content-Type: text/html; charset=UTF-8" +
"\r\n\r\n" +
body + "\r\n")
err := smtp.SendMail(server, auth, from, to, msg)
if err != nil {

@ -0,0 +1,8 @@
package tools
import "testing"
func TestSendSmtp(t *testing.T) {
body := "<a href=''>hello</a>"
SendSmtp("smtp.sina.cn:25", "taoshihan1@sina.com", "382e8a5e11cfae8c", []string{"taoshihan1@sina.com"}, "123456", body)
}

@ -1,5 +1,20 @@
package tools
import "sort"
func SortMap(youMap map[string]interface{}) []interface{} {
keys := make([]string, 0)
for k, _ := range youMap {
keys = append(keys, k)
}
myMap := make([]interface{}, 0)
sort.Strings(keys)
for _, k := range keys {
myMap = append(myMap, youMap[k])
}
return myMap
}
//划分
func partition(arr *[]int, left int, right int) int {
privot := (*arr)[right]

@ -1,15 +1,5 @@
package tools
import (
"fmt"
"mime"
)
func MyPointer() {
func main() {
dec := new(mime.WordDecoder)
header, err := dec.DecodeHeader("=?utf-8?q?=C3=89ric?= <eric@example.org>, =?utf-8?q?Ana=C3=AFs?= <anais@example.org>")
if err != nil {
panic(err)
}
fmt.Println(header)
}

@ -0,0 +1 @@
package tools
Loading…
Cancel
Save