this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

bigsky: standardize DATABASE_URL connection string parsing

+10 -14
+2 -2
cmd/bigsky/main.go
··· 64 64 }, 65 65 &cli.StringFlag{ 66 66 Name: "db", 67 - Value: "sqlite=data/bigsky/bgs.sqlite", 67 + Value: "sqlite://./data/bigsky/bgs.sqlite", 68 68 EnvVars: []string{"DATABASE_URL"}, 69 69 }, 70 70 &cli.StringFlag{ 71 71 Name: "carstoredb", 72 - Value: "sqlite=data/bigsky/carstore.sqlite", 72 + Value: "sqlite://./data/bigsky/carstore.sqlite", 73 73 EnvVars: []string{"CARSTORE_DATABASE_URL"}, 74 74 }, 75 75 &cli.StringFlag{
+8 -12
cmd/gosky/util/util.go
··· 151 151 } 152 152 153 153 func SetupDatabase(dbval string) (*gorm.DB, error) { 154 - parts := strings.SplitN(dbval, "=", 2) 155 - if len(parts) == 1 { 156 - return nil, fmt.Errorf("format for database string is 'DBTYPE=PARAMS'") 157 - } 158 - 159 154 var dial gorm.Dialector 160 - switch parts[0] { 161 - case "sqlite": 162 - dial = sqlite.Open(parts[1]) 163 - case "postgres": 164 - dial = postgres.Open(parts[1]) 165 - default: 166 - return nil, fmt.Errorf("unsupported or unrecognized db type: %s", parts[0]) 155 + if strings.HasPrefix(dbval, "sqlite://") { 156 + dial = sqlite.Open(dbval[len("sqlite://"):]) 157 + } else if strings.HasPrefix(dbval, "postgresql://") { 158 + // can pass entire URL, with prefix 159 + dial = postgres.Open(dbval) 160 + } else { 161 + // TODO: this might print password 162 + return nil, fmt.Errorf("unsupported or unrecognized DATABASE_URL value: %s", dbval) 167 163 } 168 164 169 165 db, err := gorm.Open(dial, &gorm.Config{