當前位置: 首頁>>代碼示例>>Golang>>正文


Golang common.UI類代碼示例

本文整理匯總了Golang中github.com/pquerna/hurl/common.UI的典型用法代碼示例。如果您正苦於以下問題:Golang UI類的具體用法?Golang UI怎麽用?Golang UI使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UI類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewTask

func NewTask(ui common.UI) (workers.WorkerTask, error) {
	c := ui.ConfigGet()
	conf := c.GetSwiftConfig()
	if conf == nil {
		panic("Invalid Configuration object for swift worker")
	}

	conn := swift.Connection{
		UserName: conf.Username,
		ApiKey:   conf.ApiKey,
		AuthUrl:  conf.AuthUrl,
		// https://auth.api.rackspacecloud.com/v1.0
		Region:    conf.Region,
		UserAgent: fmt.Sprintf("hurl/1 http load tester; https://github.com/pquerna/hurl;  username=%s", conf.Username),
	}

	if authTokenCache != "" && storageUrlCache != "" {
		conn.AuthToken = authTokenCache
		conn.StorageUrl = storageUrlCache
	} else {
		err := conn.Authenticate()
		if err != nil {
			return nil, err
		}
		authTokenCache = conn.AuthToken
		storageUrlCache = conn.StorageUrl
	}

	return &Task{
		conf: conf,
		conn: &conn}, nil
}
開發者ID:pquerna,項目名稱:hurl,代碼行數:32,代碼來源:task.go

示例2: ConsoleRun

func ConsoleRun(ui common.UI, cmd *cobra.Command, args []string) {
	if len(args) != 1 {
		common.ConsoleErr(cmd, fmt.Sprintf("Error: Expected 1 URL, got: %s", args))
		return
	}

	g_config.Url = args[0]

	ui.ConfigSet(&g_config)

	common.ConsoleRun(workers.Run, "http", ui, cmd, args)
}
開發者ID:pquerna,項目名稱:hurl,代碼行數:12,代碼來源:console.go

示例3: resultHanlder

func resultHanlder(ui common.UI, wgres *sync.WaitGroup, resChan chan *common.Result, raw *common.ResultArchiveWriter) {
	defer func() { wgres.Done() }()
	var i int64 = 0
	for {
		rv, ok := <-resChan
		if !ok {
			return
		}
		i++
		ui.WorkStatus(i)
		raw.Write(rv)
	}
}
開發者ID:pquerna,項目名稱:hurl,代碼行數:13,代碼來源:worker.go

示例4: Run

func Run(ui common.UI, taskType string) error {
	//	if clusterConf != "" {
	//		// TODO: add ClusterWorker
	//		return nil, fmt.Errorf("TODO: Cluster support")
	//	}
	wt, ok := g_workers_tasks[taskType]
	if !ok {
		return fmt.Errorf("unknown worker type: %s", taskType)
	}

	conf := ui.ConfigGet()
	bconf := conf.GetBasicConfig()
	workers := make([]Worker, bconf.Concurrency)
	for index, _ := range workers {
		w, err := wt(ui)
		if err != nil {
			return err
		}
		workers[index] = &LocalWorker{task: w}
	}

	ui.WorkStart(bconf.NumRequests)
	defer func() {
		for _, worker := range workers {
			worker.Halt()
		}
	}()

	var wg sync.WaitGroup
	var wgres sync.WaitGroup
	reqchan := make(chan int64, 1024*1024)
	// TODO: how big should this be?
	reschan := make(chan *common.Result)
	for _, worker := range workers {
		err := worker.Start(taskType, &wg, reqchan, reschan)
		if err != nil {
			return err
		}
	}

	var i int64

	for i = 0; i < bconf.NumRequests; i++ {
		reqchan <- i
		// TOOD: ui.WorkStatus(numDone int64)
	}
	wgres.Add(1)

	rw := common.NewResultArchiveWriter()
	defer rw.Remove()
	go resultHanlder(ui, &wgres, reschan, rw)

	close(reqchan)
	wg.Wait()
	close(reschan)
	wgres.Wait()
	ui.WorkEnd()

	rw.Close()

	rr := common.NewResultArchiveReader(rw.Path)
	return reports.Run(ui, taskType, conf, rr)
}
開發者ID:pquerna,項目名稱:hurl,代碼行數:63,代碼來源:worker.go


注:本文中的github.com/pquerna/hurl/common.UI類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。