mirror of
https://github.com/weloe/token-go.git
synced 2025-10-06 16:07:18 +08:00
32 lines
643 B
Go
32 lines
643 B
Go
package go_http_context
|
|
|
|
import (
|
|
"context"
|
|
"github.com/weloe/token-go/ctx"
|
|
"net/http"
|
|
)
|
|
|
|
type HttpReqStorage struct {
|
|
source context.Context
|
|
}
|
|
|
|
func NewReqStorage(req *http.Request) *HttpReqStorage {
|
|
return &HttpReqStorage{source: req.Context()}
|
|
}
|
|
|
|
func (r *HttpReqStorage) Source() interface{} {
|
|
return r.source
|
|
}
|
|
|
|
func (r *HttpReqStorage) Get(key ctx.StorageKey) interface{} {
|
|
return r.source.Value(key)
|
|
}
|
|
|
|
func (r *HttpReqStorage) Set(key ctx.StorageKey, value string) {
|
|
r.source = context.WithValue(r.source, key, value)
|
|
}
|
|
|
|
func (r *HttpReqStorage) Delete(key ctx.StorageKey) {
|
|
r.source = context.WithValue(r.source, key, nil)
|
|
}
|