This code snippet checks if the 'X-Sign' header is present in the request. If it is not present, it logs an error, responds with an error message, and aborts the request. If the header is present, it verifies the signature using the verifySign function. If the signature is incorrect, it logs an error, responds with an error message, and aborts the request. If the signature is correct, it continues with the request and returns nil and the raw request data.

sign := c.GetHeader("X-Sign")

if sign == "" {
	r.IllegalRequest(c, nil, 'missing one of these headers ['sign']')
	c.Abort()
	return errors.New("header missing sign"),0
}

ok, err, requestDataRaw := verifySign(sign)

if !ok {
	log.Log.Errorf("incorrect signature : error : %s",err.Error())
	r.Forbidden(c, nil, "incorrect signature")
	c.Abort()
	return err,0
}
	c.Next()
	return nil,requestDataRaw
Go HTTP Request Signature Verification

原文地址: https://www.cveoy.top/t/topic/bsqh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录