Пример #1
0
func main() {

	fmt.Println("Hello World!")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	for i := 0; i < cap(clientsPool); i++ {
		socket, err := thrift.NewTSocketTimeout(hostUds, 1*time.Second)
		if err != nil {
			log.Fatal("uds socket error:", err)
		}
		transport := thrift.NewTBufferedTransport(socket, 10240)
		inputProtocol := thrift.NewTBinaryProtocolTransport(transport)
		outputProtocol := thrift.NewTMultiplexedProtocol(inputProtocol, "userManager")
		userManagerClient := services.NewUserManagerClientProtocol(transport, inputProtocol, outputProtocol)

		if err := transport.Open(); err != nil {
			log.Fatal("uds transport open error[userManager]:", err)
		}
		clientsPool <- userManagerClient
	}

	log.Print("start...")

	times := 100000

	ret := make(chan int, times)

	for i := 0; i < times; i++ {
		go func() {
			fromInfo := entity.NewFromInfo()
			fromInfo.Ctx = getUdsCtx()
			fromInfo.FromUid = 1000501
			fromInfo.FromIid = IID
			fromInfo.FromNjs = NJS

			userManagerClient := <-clientsPool
			//			_, err := userManagerClient.GetUserByPhone("15201218403")
			//			_, err := userManagerClient.GetUserById(1000501, entity.DBQueryStatus_NORMAL)
			err := userManagerClient.GetUserById(fromInfo.FromUid, fromInfo)
			clientsPool <- userManagerClient
			if err != nil {
				log.Fatal(err)
			}
			//			log.Print(u.GetBasic().Uid)
			ret <- 1
		}()
	}

	for i := 0; i < times; i++ {
		<-ret
	}

	log.Print("end...")

}
Пример #2
0
func getUserGroups(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	req.ParseForm()
	log.Println("Form:", req.Form)
	uid := req.Form.Get("uid")

	if uid == "" {
		fmt.Fprint(w, "{\"error\":\"invalid uid\"}")
		return
	}

	intUid, err := strconv.ParseInt(uid, 10, 64)
	if err != nil {
		fmt.Fprint(w, "{\"error\":\"invalid uid\"}")
		return
	}

	fromInfo := entity.NewFromInfo()
	fromInfo.Ctx = getUdsCtx()
	fromInfo.FromUid = UID
	fromInfo.FromIid = IID
	fromInfo.FromNjs = NJS

	groupManagerClient := <-groupManagerClients

	if err := groupManagerClient.GetUserGroups(intUid, fromInfo); err == nil {
		groupManagerClients <- groupManagerClient
		resChan := make(chan string)
		requestsResponseWaitings[fromInfo.Ctx] = &RequestsResponseWaiting{resChan, time.Now()}
		str := <-resChan
		fmt.Fprintln(w, str)
	} else {
		switch v := err.(type) {
		case thrift.TProtocolException:
			fmt.Fprintln(w, v)
			groupManagerClient.Transport.Close()
			groupManagerClient.Transport.Open()
		default:
			fmt.Fprintln(w, v)
		}
		groupManagerClients <- groupManagerClient
	}
}
Пример #3
0
func login(w http.ResponseWriter, req *http.Request) {
	w.Header().Set("Content-Type", "application/json; charset=utf-8")
	req.ParseForm()
	log.Println("Form:", req.Form)
	phone := req.Form.Get("phone")

	if phone == "" {
		fmt.Fprint(w, "{\"error\": \"invalid phone\"}")
		return
	}

	fromInfo := entity.NewFromInfo()
	fromInfo.Ctx = getUdsCtx()
	fromInfo.FromUid = UID
	fromInfo.FromIid = IID
	fromInfo.FromNjs = NJS

	userManagerClient := <-userManagerClients

	if err := userManagerClient.GetUserByPhone(phone, fromInfo); err == nil {
		userManagerClients <- userManagerClient
		resChan := make(chan string)
		requestsResponseWaitings[fromInfo.Ctx] = &RequestsResponseWaiting{resChan, time.Now()}
		str := <-resChan
		fmt.Fprintln(w, str)
	} else {
		switch v := err.(type) {
		case thrift.TProtocolException:
			fmt.Fprintln(w, v)
			userManagerClient.Transport.Close()
			userManagerClient.Transport.Open()
		default:
			fmt.Fprintln(w, v)
		}
		userManagerClients <- userManagerClient
	}
}