diff --git a/main.go b/main.go index a227780..2fc24ba 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "net/http" "errors" + "flag" "fmt" "log" "os" @@ -65,12 +66,16 @@ var ( } // Some random string, random for each request oauthStateString = "random" + cfgFilePath = flag.String("config", "configuration.toml", "Path to the configuration file.") + cacheDBPath = flag.String("cache", "cache.db", "Path to the cache sqlite database.") ) var ctx = context.Background() var messages = make(chan *oauth2.Token) func main() { + flag.Parse() + logfilename := fmt.Sprintf("log-%s.log", time.Now().Format("2006-01-02_15_04_05")) f, err := os.OpenFile(logfilename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { @@ -117,16 +122,15 @@ func main() { } func readConfigurationFile() error { - cfgFilePath := "configuration.toml" var config configurationFile - if _, err := toml.DecodeFile(cfgFilePath, &config); err != nil { + if _, err := toml.DecodeFile(*cfgFilePath, &config); err != nil { log.Println(err) return err } if config.ClientID == "" || config.ClientSecret == "" { - log.Println("Missing ClientID or ClientSecret configuration option in configuration file" + cfgFilePath + ".") - return errors.New("Missing ClientID or ClientSecret in configuration file " + cfgFilePath + ".") + log.Println("Missing ClientID or ClientSecret configuration option in configuration file" + *cfgFilePath + ".") + return errors.New("Missing ClientID or ClientSecret in configuration file " + *cfgFilePath + ".") } googleOauthConfig.ClientID = config.ClientID @@ -486,7 +490,7 @@ func handleAuthenticationCallback(w http.ResponseWriter, r *http.Request) { } func getCachedData(key string) string { - db, err := sql.Open("sqlite3", "./foo.db") + db, err := sql.Open("sqlite3", *cacheDBPath) if err != nil { log.Fatal(err) } @@ -515,7 +519,7 @@ func getCachedData(key string) string { } func putCacheData(key string, value string) { - db, err := sql.Open("sqlite3", "./foo.db") + db, err := sql.Open("sqlite3", *cacheDBPath) if err != nil { log.Fatal(err) }