* Build the Go function where the package name is not `"main"`. If a `go.mod` * does not exist, a default one will be used.
({
downloadPath,
entrypoint,
entrypointAbsolute,
entrypointDirname,
go,
goModPath,
handlerFunctionName,
isGoModInRootDir,
outDir,
packageName,
undo,
}: BuildHandlerOptions)
| 365 | * does not exist, a default one will be used. |
| 366 | */ |
| 367 | async function buildHandlerWithGoMod({ |
| 368 | downloadPath, |
| 369 | entrypoint, |
| 370 | entrypointAbsolute, |
| 371 | entrypointDirname, |
| 372 | go, |
| 373 | goModPath, |
| 374 | handlerFunctionName, |
| 375 | isGoModInRootDir, |
| 376 | outDir, |
| 377 | packageName, |
| 378 | undo, |
| 379 | }: BuildHandlerOptions): Promise<void> { |
| 380 | debug( |
| 381 | `Building Go handler as package "${packageName}" (with${ |
| 382 | goModPath ? '' : 'out' |
| 383 | } go.mod)` |
| 384 | ); |
| 385 | |
| 386 | let goModDirname: string | undefined; |
| 387 | |
| 388 | if (goModPath !== undefined) { |
| 389 | goModDirname = dirname(goModPath); |
| 390 | |
| 391 | // first we backup the original |
| 392 | const backupFile = join(goModDirname, `__vc_go.mod.bak`); |
| 393 | await copy(goModPath, backupFile); |
| 394 | |
| 395 | undo.fileActions.push({ |
| 396 | to: goModPath, |
| 397 | from: backupFile, |
| 398 | }); |
| 399 | |
| 400 | const goSumPath = join(goModDirname, 'go.sum'); |
| 401 | const isGoSumExists = await pathExists(goSumPath); |
| 402 | if (!isGoSumExists) { |
| 403 | // remove the `go.sum` file that will be generated as well |
| 404 | undo.fileActions.push({ |
| 405 | to: undefined, // delete |
| 406 | from: goSumPath, |
| 407 | }); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | // Detect vendored dependencies by checking for vendor/modules.txt, |
| 412 | // the canonical marker created by `go mod vendor` |
| 413 | const vendorModulesPath = join( |
| 414 | goModDirname || entrypointDirname, |
| 415 | 'vendor', |
| 416 | 'modules.txt' |
| 417 | ); |
| 418 | const isVendored = await pathExists(vendorModulesPath); |
| 419 | if (isVendored) { |
| 420 | debug('Detected vendor directory in project'); |
| 421 | |
| 422 | const vendorModulesBackup = vendorModulesPath + '.bak'; |
| 423 | await copy(vendorModulesPath, vendorModulesBackup); |
| 424 | undo.fileActions.push({ |
no test coverage detected