MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / stringToGoCommentWithPrefix

Function stringToGoCommentWithPrefix

pkg/codegen/utils.go:940–964  ·  view source on GitHub ↗
(in, prefix string)

Source from the content-addressed store, hash-verified

938}
939
940func stringToGoCommentWithPrefix(in, prefix string) string {
941 if len(in) == 0 || len(strings.TrimSpace(in)) == 0 { // ignore empty comment
942 return ""
943 }
944
945 // Normalize newlines from Windows/Mac to Linux
946 in = strings.ReplaceAll(in, "\r\n", "\n")
947 in = strings.ReplaceAll(in, "\r", "\n")
948
949 // Add comment to each line
950 var lines []string
951 for i, line := range strings.Split(in, "\n") {
952 s := "//"
953 if i == 0 && len(prefix) > 0 {
954 s += " " + prefix
955 }
956 lines = append(lines, fmt.Sprintf("%s %s", s, line))
957 }
958 in = strings.Join(lines, "\n")
959
960 // in case we have a multiline string which ends with \n, we would generate
961 // empty-line-comments, like `// `. Therefore remove this line comment.
962 in = strings.TrimSuffix(in, "\n// ")
963 return in
964}
965
966// EscapePathElements breaks apart a path, and looks at each element. If it's
967// not a path parameter, eg, {param}, it will URL-escape the element.

Callers 3

StringToGoCommentFunction · 0.85
DeprecationCommentFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected