github.com/avenga/couper@v1.12.2/logging/helper.go (about)

     1  package logging
     2  
     3  import (
     4  	"math"
     5  	"net"
     6  	"net/http"
     7  	"strings"
     8  	"time"
     9  )
    10  
    11  func filterHeader(list []string, src http.Header) map[string]string {
    12  	header := make(map[string]string)
    13  	for _, key := range list {
    14  		ck := http.CanonicalHeaderKey(key)
    15  		val, ok := src[ck]
    16  		if !ok || len(val) == 0 || val[0] == "" {
    17  			continue
    18  		}
    19  		header[strings.ToLower(key)] = strings.Join(val, "|")
    20  	}
    21  	return header
    22  }
    23  
    24  func splitHostPort(hp string) (string, string) {
    25  	host, port, err := net.SplitHostPort(hp)
    26  	if err != nil {
    27  		return hp, port
    28  	}
    29  	return host, port
    30  }
    31  
    32  func RoundMS(d time.Duration) float64 {
    33  	const (
    34  		maxDuration time.Duration = 1<<63 - 1
    35  		milliSecond               = float64(time.Millisecond)
    36  	)
    37  
    38  	if d == maxDuration {
    39  		return 0.0
    40  	}
    41  
    42  	return math.Round((float64(d)/milliSecond)*1000) / 1000
    43  }