api/pkg/audit/http_details.go

43 lines
749 B
Go
Raw Normal View History

2020-12-30 16:03:01 +00:00
package audit
import (
"net/http"
"strings"
"google.golang.org/protobuf/types/known/anypb"
2020-12-30 16:03:01 +00:00
)
type HTTPDetails struct {
Method string
Host string
URI string
Proto string
Headers http.Header
}
func (d HTTPDetails) MarshalToWireFormat() (any *anypb.Any, err error) {
2020-12-30 16:03:01 +00:00
var method = HTTPMethod_GET
if methodValue, known := HTTPMethod_value[strings.ToUpper(d.Method)]; known {
method = HTTPMethod(methodValue)
}
headers := make(map[string]*HTTPHeaderValue)
for k, v := range d.Headers {
headers[k] = &HTTPHeaderValue{
Values: v,
}
}
protoDetails := &HTTPDetailsEntity{
2020-12-30 16:03:01 +00:00
Method: method,
Host: d.Host,
Uri: d.URI,
Proto: d.Proto,
Headers: headers,
}
any, err = anypb.New(protoDetails)
return
2020-12-30 16:03:01 +00:00
}