File: utils.go

package info (click to toggle)
golang-github-rs-cors 1.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 260 kB
  • sloc: makefile: 3
file content (25 lines) | stat: -rw-r--r-- 474 bytes parent folder | download
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
package cors

import (
	"strings"
)

type wildcard struct {
	prefix string
	suffix string
}

func (w wildcard) match(s string) bool {
	return len(s) >= len(w.prefix)+len(w.suffix) &&
		strings.HasPrefix(s, w.prefix) &&
		strings.HasSuffix(s, w.suffix)
}

// convert converts a list of string using the passed converter function
func convert(s []string, f func(string) string) []string {
	out := make([]string, len(s))
	for i := range s {
		out[i] = f(s[i])
	}
	return out
}