Monday, June 23, 2025
HomeGolangConstruct Failed: import "instance.com/mysql" is a program ,not an importable bundle -...

Construct Failed: import “instance.com/mysql” is a program ,not an importable bundle – Code Evaluation


I’m connecting to database in gcp console by creating new operate utilizing golang with pattern code with database is created already utilizing present one However giving error that “Construct Failed: import “instance.com/module” is a program ,not an importable bundle” if instance.com is eliminated then it reveals error “should include dot in first path factor earlier than slash”

bundle essential

import (
    "fmt"
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
)

func essential() {
    fmt.Println("Go MySQL Tutorial")

    // Open up our database connection.
 
    // The database known as testDb
    db, err := sql.Open("mysql", "username:password@tcp(127.0.0.1:3306)/check")

    // if there's an error opening the connection, deal with it
    if err != nil {
        panic(err.Error())
    }

    // defer the shut until after the primary operate has completed
    // executing
    defer db.Shut()

}

and for go.mod

module instance.com/mysql  
go 1.20
require github.com/go-sql-driver/mysql v1.7.1

I would like to attach database by means of the code

Hello @Aurelia, welcome to the discussion board.

I don’t absolutely perceive the context of the issue.

  1. The place is the import directive

    import "instance.com/module"

    that triggers the error?

  2. The message “should include dot in first path factor earlier than slash” signifies that an URL is predicted. The Go compiler doesn’t take into account import paths as URLs. The place does this message come from?

Hello @christophberger
Thanks to your response

  1. instance.com/module” is my module identify in go.mod file.For module identify it displaying error. And in essential.go file having these packages
    import (
    “fmt”
    “database/sql”
    _ “githubcom/go-sql-driver/mysql”
    )

2.In go.mod file ,module identify is anticipating the trail of the code the place code is positioned . This message is displaying in gcp console. Additionally tried by pushing code by means of github workflow by giving module identify as github repo hyperlink like github.com/myproject/projectname. However identical error it’s displaying

I nonetheless don’t see a connection between your setup and the error messages. I think it is a GCP particular drawback.

Do you utilize some specific GCP service? Plainly this service expects to obtain a library bundle, and never a essential bundle, that it may possibly import into its framework.

I need to join database mysql in gcp . I’m attempting to attach database utilizing mysql library “githubcom/go-sql-driver/mysql” . after deploying in gcp cloud operate that error is displaying in logs . It’s displaying error for module identify .

Okay, so you’re utilizing Cloud Capabilities. Because of this you get the error:

“Construct Failed: import “instance.com/module” is a program ,not an importable bundle”

Google Cloud Capabilities expects a non-main bundle with an HTTP handler operate inside.

Your code, then again, represents a stand-alone executable that can’t run as a cloud operate.

I’d repair that half first (that’s, flip the app right into a cloud operate), after which type out the database a part of the issue.

So in code want so as to add http handler operate together with database half? And module identify will probably be? Is there any one other solution to test database connection apart from cloud operate by means of golang ?

I don’t know a lot about Cloud Capabilities. However principally, Code Capabilities, AWS Labs capabilities, and different function-as-a-service methods are primarily based on the identical precept: a operate is triggered by means of an HTTP request.
I’d guess the quickest solution to test the DB connection is to shortly arrange an HTTP handler (it’s only some traces) to set off the operate.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments