INNER CODE UNIT · Go

renameConstructor

stacklok/toolhive · cmd/help/ogen-client-wrapper/main.go:29

func renameConstructor(path string) error {
	fileSet := token.NewFileSet()
	file, err := parser.ParseFile(fileSet, path, nil, parser.ParseComments)
	if err != nil {
		return fmt.Errorf("parse generated client: %w", err)
	}

	var constructors int
	for _, declaration := range file.Decls {
		function, ok := declaration.(*ast.FuncDecl)
		if !ok || function.Recv != nil || function.Name.Name != "NewClient" {
			continue
		}
		function.Name.Name = "NewUnsafeClient"
		if function.Doc != nil {
			for _, comment := range function.Doc.List {
				comment.Text = strings.Replace(comment.Text, "NewClient", "NewUnsafeClient", 1)
			}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…