@@ -67,15 +67,16 @@ type Cli struct {
6767 ErrStream io.Writer
6868 Verbose bool
6969 Priority pb.RequestOptions_Priority
70+ Endpoint string
7071}
7172
7273type command struct {
7374 Stmt Statement
7475 Vertical bool
7576}
7677
77- func NewCli (projectId , instanceId , databaseId , prompt , historyFile string , credential []byte , inStream io.ReadCloser , outStream io.Writer , errStream io.Writer , verbose bool , priority pb.RequestOptions_Priority , role string ) (* Cli , error ) {
78- session , err := createSession (projectId , instanceId , databaseId , credential , priority , role )
78+ func NewCli (projectId , instanceId , databaseId , prompt , historyFile string , credential []byte , inStream io.ReadCloser , outStream io.Writer , errStream io.Writer , verbose bool , priority pb.RequestOptions_Priority , role string , endpoint string ) (* Cli , error ) {
79+ session , err := createSession (projectId , instanceId , databaseId , credential , priority , role , endpoint )
7980 if err != nil {
8081 return nil , err
8182 }
@@ -97,6 +98,7 @@ func NewCli(projectId, instanceId, databaseId, prompt, historyFile string, crede
9798 OutStream : outStream ,
9899 ErrStream : errStream ,
99100 Verbose : verbose ,
101+ Endpoint : endpoint ,
100102 }, nil
101103}
102104
@@ -146,7 +148,7 @@ func (c *Cli) RunInteractive() int {
146148 }
147149
148150 if s , ok := stmt .(* UseStatement ); ok {
149- newSession , err := createSession (c .Session .projectId , c .Session .instanceId , s .Database , c .Credential , c .Priority , s .Role )
151+ newSession , err := createSession (c .Session .projectId , c .Session .instanceId , s .Database , c .Credential , c .Priority , s .Role , c . Endpoint )
150152 if err != nil {
151153 c .PrintInteractiveError (err )
152154 continue
@@ -308,13 +310,15 @@ func (c *Cli) getInterpolatedPrompt() string {
308310 return prompt
309311}
310312
311- func createSession (projectId string , instanceId string , databaseId string , credential []byte , priority pb.RequestOptions_Priority , role string ) (* Session , error ) {
313+ func createSession (projectId string , instanceId string , databaseId string , credential []byte , priority pb.RequestOptions_Priority , role string , endpoint string ) (* Session , error ) {
314+ var opts []option.ClientOption
312315 if credential != nil {
313- credentialOption := option .WithCredentialsJSON (credential )
314- return NewSession ( projectId , instanceId , databaseId , priority , role , credentialOption )
315- } else {
316- return NewSession ( projectId , instanceId , databaseId , priority , role )
316+ opts = append ( opts , option .WithCredentialsJSON (credential ) )
317+ }
318+ if endpoint != "" {
319+ opts = append ( opts , option . WithEndpoint ( endpoint ) )
317320 }
321+ return NewSession (projectId , instanceId , databaseId , priority , role , opts ... )
318322}
319323
320324func readInteractiveInput (rl * readline.Instance , prompt string ) (* inputStatement , error ) {
0 commit comments