当前位置: 首页>>代码示例>>Golang>>正文


Golang cocaine.Response类代码示例

本文整理汇总了Golang中github.com/cocaine/cocaine-framework-go/cocaine.Response的典型用法代码示例。如果您正苦于以下问题:Golang Response类的具体用法?Golang Response怎么用?Golang Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: WriteError

func (gofetcher *Gofetcher) WriteError(response *cocaine.Response, request *Request, err error) {
	if _, casted := err.(*WarnError); casted {
		gofetcher.Logger.Warnf("Error occured: %v, while downloading %s",
			err.Error(), request.URL)
	} else {
		gofetcher.Logger.Errf("Error occured: %v, while downloading %s",
			err.Error(), request.URL)
	}
	response.Write([]interface{}{false, err.Error(), 0, http.Header{}})
}
开发者ID:sguzwf,项目名称:cocaine-gofetcher,代码行数:10,代码来源:gofetcher.go

示例4: 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

示例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: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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
	}

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

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

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

	err = cCli.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,代码行数:36,代码来源:cbb_main.go

示例12: 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

示例13: WriteResponse

func (gofetcher *Gofetcher) WriteResponse(response *cocaine.Response, request *Request, resp *http.Response, body []byte) {
	response.Write([]interface{}{true, body, resp.StatusCode, resp.Header})
}
开发者ID:sguzwf,项目名称:cocaine-gofetcher,代码行数:3,代码来源:gofetcher.go

示例14: on_ping

func on_ping(request *cocaine.Request, response *cocaine.Response) {
	defer response.Close()
	response.Write("gofetcher: ping reply")
}
开发者ID:minaevmike,项目名称:cocaine-gofetcher,代码行数:4,代码来源:main.go

示例15: 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


注:本文中的github.com/cocaine/cocaine-framework-go/cocaine.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。