add helper options
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
7e46d86253
commit
74d8cb8538
24
options.go
Normal file
24
options.go
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package http
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
type rspCodeKey struct{}
|
||||||
|
type rspCodeVal struct {
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRspCode saves response code in context, must be used by handler to specify http code
|
||||||
|
func SetRspCode(ctx context.Context, code int) {
|
||||||
|
if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
|
||||||
|
rsp.code = code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRspCode used internally by generated http server handler
|
||||||
|
func GetRspCode(ctx context.Context) int {
|
||||||
|
var code int
|
||||||
|
if rsp, ok := ctx.Value(rspCodeKey{}).(*rspCodeVal); ok {
|
||||||
|
code = rsp.code
|
||||||
|
}
|
||||||
|
return code
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user