github.com/blend/go-sdk@v1.20220411.3/sourceutil/go_import_rewrite_prefix.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package sourceutil
     9  
    10  import (
    11  	"fmt"
    12  )
    13  
    14  // GoImportRewritePrefix is a helper that returns a visitor that
    15  // takes a source path and rewrites it as the destination path
    16  // preserving any path segments after the source if it matches the sourcePrefix.
    17  func GoImportRewritePrefix(sourcePrefix, destinationPrefix string) GoImportVisitor {
    18  	return GoImportRewrite(
    19  		OptGoImportPathRewrite(
    20  			fmt.Sprintf("^%s(.*)", sourcePrefix),
    21  			fmt.Sprintf("%s$1", destinationPrefix),
    22  		),
    23  	)
    24  }