Documentation ¶
Index ¶
- func ApplyIPMask(ipStr string) (maskedIP string, ok bool)
- func ClientIPAddr(c *gin.Context) netip.Addr
- func CopyHeader(dst, src http.Header)
- func ExtractAndMaskIP(ipStr string) (maskedIP string, ok bool)
- func ExtractProjectFromUserAgent(userAgents []string) string
- func ExtractVersionAndServiceFromUserAgent(userAgent string) (reqVer, service string)
- func GetJwks(ctx context.Context, tr *http.Transport, location string) (jwk.Set, error)
- func GetPreferredCaches(preferredCaches string) (caches []*url.URL, err error)
- func HasContentType(r *http.Response, mimetype string) bool
- func HeaderParser(values string) (retMap map[string]string)
- func LaunchPeriodicWriteCABundle(ctx context.Context, egrpKey string, filename string, sleepTime time.Duration) (count int, err error)
- func MakeRequest(ctx context.Context, tr *http.Transport, url string, method string, ...) ([]byte, error)
- func MapToSlice[K comparable, V any](m map[K]V) []V
- func SnakeCaseToCamelCase(input string) string
- func SnakeCaseToHumanReadable(input string) string
- func WriteCABundle(filename string) (int, error)
- type Group
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyIPMask ¶
ApplyIPMask will apply a /24 bit mask to IPv4 addresses and a /64 bit mask to IPv6 Will return the input string along with ok == false if there is any error while masking
func ClientIPAddr ¶
Equivalent to c.ClientIP() except that it returns netip.Addr instead of net.IP
If the IP string is invalid, it returns netip.Addr{}. Use netip.Addr.ISValid() to check the validity of the returned value
func CopyHeader ¶
Copy headers from proxied src to dst, removing those defined by HTTP as "hop-by-hop" and not to be forwarded (see https://www.rfc-editor.org/rfc/rfc9110#field.connection)
func ExtractAndMaskIP ¶
ExtractAndMaskIP will extract an IP address from a leading "[" and trailing "]". Then the function will apply the ApplyIPMask function
func ExtractProjectFromUserAgent ¶
Helper function to extract project from User-Agent Will return an empty string if no project is found
func ExtractVersionAndServiceFromUserAgent ¶
ExtractVersionAndServiceFromUserAgent will extract the Pelican version and service from the user agent. It will return empty strings if the provided userAgent failes to match against the parser
func GetPreferredCaches ¶
GetPreferredCaches parses the caches it is given and returns it as a list of url's
func HasContentType ¶
Determine whether the response `content-type` includes a server-acceptable mime-type
Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`)
Source: https://gist.github.com/rjz/fe283b02cbaa50c5991e1ba921adf7c9
func HeaderParser ¶
Simple parser to that takes a "values" string from a header and turns it into a map of key/value pairs
func LaunchPeriodicWriteCABundle ¶
func LaunchPeriodicWriteCABundle(ctx context.Context, egrpKey string, filename string, sleepTime time.Duration) (count int, err error)
Periodically write out the system CAs, updating them if the system updates. Returns an error if the first attempt at writing fails. Otherwise, it will launch a goroutine and update the entire CA bundle every specified duration.
If we're on a platform (Mac, Windows) that does not provide a CA bundle, we return a count of 0 and do not launch the go routine.
func MakeRequest ¶
func MakeRequest(ctx context.Context, tr *http.Transport, url string, method string, data map[string]interface{}, headers map[string]string) ([]byte, error)
MakeRequest makes an http request with our custom http client. It acts similarly to the http.NewRequest but it only takes json as the request data.
func MapToSlice ¶
func MapToSlice[K comparable, V any](m map[K]V) []V
Convert map to slice of values
func SnakeCaseToCamelCase ¶
snakeCaseToCamelCase converts a snake case string to camel case.
func SnakeCaseToHumanReadable ¶
snakeCaseToSnakeCase converts a snake_case string to Snake Case (CamelCase with spaces).
func WriteCABundle ¶
Write out all the trusted CAs as a CA bundle on disk. This is useful for components that do not use go's trusted CA store
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
A Group is a collection of goroutines working on subtasks that are part of the same overall task.
A zero Group is valid, has no limit on the number of active goroutines, and does not cancel on error.
func WithContext ¶
WithContext returns a new Group and an associated Context derived from ctx.
The derived Context is canceled the first time a function passed to Go returns a non-nil error or the first time Wait returns, whichever occurs first.
func (*Group) Go ¶
Go calls the given function in a new goroutine. It blocks until the new goroutine can be added without the number of active goroutines in the group exceeding the configured limit.
The first call to return a non-nil error cancels the group's context, if the group was created by calling WithContext. The error will be returned by Wait.
func (*Group) SetLimit ¶
SetLimit limits the number of active goroutines in this group to at most n. A negative value indicates no limit.
Any subsequent call to the Go method will block until it can add an active goroutine without exceeding the configured limit.
The limit must not be modified while any goroutines in the group are active.
func (*Group) TryGo ¶
TryGo calls the given function in a new goroutine only if the number of active goroutines in the group is currently below the configured limit.
It will block until the provided context is cancelled.
The return value reports whether the goroutine was started.
func (*Group) TryGoUntil ¶
TryGoUntil calls the given function in a new goroutine only if the number of active goroutines in the group is currently below the configured limit.
If the group is at the configured limit, the call will block until the provided context is cancelled.
The return value reports whether the goroutine was started.