示例#1
0
func TestHttpService(t *testing.T) {
	service := hprose.NewHttpService()
	service.AddFunction("hello", hello)
	service.AddMethods(new(testServe))
	server := httptest.NewServer(service)
	defer server.Close()
	client := hprose.NewClient(server.URL)
	var ro *testRemoteObject2
	client.UseService(&ro)
	if s, err := ro.Hello("World"); err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(s)
	}
	if a, b, err := ro.Swap(1, 2); err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(a, b)
	}
	if sum, err := ro.Sum(1); err != nil {
		fmt.Println(err.Error())
	} else {
		t.Error(sum)
	}
	if sum, err := ro.Sum(1, 2, 3, 4, 5); err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(sum)
	}
	if err := ro.PanicTest(); err != nil {
		fmt.Println(err.Error())
	} else {
		t.Error("missing panic")
	}
}
func main() {
	client := hprose.NewClient("tcp4://1.1.1.1:4321/")
	var vmstl *VmsTemplateList
	client.UseService(&vmstl)
	var getvmsip *GetVmsIp
	client.UseService(&getvmsip)

	act := flag.String("act", "", "Please tell me what will you do!")
	instance := flag.String("instance", "", "Please tell me the vms instance!")

	flag.Parse()

	if *act != "" {
		switch *act {
		case "addtpl":
			tpls := vmstl.Vmstl()
			for _, v := range tpls {
				fmt.Println(v) //	For debug
				models.AddVmsTpl(v, "")
			}
		case "getip":
			for _, v := range models.GetVmsUuidByInstance(*instance) {
				models.UpdateVmsIp(v, getvmsip.GetVmsIp(v))
			}
		}
	}
}
func main() {
	client := hprose.NewClient("tcp4://1.1.1.1:4321/")
	var cvft *CreateVmsFromTpl
	client.UseService(&cvft)

	tpl := flag.String("tpl", "", "Please give me the vms_template!")
	num := flag.Int("num", 1, "Please tell me how many vms do you want to create!")
	//	creator := flag.String("creator", "root", "Who create the vms?")
	//	pub := flag.Int("public", 1 , "Is the vms opened?")

	flag.Parse()

	if models.IsExistVmsTpl(*tpl) {
		rst, uuids, vmsinfo := cvft.Cvft(*tpl, *num)
		fmt.Println(rst)
		for _, v := range uuids {
			fmt.Println(v)
		}
		fmt.Println(vmsinfo)
		for _, vms := range vmsinfo {
			p_v := &vms
			fmt.Println(p_v.Vms_ip)
			models.AddVmsInstance(*tpl, p_v.Vms_instance, p_v.Vms_uuid, p_v.Vms_ip)
		}
	} else {
		fmt.Println("虚拟机模板不存在!")
	}
}
示例#4
0
func main() {
	hprose.ClassManager.Register(reflect.TypeOf(A{}), "A", "json")
	client := hprose.NewClient("http://127.0.0.1:8080/")
	var stub *Stub
	client.UseService(&stub)
	fmt.Println(stub.Hello("world"))
	stub.GetEmptySlice()
}
示例#5
0
文件: test.go 项目: qgweb/gopro
func main1() {
	client := hprose.NewClient("tcp://127.0.0.1:12345/")
	var ro *clientStub
	client.UseService(&ro)
	fmt.Println(ro.Hello("World"))
	fmt.Println(ro.Swap(1, 2))
	fmt.Println(ro.Sum(1, 2, 3, 4, 5))
	fmt.Println(ro.Sum(1))
}
示例#6
0
func main() {
	hprose.ClassManager.Register(reflect.TypeOf(User{}), "User", "json")
	client := hprose.NewClient("http://127.0.0.1:8080/")
	var stub *Stub
	client.UseService(&stub)
	user := stub.GetUser()
	fmt.Println(user.Name)
	fmt.Println(user.Age)
	fmt.Println(user.HaHa)
}
示例#7
0
func main() {
	client := hprose.NewClient("tcp4://127.0.0.1:4321/").(*hprose.TcpClient)
	client.AddFilter(MyClientFilter{})
	var stub Stub
	client.UseService(&stub)
	go fmt.Println(stub.Inc())
	go fmt.Println(stub.Inc())
	go fmt.Println(stub.Inc())
	go fmt.Println(stub.Inc())
	fmt.Println(stub.Inc())
}
示例#8
0
文件: client.go 项目: qgweb/new
func main() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		client := hprose.NewClient("http://127.0.0.1:12345")
		var ro Test
		client.UseService(&ro)
		(ro.RecordAdvertPutInfo(map[string]string{
			"ad":     "aaaa",
			"ua":     "bbbb",
			"pv":     "1",
			"click":  "1",
			"advert": "22",
		}))
	})
	http.ListenAndServe(":8888", nil)
}
func main() {

	//	act := flag.String("act", "", "please give me the command")
	ip := flag.String("ip", "", "Please enter the ip address!")
	mask := flag.String("mask", "", "Please enter the netmask!")
	gateway := flag.String("gw", "", "Please enter the gateway!")

	flag.Parse()

	client := hprose.NewClient("http://172.16.1.231:8080/")

	var ipset *IpSet
	client.UseService(&ipset)
	fmt.Println(ipset.IpSet("1.1.1.1", "24", "1.1.1.254"))
	fmt.Println(ipset.IpSet(*ip, *mask, *gateway))
}
func main() {

	//	act := flag.String("act", "", "please give me the command")
	subnet := flag.String("subnet", "", "Please enter the subnet address!")
	mask := flag.String("mask", "", "Please enter the netmask!")
	start := flag.String("start", "", "Please enter the start ip address!")
	end := flag.String("end", "", "Please enter the end ip address!")
	routers := flag.String("rt", "", "Please enter the routers!")

	flag.Parse()

	client := hprose.NewClient("http://172.16.1.231:8080/")

	var dhcpset *DhcpSet
	client.UseService(&dhcpset)
	fmt.Println(dhcpset.DhcpSet("1.1.1.1", "24", "1.1.1.10", "1.1.1.100", "1.1.1.254"))
	fmt.Println(dhcpset.DhcpSet(*subnet, *mask, *start, *end, *routers))
}
示例#11
0
func TestTcpServiceAsync(t *testing.T) {
	server := hprose.NewTcpServer("")
	server.AddFunction("hello", hello)
	server.AddMethods(new(testServe))
	server.Start()
	defer server.Stop()
	client := hprose.NewClient(server.URL)
	var ro *testRemoteObject3
	client.UseService(&ro)
	s, err1 := ro.Hello("World")
	a, b, err2 := ro.Swap(1, 2)
	sum1, err3 := ro.Sum(1)
	if err := <-err1; err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(<-s)
	}
	if err := <-err2; err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(<-a, <-b)
	}
	if err := <-err3; err != nil {
		fmt.Println(err.Error())
	} else {
		t.Error(<-sum1)
	}
	sum2, err4 := ro.Sum(1, 2, 3, 4, 5)
	err5 := ro.PanicTest()
	if err := <-err4; err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(<-sum2)
	}
	if err := <-err5; err != nil {
		fmt.Println(err.Error())
	} else {
		t.Error("missing panic")
	}
}
示例#12
0
func TestTcpService(t *testing.T) {
	server := hprose.NewTcpServer("")
	server.AddFunction("hello", hello)
	server.AddMethods(new(testServe))
	server.AddFunction("getIP", getIP)
	server.Start()
	defer server.Stop()
	client := hprose.NewClient(server.URL)
	var ro *testRemoteObject2
	client.UseService(&ro)
	if s, err := ro.Hello("World"); err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(s)
	}
	if a, b, err := ro.Swap(1, 2); err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(a, b)
	}
	if sum, err := ro.Sum(1); err != nil {
		fmt.Println(err.Error())
	} else {
		t.Error(sum)
	}
	if sum, err := ro.Sum(1, 2, 3, 4, 5); err != nil {
		t.Error(err.Error())
	} else {
		fmt.Println(sum)
	}
	fmt.Println(ro.GetIP())
	if err := ro.PanicTest(); err != nil {
		fmt.Println(err.Error())
	} else {
		t.Error("missing panic")
	}
}
示例#13
0
func main() {
	client := hprose.NewClient("tcp4://127.0.0.1:4321/")
	var stub *Stub
	client.UseService(&stub)
	fmt.Println(stub.Hello("world"))
}