File: submatches.go

package info (click to toggle)
golang-github-jarcoal-httpmock 1.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 2
file content (22 lines) | stat: -rw-r--r-- 446 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package internal

import (
	"context"
	"net/http"
)

type submatchesKeyType struct{}

var submatchesKey submatchesKeyType

func SetSubmatches(req *http.Request, submatches []string) *http.Request {
	if len(submatches) > 0 {
		return req.WithContext(context.WithValue(req.Context(), submatchesKey, submatches))
	}
	return req
}

func GetSubmatches(req *http.Request) []string {
	sm, _ := req.Context().Value(submatchesKey).([]string)
	return sm
}