mirror of
https://github.com/gojp/goreportcard.git
synced 2026-01-28 22:39:05 +08:00
Allow overriding of database path
This commit is contained in:
@@ -28,16 +28,16 @@ make install
|
||||
Now run:
|
||||
|
||||
```
|
||||
make start
|
||||
GRC_DATABASE_PATH=./db make start
|
||||
```
|
||||
|
||||
and you should see
|
||||
|
||||
```
|
||||
Running on 127.0.0.1:8000...
|
||||
Running on :8000...
|
||||
```
|
||||
|
||||
Navigate to that URL and you should see the Go Report Card front page.
|
||||
Navigate to `localhost:8000` and you should see the Go Report Card front page.
|
||||
|
||||
### Command Line Interface
|
||||
|
||||
|
||||
12
main.go
12
main.go
@@ -21,6 +21,8 @@ import (
|
||||
var (
|
||||
addr = flag.String("http", ":8000", "HTTP listen address")
|
||||
|
||||
databasePath = flag.String("db", getEnv("GRC_DATABASE_PATH", "/usr/local/badger"), "path to local badger database")
|
||||
|
||||
//go:embed assets/*
|
||||
embedFS embed.FS
|
||||
)
|
||||
@@ -103,13 +105,21 @@ func (m metrics) instrument(path string, h http.HandlerFunc) (string, http.Handl
|
||||
}
|
||||
}
|
||||
|
||||
func getEnv(name, def string) string {
|
||||
got := os.Getenv(name)
|
||||
if got == "" {
|
||||
return def
|
||||
}
|
||||
return got
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
if err := os.MkdirAll("_repos/src/github.com", 0755); err != nil && !os.IsExist(err) {
|
||||
log.Fatal("ERROR: could not create repos dir: ", err)
|
||||
}
|
||||
|
||||
db, err := badger.Open(badger.DefaultOptions("./badger").WithTruncate(true))
|
||||
db, err := badger.Open(badger.DefaultOptions(*databasePath).WithTruncate(true))
|
||||
if err != nil {
|
||||
log.Fatal("ERROR: could not open badger db: ", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user