func newInMemoryConfig() *sql.Config { c := sql.NewConfig() c.Memory = true return c }
func main() { flag.Parse() // Ensure the data path is set. if flag.NArg() == 0 { flag.Usage() os.Exit(1) } dataPath := flag.Arg(0) // Set up profiling, if requested. if cpuprofile != "" { log.Println("profiling enabled") f, err := os.Create(cpuprofile) if err != nil { log.Printf("unable to create path: %s", err.Error()) } defer f.Close() err = pprof.StartCPUProfile(f) if err != nil { log.Printf("unable to start CPU Profile: %s", err.Error()) } defer pprof.StopCPUProfile() } // Create and open the store. dataPath, err := filepath.Abs(dataPath) if err != nil { log.Fatalf("failed to determine absolute data path: %s", err.Error()) } dbConf := sql.NewConfig() dbConf.DSN = dsn dbConf.Memory = inMem store := store.New(dbConf, dataPath, raftAddr) if err := store.Open(joinAddr == ""); err != nil { log.Fatalf("failed to open store: %s", err.Error()) } // If join was specified, make the join request. if joinAddr != "" { if err := join(joinAddr, raftAddr); err != nil { log.Fatalf("failed to join node at %s: %s", joinAddr, err.Error()) } } // Create the HTTP query server. s := httpd.New(httpAddr, store) s.DisableRedirect = disRedirect if err := s.Start(); err != nil { log.Fatalf("failed to start HTTP server: %s", err.Error()) } terminate := make(chan os.Signal, 1) signal.Notify(terminate, os.Interrupt) <-terminate if err := store.Close(); err != nil { log.Printf("failed to close store: %s", err.Error()) } log.Println("rqlite server stopped") }