Initial euclide.org release

This commit is contained in:
2023-11-17 06:55:06 +01:00
commit 97379c8e8a
210 changed files with 32403 additions and 0 deletions

41
vendor/github.com/jarcoal/httpmock/internal/error.go generated vendored Normal file
View File

@@ -0,0 +1,41 @@
package internal
import (
"errors"
"fmt"
)
// NoResponderFound is returned when no responders are found for a
// given HTTP method and URL.
var NoResponderFound = errors.New("no responder found") // nolint: revive
// ErrorNoResponderFoundMistake encapsulates a NoResponderFound
// error probably due to a user error on the method or URL path.
type ErrorNoResponderFoundMistake struct {
Kind string // "method", "URL" or "matcher"
Orig string // original wrong method/URL, without any matching responder
Suggested string // suggested method/URL with a matching responder
}
var _ error = (*ErrorNoResponderFoundMistake)(nil)
// Unwrap implements the interface needed by errors.Unwrap.
func (e *ErrorNoResponderFoundMistake) Unwrap() error {
return NoResponderFound
}
// Error implements error interface.
func (e *ErrorNoResponderFoundMistake) Error() string {
if e.Kind == "matcher" {
return fmt.Sprintf("%s despite %s",
NoResponderFound,
e.Suggested,
)
}
return fmt.Sprintf("%[1]s for %[2]s %[3]q, but one matches %[2]s %[4]q",
NoResponderFound,
e.Kind,
e.Orig,
e.Suggested,
)
}

View File

@@ -0,0 +1,15 @@
package internal
type RouteKey struct {
Method string
URL string
}
var NoResponder RouteKey
func (r RouteKey) String() string {
if r == NoResponder {
return "NO_RESPONDER"
}
return r.Method + " " + r.URL
}

View File

@@ -0,0 +1,91 @@
package internal
import (
"bytes"
"fmt"
"net/http"
"runtime"
"strings"
)
type StackTracer struct {
CustomFn func(...interface{})
Err error
}
// Error implements error interface.
func (s StackTracer) Error() string {
if s.Err == nil {
return ""
}
return s.Err.Error()
}
// Unwrap implements the interface needed by errors.Unwrap.
func (s StackTracer) Unwrap() error {
return s.Err
}
// CheckStackTracer checks for specific error returned by
// NewNotFoundResponder function or Trace Responder method.
func CheckStackTracer(req *http.Request, err error) error {
if nf, ok := err.(StackTracer); ok {
if nf.CustomFn != nil {
pc := make([]uintptr, 128)
npc := runtime.Callers(2, pc)
pc = pc[:npc]
var mesg bytes.Buffer
var netHTTPBegin, netHTTPEnd bool
// Start recording at first net/http call if any...
for {
frames := runtime.CallersFrames(pc)
var lastFn string
for {
frame, more := frames.Next()
if !netHTTPEnd {
if netHTTPBegin {
netHTTPEnd = !strings.HasPrefix(frame.Function, "net/http.")
} else {
netHTTPBegin = strings.HasPrefix(frame.Function, "net/http.")
}
}
if netHTTPEnd {
if lastFn != "" {
if mesg.Len() == 0 {
if nf.Err != nil {
mesg.WriteString(nf.Err.Error())
} else {
fmt.Fprintf(&mesg, "%s %s", req.Method, req.URL)
}
mesg.WriteString("\nCalled from ")
} else {
mesg.WriteString("\n ")
}
fmt.Fprintf(&mesg, "%s()\n at %s:%d", lastFn, frame.File, frame.Line)
}
}
lastFn = frame.Function
if !more {
break
}
}
// At least one net/http frame found
if mesg.Len() > 0 {
break
}
netHTTPEnd = true // retry without looking at net/http frames
}
nf.CustomFn(mesg.String())
}
err = nf.Err
}
return err
}

View File

@@ -0,0 +1,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
}