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


Golang cocaine.Request類代碼示例

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


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

示例1: handler

func (gofetcher *Gofetcher) handler(method string, request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()

	requestBody := <-request.Read()
	httpRequest := gofetcher.ParseRequest(method, requestBody)

	req, client, err := gofetcher.PrepareRequest(httpRequest)
	if err != nil {
		gofetcher.WriteError(response, httpRequest, err)
		return
	}

	resp, err := gofetcher.ExecuteRequest(req, client, 1)
	if err != nil {
		gofetcher.WriteError(response, httpRequest, err)
		return
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		gofetcher.WriteError(response, httpRequest, err)
		return
	}

	gofetcher.WriteResponse(response, httpRequest, resp, body)
}
開發者ID:sguzwf,項目名稱:cocaine-gofetcher,代碼行數:27,代碼來源:gofetcher.go

示例2: get

func get(request *cocaine.Request, response *cocaine.Response) {
	incoming := <-request.Read()

	var inp struct {
		Config map[string]interface{} "Config"
		Task   common.FetcherTask     "Task"
	}

	err := common.Unpack(incoming, &inp)
	if err != nil {
		logger.Err(err)
		response.ErrorMsg(1, fmt.Sprintf("%v", err))
		response.Close()
		return
	}

	url := CfgandTaskUrl(inp.Config, &inp.Task)
	res, err := timetail.Get(url)
	if err != nil {
		response.ErrorMsg(1, fmt.Sprintf("%v", err))
		response.Close()
		return
	}

	response.Write(res)
	response.Close()
}
開發者ID:kartvep,項目名稱:Combaine,代碼行數:27,代碼來源:timetail_main.go

示例3: Send

func Send(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()

	raw := <-request.Read()
	var task Task
	err := common.Unpack(raw, &task)
	if err != nil {
		response.ErrorMsg(-100, err.Error())
		return
	}

	task.Config.Host, err = getRazladkiHost()
	if err != nil {
		response.ErrorMsg(-100, err.Error())
		return
	}

	logger.Debugf("Task: %v", task)

	rCli, err := razladki.NewRazladkiClient(&task.Config, task.Id)
	if err != nil {
		logger.Errf("Unexpected error %s", err)
		response.ErrorMsg(-100, err.Error())
		return
	}

	err = rCli.Send(task.Data, task.PrevTime)
	if err != nil {
		logger.Errf("Sending error %s", err)
		response.ErrorMsg(-100, err.Error())
		return
	}
	response.Write("DONE")
}
開發者ID:noxiouz,項目名稱:Combaine,代碼行數:34,代碼來源:razladki_main.go

示例4: on_http_generate

func on_http_generate(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	r, err := cocaine.UnpackProxyRequest(<-request.Read())
	if err != nil {
		response.ErrorMsg(-200, err.Error())
		return
	}

	message := r.FormValue("message")
	if len(message) == 0 {
		response.Write(cocaine.WriteHead(http.StatusBadRequest, ErrorHeaders))
		response.Write("Missing argument `message`")
		return
	}

	png, err := qenerate(message)
	if err != nil {
		response.Write(cocaine.WriteHead(http.StatusInternalServerError, ErrorHeaders))
		response.Write("Unable to generate QR")
		return
	}

	response.Write(cocaine.WriteHead(http.StatusOK, OkHeaders))
	response.Write(png)
}
開發者ID:sguzwf,項目名稱:cocaine-paper-sources,代碼行數:25,代碼來源:qr.go

示例5: http_test

func http_test(request *cocaine.Request, response *cocaine.Response) {
	req := cocaine.UnpackProxyRequest(<-request.Read())
	response.Write(cocaine.WriteHead(200, [][2]string{{"Content-Type", "text/html"}}))
	ans := fmt.Sprintf("Method: %s, Uri: %s, UA: %s", req.Method, req.URL, req.UserAgent())
	response.Write(ans)
	response.Close()
}
開發者ID:kod3r,項目名稱:cocaine-framework-go,代碼行數:7,代碼來源:main.go

示例6: parsing

func parsing(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	raw := <-request.Read()
	name := string(raw)
	if data, err := configmanager.GetParsingCfg(name); err != nil {
		response.ErrorMsg(-2, fmt.Sprintf("Missing file with name %s", name))
	} else {
		response.Write(data)
	}
}
開發者ID:kartvep,項目名稱:Combaine,代碼行數:10,代碼來源:cfgmanager_main.go

示例7: common

func common(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	<-request.Read()
	if data, err := configmanager.GetCommonCfg(); err != nil {
		response.ErrorMsg(-2, "Missing combaine.(yaml|json)")
	} else {
		response.Write(data)
	}

}
開發者ID:kartvep,項目名稱:Combaine,代碼行數:10,代碼來源:cfgmanager_main.go

示例8: dummy

func dummy(request *cocaine.Request, response *cocaine.Response) {
	logger := cocaine.NewLogger()
	logger.Info("FROM HANDLER")
	<-request.Read()
	logger.Info("AFTER READ")
	response.Write("Hello! I'm GO worker")
	logger.Info("AFTER WRITE")
	response.Close()
	logger.Info("AFTER CLOSE")
}
開發者ID:kod3r,項目名稱:cocaine-framework-go,代碼行數:10,代碼來源:main.go

示例9: app_list

func app_list(request *cocaine.Request, response *cocaine.Response) {
	<-request.Read()
	if list := <-storage.Find("apps", []string{"app"}); list.Err != nil {
		logger.Err(fmt.Sprintf("Unable to fetch  list%s", list.Err))
		response.Write("fail")
		response.Close()
	} else {
		response.Write(strings.Join(list.Res, ","))
		response.Close()
	}
}
開發者ID:kod3r,項目名稱:cocaine-framework-go,代碼行數:11,代碼來源:main.go

示例10: handleTask

func handleTask(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	raw := <-request.Read()
	var task tasks.ParsingTask
	err := common.Unpack(raw, &task)
	if err != nil {
		response.ErrorMsg(-100, err.Error())
		return
	}
	err = parsing.Parsing(ctxParsing, task)
	if err != nil {
		response.ErrorMsg(-100, err.Error())
	} else {
		response.Write("OK")
	}
}
開發者ID:noxiouz,項目名稱:Combaine,代碼行數:16,代碼來源:parsing_main.go

示例11: Send

func Send(request *cocaine.Request, response *cocaine.Response) {
	raw := <-request.Read()

	var task Task
	err := common.Unpack(raw, &task)
	if err != nil {
		response.ErrorMsg(-100, err.Error())
		return
	}
	logger.Debugf("%s Task: %v", task.Id, task)

	task.Config.Id = task.Id
	task.Config.Hosts, err = getAgaveHosts()
	if err != nil {
		response.ErrorMsg(-100, err.Error())
		return
	}

	if len(task.Config.Fields) == 0 {
		task.Config.Fields = DEFAULT_FIELDS
	}

	if task.Config.Step == 0 {
		task.Config.Step = DEFAULT_STEP
	}

	logger.Debugf("%s Fields: %v Step: %d", task.Id, task.Config.Fields, task.Config.Step)

	as, err := agave.NewAgaveSender(task.Config)
	if err != nil {
		logger.Errf("%s Unexpected error %s", task.Id, err)
		response.ErrorMsg(-100, err.Error())
		response.Close()
		return
	}
	as.Send(task.Data)
	response.Write("OK")
	response.Close()
}
開發者ID:noxiouz,項目名稱:Combaine,代碼行數:39,代碼來源:agave_main.go

示例12: on_generate

func on_generate(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	inc := <-request.Read()
	var task struct {
		Text string
		Size int
	}

	err := codec.NewDecoderBytes(inc, h).Decode(&task)
	if err != nil {
		response.ErrorMsg(-100, err.Error())
		return
	}

	png, err := qenerate(task.Text)
	if err != nil {
		response.ErrorMsg(-200, err.Error())
		return
	}

	response.Write(png)
}
開發者ID:sguzwf,項目名稱:cocaine-paper-sources,代碼行數:22,代碼來源:qr.go

示例13: handler

func (gofetcher *Gofetcher) handler(method string, request *cocaine.Request, response *cocaine.Response) {
	defer func() {
		if r := recover(); r != nil {
			var errMsg string
			if err := r.(*error); err == nil {
				errMsg = "Unknown error has occured."
			} else {
				errMsg = (*err).Error()
			}
			gofetcher.Logger.Errf("Error occured: %s.", errMsg)
			response.ErrorMsg(PanicResponseErrorCode, errMsg)
		}
		response.Close()
	}()

	requestBody := <-request.Read()
	httpRequest := gofetcher.ParseRequest(method, requestBody)

	req, client, err := gofetcher.PrepareRequest(httpRequest)
	if err != nil {
		gofetcher.WriteError(response, httpRequest, err)
		return
	}

	resp, err := gofetcher.ExecuteRequest(req, client, 1)
	if err != nil {
		gofetcher.WriteError(response, httpRequest, err)
		return
	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		gofetcher.WriteError(response, httpRequest, err)
		return
	}

	gofetcher.WriteResponse(response, httpRequest, resp, body)
}
開發者ID:coldze,項目名稱:cocaine-gofetcher,代碼行數:39,代碼來源:gofetcher.go

示例14: echo

func echo(request *cocaine.Request, response *cocaine.Response) {
	inc := <-request.Read()
	response.Write(inc)
	response.Close()
}
開發者ID:kod3r,項目名稱:cocaine-framework-go,代碼行數:5,代碼來源:main.go


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