2022-01-27 12:29:49 +00:00
|
|
|
package tpl
|
|
|
|
|
2022-01-31 08:43:40 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
)
|
2022-01-27 12:29:49 +00:00
|
|
|
|
|
|
|
type Properties struct { // only string properties with a "token" tag, please
|
|
|
|
Code string `token:"code"`
|
|
|
|
Message string `token:"message"`
|
|
|
|
Description string `token:"description"`
|
|
|
|
OriginalURI string `token:"original_uri"`
|
|
|
|
Namespace string `token:"namespace"`
|
|
|
|
IngressName string `token:"ingress_name"`
|
|
|
|
ServiceName string `token:"service_name"`
|
|
|
|
ServicePort string `token:"service_port"`
|
|
|
|
RequestID string `token:"request_id"`
|
2022-01-31 05:40:58 +00:00
|
|
|
ForwardedFor string `token:"forwarded_for"`
|
2022-01-31 05:46:51 +00:00
|
|
|
Host string `token:"host"`
|
2022-01-27 12:29:49 +00:00
|
|
|
ShowRequestDetails bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replaces return a map with strings for the replacing, where the map key is a token.
|
|
|
|
func (p *Properties) Replaces() map[string]string {
|
|
|
|
var replaces = make(map[string]string, reflect.ValueOf(*p).NumField())
|
|
|
|
|
|
|
|
for i, v := 0, reflect.ValueOf(*p); i < v.NumField(); i++ {
|
|
|
|
if keyword, tagExists := v.Type().Field(i).Tag.Lookup("token"); tagExists {
|
|
|
|
if sv, isString := v.Field(i).Interface().(string); isString && len(sv) > 0 {
|
|
|
|
replaces[keyword] = sv
|
|
|
|
} else {
|
|
|
|
replaces[keyword] = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return replaces
|
|
|
|
}
|
2022-01-31 08:43:40 +00:00
|
|
|
|
|
|
|
func (p *Properties) Hash() (Hash, error) { return HashStruct(p) }
|