MCPcopy
hub / github.com/gin-gonic/gin / exampleFromPath

Function exampleFromPath

githubapi_test.go:405–438  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

403}
404
405func exampleFromPath(path string) (string, Params) {
406 output := new(strings.Builder)
407 params := make(Params, 0, 6)
408 start := -1
409 for i, c := range path {
410 if c == ':' {
411 start = i + 1
412 }
413 if start >= 0 {
414 if c == '/' {
415 value := strconv.Itoa(rand.Intn(100000))
416 params = append(params, Param{
417 Key: path[start:i],
418 Value: value,
419 })
420 output.WriteString(value)
421 output.WriteRune(c)
422 start = -1
423 }
424 } else {
425 output.WriteRune(c)
426 }
427 }
428 if start >= 0 {
429 value := strconv.Itoa(rand.Intn(100000))
430 params = append(params, Param{
431 Key: path[start:],
432 Value: value,
433 })
434 output.WriteString(value)
435 }
436
437 return output.String(), params
438}
439
440func BenchmarkGithub(b *testing.B) {
441 router := New()

Callers 4

TestShouldBindUriFunction · 0.85
TestBindUriFunction · 0.85
TestBindUriErrorFunction · 0.85
TestGithubAPIFunction · 0.85

Calls 2

WriteStringMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected