github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/nodejs/gen_program_utils.go (about)

     1  package nodejs
     2  
     3  // Provides code for a method which will be placed in the program preamble if deemed
     4  // necessary. Because many tasks in Go such as reading a file require extensive error
     5  // handling, it is much prettier to encapsulate that error handling boilerplate as its
     6  // own function in the preamble.
     7  func getHelperMethodIfNeeded(functionName string) (string, bool) {
     8  	switch functionName {
     9  	case "filebase64sha256":
    10  		return `func computeFilebase64sha256(path string) string {
    11  	const fileData = Buffer.from(fs.readFileSync(path), 'binary')
    12  	return crypto.createHash('sha256').update(fileData).digest('hex')
    13  }`, true
    14  	default:
    15  		return "", false
    16  	}
    17  }