示例#1
0
文件: web.go 项目: cubeee/go-sig
func createAndSaveSignature(writer http.ResponseWriter, req util.SignatureRequest, generator generators.BaseGenerator) error {
	// Create the signature image
	sig, err := generator.CreateSignature(req.Req)
	if err != nil {
		return err
	}

	// note: queue saving if it causes performance issues?
	// Save the image to disk with the given hash as the file name
	saveImage(req.Hash, sig.Image)
	return nil
}
示例#2
0
文件: web.go 项目: cubeee/go-sig
func registerGenerator(generator generators.BaseGenerator) {
	goji.Get(generator.Url(), func(c web.C, writer http.ResponseWriter, request *http.Request) {
		parsedReq, err := generator.ParseSignatureRequest(c, request)
		if err != nil {
			writeTextResponse(writer, "Failed to parse the request: "+err.Error())
			return
		}
		hash := finalizeHash(generator.Name(), generator.CreateHash(parsedReq))
		req := util.SignatureRequest{parsedReq, hash}

		serveSignature(c, writer, request, req, generator)
	})

	formUrl := generator.FormUrl()
	if formUrl != "" {
		goji.Post(formUrl, func(c web.C, writer http.ResponseWriter, request *http.Request) {
			generator.HandleForm(c, writer, request)
		})
	}
}