-
Notifications
You must be signed in to change notification settings - Fork 20
/
context.go
34 lines (26 loc) · 881 Bytes
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (c) 2022 Silverton Data, Inc.
// You may use, distribute, and modify this code under the terms of the Apache-2.0 license, a copy of
// which may be found at https://github.com/silverton-io/buz/blob/main/LICENSE
package envelope
import (
"database/sql/driver"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/silverton-io/buz/pkg/util"
)
const HTTP_HEADERS_CONTEXT string = "io.silverton/buz/internal/contexts/httpHeaders/v1.0.json"
type Contexts map[string]interface{}
func (c Contexts) Value() (driver.Value, error) {
b, err := json.Marshal(c)
return string(b), err
}
func (c Contexts) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), &c)
}
func BuildContextsFromRequest(c *gin.Context) Contexts {
headers := util.HttpHeadersToMap(c)
context := map[string]interface{}{
HTTP_HEADERS_CONTEXT: headers,
}
return context
}