forked from solcates/go-sql-bigquery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
29 lines (26 loc) · 745 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package bigquery
import (
"fmt"
"strings"
)
// ConfigFromConnString will return the Config structures
func ConfigFromConnString(in string) (*Config, error) {
// Expects format to be bigquery://projectid/location/dataset that's IT!
// anything else will fail
cfg := &Config{}
if strings.HasPrefix(in, "bigquery://") {
in = strings.ToLower(in)
path := strings.TrimPrefix(in, "bigquery://")
fields := strings.Split(path, "/")
if len(fields) != 3 {
return nil, fmt.Errorf("invalid connection string : %s", in)
}
cfg.ProjectID = fields[0]
cfg.Location = fields[1]
cfg.DataSet = fields[2]
return cfg, nil
} else {
// Nope, bad prefix
return nil, fmt.Errorf("invalid prefix, expected bigquery:// got: %s", in)
}
}